use .entry() match in generate_models
This commit is contained in:
parent
5f0ddc2f28
commit
6e6bafe719
@ -1006,31 +1006,30 @@ 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|{
|
let attr_id=match p_attr{
|
||||||
let attr_id=match p_attr{
|
PhysicsCollisionAttributes::Contact(attr)=>{
|
||||||
PhysicsCollisionAttributes::Contact(attr)=>{
|
let attr_id=ContactAttributesId::new(used_contact_attributes.len() as u32);
|
||||||
let attr_id=ContactAttributesId::new(used_contact_attributes.len() as u32);
|
used_contact_attributes.push(attr);
|
||||||
used_contact_attributes.push(attr);
|
PhysicsAttributesId::Contact(attr_id)
|
||||||
PhysicsAttributesId::Contact(attr_id)
|
},
|
||||||
},
|
PhysicsCollisionAttributes::Intersect(attr)=>{
|
||||||
PhysicsCollisionAttributes::Intersect(attr)=>{
|
let attr_id=IntersectAttributesId::new(used_intersect_attributes.len() as u32);
|
||||||
let attr_id=IntersectAttributesId::new(used_intersect_attributes.len() as u32);
|
used_intersect_attributes.push(attr);
|
||||||
used_intersect_attributes.push(attr);
|
PhysicsAttributesId::Intersect(attr_id)
|
||||||
PhysicsAttributesId::Intersect(attr_id)
|
},
|
||||||
},
|
};
|
||||||
};
|
Some(*entry.insert(attr_id))
|
||||||
physics_attr_id_from_model_attr_id.insert(model.attributes,attr_id);
|
})
|
||||||
Some(attr_id)
|
}){
|
||||||
})
|
Some(attr_id)=>attr_id,
|
||||||
}){
|
None=>continue,
|
||||||
Some(attr_id)=>attr_id,
|
}
|
||||||
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){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user