Add a parameter to indicate if collider removal should wake-up its parent.

This commit is contained in:
Crozet Sébastien
2020-11-19 11:09:40 +01:00
parent 1b0f39073f
commit 0d49a80974
3 changed files with 14 additions and 3 deletions

View File

@@ -207,7 +207,7 @@ impl RigidBodySet {
* Remove colliders attached to this rigid-body. * Remove colliders attached to this rigid-body.
*/ */
for collider in &rb.colliders { for collider in &rb.colliders {
colliders.remove(*collider, self); colliders.remove(*collider, self, false);
} }
/* /*

View File

@@ -78,10 +78,14 @@ impl ColliderSet {
} }
/// Remove a collider from this set and update its parent accordingly. /// Remove a collider from this set and update its parent accordingly.
///
/// If `wake_up` is `true`, the rigid-body the removed collider is attached to
/// will be woken up.
pub fn remove( pub fn remove(
&mut self, &mut self,
handle: ColliderHandle, handle: ColliderHandle,
bodies: &mut RigidBodySet, bodies: &mut RigidBodySet,
wake_up: bool,
) -> Option<Collider> { ) -> Option<Collider> {
let collider = self.colliders.remove(handle)?; let collider = self.colliders.remove(handle)?;
@@ -90,7 +94,10 @@ impl ColliderSet {
*/ */
if let Some(parent) = bodies.get_mut_internal(collider.parent) { if let Some(parent) = bodies.get_mut_internal(collider.parent) {
parent.remove_collider_internal(handle, &collider); parent.remove_collider_internal(handle, &collider);
bodies.wake_up(collider.parent, true);
if wake_up {
bodies.wake_up(collider.parent, true);
}
} }
/* /*

View File

@@ -758,7 +758,7 @@ impl Testbed {
for to_delete in &colliders[..num_to_delete] { for to_delete in &colliders[..num_to_delete] {
self.physics self.physics
.colliders .colliders
.remove(to_delete[0], &mut self.physics.bodies); .remove(to_delete[0], &mut self.physics.bodies, true);
} }
} }
WindowEvent::Key(Key::D, Action::Release, _) => { WindowEvent::Key(Key::D, Action::Release, _) => {
@@ -1576,11 +1576,13 @@ CCD: {:.2}ms
} }
if self.state.flags.contains(TestbedStateFlags::DEBUG) { if self.state.flags.contains(TestbedStateFlags::DEBUG) {
let t = instant::now();
let bf = bincode::serialize(&self.physics.broad_phase).unwrap(); let bf = bincode::serialize(&self.physics.broad_phase).unwrap();
let nf = bincode::serialize(&self.physics.narrow_phase).unwrap(); let nf = bincode::serialize(&self.physics.narrow_phase).unwrap();
let bs = bincode::serialize(&self.physics.bodies).unwrap(); let bs = bincode::serialize(&self.physics.bodies).unwrap();
let cs = bincode::serialize(&self.physics.colliders).unwrap(); let cs = bincode::serialize(&self.physics.colliders).unwrap();
let js = bincode::serialize(&self.physics.joints).unwrap(); let js = bincode::serialize(&self.physics.joints).unwrap();
let serialization_time = instant::now() - t;
let hash_bf = md5::compute(&bf); let hash_bf = md5::compute(&bf);
let hash_nf = md5::compute(&nf); let hash_nf = md5::compute(&nf);
let hash_bodies = md5::compute(&bs); let hash_bodies = md5::compute(&bs);
@@ -1588,6 +1590,7 @@ CCD: {:.2}ms
let hash_joints = md5::compute(&js); let hash_joints = md5::compute(&js);
profile = format!( profile = format!(
r#"{} r#"{}
Serialization time: {:.2}ms
Hashes at frame: {} Hashes at frame: {}
|_ Broad phase [{:.1}KB]: {:?} |_ Broad phase [{:.1}KB]: {:?}
|_ Narrow phase [{:.1}KB]: {:?} |_ Narrow phase [{:.1}KB]: {:?}
@@ -1595,6 +1598,7 @@ Hashes at frame: {}
|_ Colliders [{:.1}KB]: {:?} |_ Colliders [{:.1}KB]: {:?}
|_ Joints [{:.1}KB]: {:?}"#, |_ Joints [{:.1}KB]: {:?}"#,
profile, profile,
serialization_time,
self.state.timestep_id, self.state.timestep_id,
bf.len() as f32 / 1000.0, bf.len() as f32 / 1000.0,
hash_bf, hash_bf,