use .entry() match in generate_models

This commit is contained in:
2025-04-29 17:57:31 -07:00
parent 5f0ddc2f28
commit 6e6bafe719

@ -1006,10 +1006,9 @@ impl PhysicsData{
let mut used_meshes=Vec::new(); let mut used_meshes=Vec::new();
let mut physics_mesh_id_from_model_mesh_id=HashMap::<MeshId,PhysicsMeshId>::new(); let mut physics_mesh_id_from_model_mesh_id=HashMap::<MeshId,PhysicsMeshId>::new();
for (model_id,model) in map.models.iter().enumerate(){ for (model_id,model) in map.models.iter().enumerate(){
//TODO: use .entry().or_insert_with(||{ let attr_id=match physics_attr_id_from_model_attr_id.entry(model.attributes){
let attr_id=if let Some(&attr_id)=physics_attr_id_from_model_attr_id.get(&model.attributes){ std::collections::hash_map::Entry::Occupied(entry)=>*entry.get(),
attr_id std::collections::hash_map::Entry::Vacant(entry)=>{
}else{
//check if it's real //check if it's real
match map.attributes.get(model.attributes.get() as usize).and_then(|m_attr|{ match map.attributes.get(model.attributes.get() as usize).and_then(|m_attr|{
PhysicsCollisionAttributes::try_from(m_attr).map_or(None,|p_attr|{ PhysicsCollisionAttributes::try_from(m_attr).map_or(None,|p_attr|{
@ -1025,13 +1024,13 @@ impl PhysicsData{
PhysicsAttributesId::Intersect(attr_id) PhysicsAttributesId::Intersect(attr_id)
}, },
}; };
physics_attr_id_from_model_attr_id.insert(model.attributes,attr_id); Some(*entry.insert(attr_id))
Some(attr_id)
}) })
}){ }){
Some(attr_id)=>attr_id, Some(attr_id)=>attr_id,
None=>continue, None=>continue,
} }
}
}; };
let mesh_id=if let Some(&mesh_id)=physics_mesh_id_from_model_mesh_id.get(&model.mesh){ let mesh_id=if let Some(&mesh_id)=physics_mesh_id_from_model_mesh_id.get(&model.mesh){
mesh_id mesh_id