aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-10-05 19:04:18 +0200
committerCrozet Sébastien <developer@crozet.re>2020-10-05 19:04:18 +0200
commit93aa7b6e1e8cbfd73542ed10ad5c26ae0a8b9848 (patch)
tree5d602450c5b5e1c0c08eeffd3196b373b4312a08 /src/dynamics
parent2d0a888484dd296cc785caf978252dd97b58e10a (diff)
downloadrapier-93aa7b6e1e8cbfd73542ed10ad5c26ae0a8b9848.tar.gz
rapier-93aa7b6e1e8cbfd73542ed10ad5c26ae0a8b9848.tar.bz2
rapier-93aa7b6e1e8cbfd73542ed10ad5c26ae0a8b9848.zip
Use the publish-subscribe mechanism to handle collider removals across pipelines.
Diffstat (limited to 'src/dynamics')
-rw-r--r--src/dynamics/rigid_body_set.rs34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/dynamics/rigid_body_set.rs b/src/dynamics/rigid_body_set.rs
index f54bc55..7906083 100644
--- a/src/dynamics/rigid_body_set.rs
+++ b/src/dynamics/rigid_body_set.rs
@@ -2,7 +2,8 @@
use rayon::prelude::*;
use crate::data::arena::Arena;
-use crate::dynamics::{BodyStatus, Joint, RigidBody};
+use crate::data::pubsub::PubSub;
+use crate::dynamics::{BodyStatus, Joint, JointSet, RigidBody};
use crate::geometry::{ColliderHandle, ColliderSet, ContactPair, InteractionGraph};
use crossbeam::channel::{Receiver, Sender};
use num::Zero;
@@ -176,12 +177,17 @@ impl RigidBodySet {
handle
}
- pub(crate) fn num_islands(&self) -> usize {
- self.active_islands.len() - 1
- }
-
- pub(crate) fn remove_internal(&mut self, handle: RigidBodyHandle) -> Option<RigidBody> {
+ /// Removes a rigid-body, and all its attached colliders and joints, from these sets.
+ pub fn remove(
+ &mut self,
+ handle: RigidBodyHandle,
+ colliders: &mut ColliderSet,
+ joints: &mut JointSet,
+ ) -> Option<RigidBody> {
let rb = self.bodies.remove(handle)?;
+ /*
+ * Update active sets.
+ */
let mut active_sets = [&mut self.active_kinematic_set, &mut self.active_dynamic_set];
for active_set in &mut active_sets {
@@ -194,9 +200,25 @@ impl RigidBodySet {
}
}
+ /*
+ * Remove colliders attached to this rigid-body.
+ */
+ for collider in &rb.colliders {
+ colliders.remove(*collider, self);
+ }
+
+ /*
+ * Remove joints attached to this rigid-body.
+ */
+ joints.remove_rigid_body(rb.joint_graph_index, self);
+
Some(rb)
}
+ pub(crate) fn num_islands(&self) -> usize {
+ self.active_islands.len() - 1
+ }
+
/// Forces the specified rigid-body to wake up if it is dynamic.
///
/// If `strong` is `true` then it is assured that the rigid-body will