Track the change of effective dominance of a rigid-body.

This commit is contained in:
Sébastien Crozet
2021-10-24 16:40:16 +02:00
committed by Sébastien Crozet
parent 601955b4ee
commit b45d4b5ac2
4 changed files with 36 additions and 6 deletions

View File

@@ -331,7 +331,10 @@ impl RigidBody {
/// The dominance group of this rigid-body. /// The dominance group of this rigid-body.
pub fn set_dominance_group(&mut self, dominance: i8) { 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. /// Adds a collider to this rigid-body.

View File

@@ -107,6 +107,8 @@ bitflags::bitflags! {
const COLLIDERS = 1 << 3; const COLLIDERS = 1 << 3;
/// Flag indicating that the `RigidBodyType` component of this rigid-body has been modified. /// Flag indicating that the `RigidBodyType` component of this rigid-body has been modified.
const TYPE = 1 << 4; const TYPE = 1 << 4;
/// Flag indicating that the `RigidBodyDominance` component of this rigid-body has been modified.
const DOMINANCE = 1 << 5;
} }
} }

View File

@@ -47,16 +47,21 @@ bitflags::bitflags! {
pub struct ColliderChanges: u32 { pub struct ColliderChanges: u32 {
/// Flag indicating that any component of the collider has been modified. /// Flag indicating that any component of the collider has been modified.
const MODIFIED = 1 << 0; 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. 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. 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. 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. 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. 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? /// Do these changes justify a narrow-phase update?
pub fn needs_narrow_phase_update(self) -> bool { 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 self.bits() > 1
} }
} }

View File

@@ -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, RigidBodyChanges::empty());
bodies.set_internal(handle.0, ids); bodies.set_internal(handle.0, ids);
bodies.set_internal(handle.0, activation); bodies.set_internal(handle.0, activation);