diff --git a/strafe-client/src/model_physics.rs b/strafe-client/src/model_physics.rs index fd9be5d..1d3f307 100644 --- a/strafe-client/src/model_physics.rs +++ b/strafe-client/src/model_physics.rs @@ -279,14 +279,11 @@ struct EdgePool{ } impl EdgePool{ fn push(&mut self,edge_ref_verts:EdgeRefVerts)->(&mut EdgeRefFaces,SubmeshEdgeId){ - let edge_id=if let Some(&edge_id)=self.edge_id_from_guy.get(&edge_ref_verts){ - edge_id - }else{ + let edge_id=*self.edge_id_from_guy.entry(edge_ref_verts.clone()).or_insert_with(||{ let edge_id=SubmeshEdgeId::new(self.edge_guys.len() as u32); - self.edge_guys.push((edge_ref_verts.clone(),EdgeRefFaces::new())); - self.edge_id_from_guy.insert(edge_ref_verts,edge_id); + self.edge_guys.push((edge_ref_verts,EdgeRefFaces::new())); edge_id - }; + }); (&mut self.edge_guys[edge_id.get() as usize].1,edge_id) } } @@ -322,16 +319,11 @@ impl TryFrom<&model::Mesh> for PhysicsMesh{ let mut submesh_verts=Vec::new(); let mut submesh_vert_id_from_mesh_vert_id=HashMap::::new(); //lazy closure - let mut get_submesh_vert_id=|vert_id:MeshVertId|{ - if let Some(&submesh_vert_id)=submesh_vert_id_from_mesh_vert_id.get(&vert_id){ - submesh_vert_id - }else{ - let submesh_vert_id=SubmeshVertId::new(submesh_verts.len() as u32); - submesh_verts.push(vert_id); - submesh_vert_id_from_mesh_vert_id.insert(vert_id,submesh_vert_id); - submesh_vert_id - } - }; + let mut get_submesh_vert_id=|vert_id:MeshVertId|*submesh_vert_id_from_mesh_vert_id.entry(vert_id).or_insert_with(||{ + let submesh_vert_id=SubmeshVertId::new(submesh_verts.len() as u32); + submesh_verts.push(vert_id); + submesh_vert_id + }); let mut edge_pool=EdgePool::default(); let mut vert_ref_guys=vec![VertRefGuy::default();mesh.unique_pos.len()]; let mut face_ref_guys=Vec::new();