diff options
| author | Sébastien Crozet <developer@crozet.re> | 2021-10-24 16:40:16 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2021-10-26 15:38:54 +0200 |
| commit | b45d4b5ac2b31856c15e802b31e288a58940cbf2 (patch) | |
| tree | e6ed90504637749cb99229dc5d1d6abb02ce7b72 | |
| parent | 601955b4ee4096db1f387017eb3d85ff727f6d31 (diff) | |
| download | rapier-b45d4b5ac2b31856c15e802b31e288a58940cbf2.tar.gz rapier-b45d4b5ac2b31856c15e802b31e288a58940cbf2.tar.bz2 rapier-b45d4b5ac2b31856c15e802b31e288a58940cbf2.zip | |
Track the change of effective dominance of a rigid-body.
| -rw-r--r-- | src/dynamics/rigid_body.rs | 5 | ||||
| -rw-r--r-- | src/dynamics/rigid_body_components.rs | 2 | ||||
| -rw-r--r-- | src/geometry/collider_components.rs | 20 | ||||
| -rw-r--r-- | src/pipeline/user_changes.rs | 15 |
4 files changed, 36 insertions, 6 deletions
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index c0acd5e..de11e15 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -331,7 +331,10 @@ impl RigidBody { /// The dominance group of this rigid-body. pub fn set_dominance_group(&mut self, dominance: i8) { - self.rb_dominance.0 = dominance + if self.rb_dominance.0 != dominance { + self.changes.insert(RigidBodyChanges::DOMINANCE); + self.rb_dominance.0 = dominance + } } /// Adds a collider to this rigid-body. diff --git a/src/dynamics/rigid_body_components.rs b/src/dynamics/rigid_body_components.rs index 82ecacf..a135a1c 100644 --- a/src/dynamics/rigid_body_components.rs +++ b/src/dynamics/rigid_body_components.rs @@ -107,6 +107,8 @@ bitflags::bitflags! { const COLLIDERS = 1 << 3; /// Flag indicating that the `RigidBodyType` component of this rigid-body has been modified. const TYPE = 1 << 4; + /// Flag indicating that the `RigidBodyDominance` component of this rigid-body has been modified. + const DOMINANCE = 1 << 5; } } diff --git a/src/geometry/collider_components.rs b/src/geometry/collider_components.rs index 7d621f3..1c737dd 100644 --- a/src/geometry/collider_components.rs +++ b/src/geometry/collider_components.rs @@ -47,16 +47,21 @@ bitflags::bitflags! { pub struct ColliderChanges: u32 { /// Flag indicating that any component of the collider has been modified. const MODIFIED = 1 << 0; - /// Flag indicating that the `RigidBodyParent` component of the collider has been modified. + /// Flag indicating that the `ColliderParent` component of the collider has been modified. const PARENT = 1 << 1; // => BF & NF updates. - /// Flag indicating that the `RigidBodyPosition` component of the collider has been modified. + /// Flag indicating that the `ColliderPosition` component of the collider has been modified. const POSITION = 1 << 2; // => BF & NF updates. - /// Flag indicating that the `RigidBodyGroups` component of the collider has been modified. + /// Flag indicating that the collision groups of the collider have been modified. const GROUPS = 1 << 3; // => NF update. - /// Flag indicating that the `RigidBodyShape` component of the collider has been modified. + /// Flag indicating that the `ColliderShape` component of the collider has been modified. const SHAPE = 1 << 4; // => BF & NF update. NF pair workspace invalidation. - /// Flag indicating that the `RigidBodyType` component of the collider has been modified. + /// Flag indicating that the `ColliderType` component of the collider has been modified. const TYPE = 1 << 5; // => NF update. NF pair invalidation. + /// Flag indicating that the dominance groups of the parent of this collider have been modified. + /// + /// This flags is automatically set by the `PhysicsPipeline` when the `RigidBodyChanges::DOMINANCE` + /// or `RigidBodyChanges::TYPE` of the parent rigid-body of this collider is detected. + const PARENT_EFFECTIVE_DOMINANCE = 1 << 6; // NF update. } } @@ -76,6 +81,11 @@ impl ColliderChanges { /// Do these changes justify a narrow-phase update? pub fn needs_narrow_phase_update(self) -> bool { + // NOTE: for simplicity of implementation, we return `true` even if + // we only need a dominance update. If this does become a + // bottleneck at some point in the future (which is very unlikely) + // we could do a special-case for dominance-only change (so that + // we only update the relative_dominance of the pre-existing contact. self.bits() > 1 } } diff --git a/src/pipeline/user_changes.rs b/src/pipeline/user_changes.rs index 699361c..643360c 100644 --- a/src/pipeline/user_changes.rs +++ b/src/pipeline/user_changes.rs @@ -155,6 +155,21 @@ pub(crate) fn handle_user_changes_to_rigid_bodies<Bodies, Colliders>( } } + if changes.contains(RigidBodyChanges::DOMINANCE) + || changes.contains(RigidBodyChanges::TYPE) + { + for handle in rb_colliders.0.iter() { + colliders.map_mut_internal(handle.0, |co_changes: &mut ColliderChanges| { + if !co_changes.contains(ColliderChanges::MODIFIED) { + modified_colliders.push(*handle); + } + + *co_changes |= + ColliderChanges::MODIFIED | ColliderChanges::PARENT_EFFECTIVE_DOMINANCE; + }); + } + } + bodies.set_internal(handle.0, RigidBodyChanges::empty()); bodies.set_internal(handle.0, ids); bodies.set_internal(handle.0, activation); |
