aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline/user_changes.rs
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-04-29 10:26:44 +0200
committerCrozet Sébastien <developer@crozet.re>2021-04-29 10:26:44 +0200
commit705876f5e595a0a311b5c73cd71705c93f4f23d8 (patch)
treef89e12e33d6624853f7fa86787f667a205482a50 /src/pipeline/user_changes.rs
parent83cb981a88772626dcfb091430e8c3dba62ba1e8 (diff)
downloadrapier-705876f5e595a0a311b5c73cd71705c93f4f23d8.tar.gz
rapier-705876f5e595a0a311b5c73cd71705c93f4f23d8.tar.bz2
rapier-705876f5e595a0a311b5c73cd71705c93f4f23d8.zip
Restore the collision pipeline
Diffstat (limited to 'src/pipeline/user_changes.rs')
-rw-r--r--src/pipeline/user_changes.rs140
1 files changed, 78 insertions, 62 deletions
diff --git a/src/pipeline/user_changes.rs b/src/pipeline/user_changes.rs
index 354ff3d..34a34a2 100644
--- a/src/pipeline/user_changes.rs
+++ b/src/pipeline/user_changes.rs
@@ -37,7 +37,7 @@ pub(crate) fn handle_user_changes_to_colliders<Colliders>(
}
pub(crate) fn handle_user_changes_to_rigid_bodies<Bodies, Colliders>(
- islands: &mut IslandManager,
+ mut islands: Option<&mut IslandManager>,
bodies: &mut Bodies,
colliders: &mut Colliders,
modified_bodies: &[RigidBodyHandle],
@@ -73,65 +73,79 @@ pub(crate) fn handle_user_changes_to_rigid_bodies<Bodies, Colliders>(
{
// The body's status changed. We need to make sure
// it is on the correct active set.
- if changes.contains(RigidBodyChanges::TYPE) {
- match status {
- RigidBodyType::Dynamic => {
- // Remove from the active kinematic set if it was there.
- if islands.active_kinematic_set.get(ids.active_set_id) == Some(handle) {
- islands.active_kinematic_set.swap_remove(ids.active_set_id);
- final_action =
- Some((FinalAction::UpdateActiveKinematicSetId, ids.active_set_id));
+ if let Some(islands) = islands.as_deref_mut() {
+ if changes.contains(RigidBodyChanges::TYPE) {
+ match status {
+ RigidBodyType::Dynamic => {
+ // Remove from the active kinematic set if it was there.
+ if islands.active_kinematic_set.get(ids.active_set_id) == Some(handle) {
+ islands.active_kinematic_set.swap_remove(ids.active_set_id);
+ final_action = Some((
+ FinalAction::UpdateActiveKinematicSetId,
+ ids.active_set_id,
+ ));
+ }
+
+ // Add to the active dynamic set.
+ activation.wake_up(true);
+ // Make sure the sleep change flag is set (even if for some
+ // reasons the rigid-body was already awake) to make
+ // sure the code handling sleeping change adds the body to
+ // the active_dynamic_set.
+ changes.set(RigidBodyChanges::SLEEP, true);
}
-
- // Add to the active dynamic set.
- activation.wake_up(true);
- // Make sure the sleep change flag is set (even if for some
- // reasons the rigid-body was already awake) to make
- // sure the code handling sleeping change adds the body to
- // the active_dynamic_set.
- changes.set(RigidBodyChanges::SLEEP, true);
- }
- RigidBodyType::Kinematic => {
- // Remove from the active dynamic set if it was there.
- if islands.active_dynamic_set.get(ids.active_set_id) == Some(&handle) {
- islands.active_dynamic_set.swap_remove(ids.active_set_id);
- final_action =
- Some((FinalAction::UpdateActiveDynamicSetId, ids.active_set_id));
- }
-
- // Add to the active kinematic set.
- if islands.active_kinematic_set.get(ids.active_set_id) != Some(&handle) {
- ids.active_set_id = islands.active_kinematic_set.len();
- islands.active_kinematic_set.push(*handle);
+ RigidBodyType::Kinematic => {
+ // Remove from the active dynamic set if it was there.
+ if islands.active_dynamic_set.get(ids.active_set_id) == Some(&handle) {
+ islands.active_dynamic_set.swap_remove(ids.active_set_id);
+ final_action = Some((
+ FinalAction::UpdateActiveDynamicSetId,
+ ids.active_set_id,
+ ));
+ }
+
+ // Add to the active kinematic set.
+ if islands.active_kinematic_set.get(ids.active_set_id) != Some(&handle)
+ {
+ ids.active_set_id = islands.active_kinematic_set.len();
+ islands.active_kinematic_set.push(*handle);
+ }
}
+ RigidBodyType::Static => {}
}
- RigidBodyType::Static => {}
}
- }
-
- // Update the positions of the colliders.
- if changes.contains(RigidBodyChanges::POSITION)
- || changes.contains(RigidBodyChanges::COLLIDERS)
- {
- rb_colliders.update_positions(colliders, modified_colliders, &poss.position);
- if status.is_kinematic()
- && islands.active_kinematic_set.get(ids.active_set_id) != Some(handle)
+ // Update the positions of the colliders.
+ if changes.contains(RigidBodyChanges::POSITION)
+ || changes.contains(RigidBodyChanges::COLLIDERS)
{
- ids.active_set_id = islands.active_kinematic_set.len();
- islands.active_kinematic_set.push(*handle);
+ rb_colliders.update_positions(colliders, modified_colliders, &poss.position);
+
+ if status.is_kinematic()
+ && islands.active_kinematic_set.get(ids.active_set_id) != Some(handle)
+ {
+ ids.active_set_id = islands.active_kinematic_set.len();
+ islands.active_kinematic_set.push(*handle);
+ }
}
- }
- // Push the body to the active set if it is not
- // sleeping and if it is not already inside of the active set.
- if changes.contains(RigidBodyChanges::SLEEP)
- && !activation.sleeping // May happen if the body was put to sleep manually.
- && status.is_dynamic() // Only dynamic bodies are in the active dynamic set.
- && islands.active_dynamic_set.get(ids.active_set_id) != Some(handle)
- {
- ids.active_set_id = islands.active_dynamic_set.len(); // This will handle the case where the activation_channel contains duplicates.
- islands.active_dynamic_set.push(*handle);
+ // Push the body to the active set if it is not
+ // sleeping and if it is not already inside of the active set.
+ if changes.contains(RigidBodyChanges::SLEEP)
+ && !activation.sleeping // May happen if the body was put to sleep manually.
+ && status.is_dynamic() // Only dynamic bodies are in the active dynamic set.
+ && islands.active_dynamic_set.get(ids.active_set_id) != Some(handle)
+ {
+ ids.active_set_id = islands.active_dynamic_set.len(); // This will handle the case where the activation_channel contains duplicates.
+ islands.active_dynamic_set.push(*handle);
+ }
+ } else {
+ // We don't use islands. So just update the colliders' positions.
+ if changes.contains(RigidBodyChanges::POSITION)
+ || changes.contains(RigidBodyChanges::COLLIDERS)
+ {
+ rb_colliders.update_positions(colliders, modified_colliders, &poss.position);
+ }
}
bodies.set_internal(handle.0, RigidBodyChanges::empty());
@@ -140,16 +154,18 @@ pub(crate) fn handle_user_changes_to_rigid_bodies<Bodies, Colliders>(
}
// Adjust some ids, if needed.
- if let Some((action, id)) = final_action {
- let active_set = match action {
- FinalAction::UpdateActiveKinematicSetId => &mut islands.active_kinematic_set,
- FinalAction::UpdateActiveDynamicSetId => &mut islands.active_dynamic_set,
- };
-
- if id < active_set.len() {
- bodies.map_mut_internal(active_set[id].0, |ids2: &mut RigidBodyIds| {
- ids2.active_set_id = id;
- });
+ if let Some(islands) = islands.as_deref_mut() {
+ if let Some((action, id)) = final_action {
+ let active_set = match action {
+ FinalAction::UpdateActiveKinematicSetId => &mut islands.active_kinematic_set,
+ FinalAction::UpdateActiveDynamicSetId => &mut islands.active_dynamic_set,
+ };
+
+ if id < active_set.len() {
+ bodies.map_mut_internal(active_set[id].0, |ids2: &mut RigidBodyIds| {
+ ids2.active_set_id = id;
+ });
+ }
}
}
}