diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-10-05 19:04:18 +0200 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-10-05 19:04:18 +0200 |
| commit | 93aa7b6e1e8cbfd73542ed10ad5c26ae0a8b9848 (patch) | |
| tree | 5d602450c5b5e1c0c08eeffd3196b373b4312a08 /src/pipeline | |
| parent | 2d0a888484dd296cc785caf978252dd97b58e10a (diff) | |
| download | rapier-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/pipeline')
| -rw-r--r-- | src/pipeline/collision_pipeline.rs | 24 | ||||
| -rw-r--r-- | src/pipeline/physics_pipeline.rs | 65 |
2 files changed, 15 insertions, 74 deletions
diff --git a/src/pipeline/collision_pipeline.rs b/src/pipeline/collision_pipeline.rs index f30dae7..2283fa7 100644 --- a/src/pipeline/collision_pipeline.rs +++ b/src/pipeline/collision_pipeline.rs @@ -84,28 +84,4 @@ impl CollisionPipeline { bodies.modified_inactive_set.clear(); } - - /// Remove a rigid-body and all its associated data. - pub fn remove_rigid_body( - &mut self, - handle: RigidBodyHandle, - broad_phase: &mut BroadPhase, - narrow_phase: &mut NarrowPhase, - bodies: &mut RigidBodySet, - colliders: &mut ColliderSet, - ) -> Option<RigidBody> { - // Remove the body. - let body = bodies.remove_internal(handle)?; - - // Remove this rigid-body from the broad-phase and narrow-phase. - broad_phase.remove_colliders(&body.colliders, colliders); - narrow_phase.remove_colliders(&body.colliders, colliders, bodies); - - // Remove all colliders attached to this body. - for collider in &body.colliders { - colliders.remove_internal(*collider); - } - - Some(body) - } } diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index 3fcd1af..7185c62 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -1,6 +1,7 @@ //! Physics pipeline structures. use crate::counters::Counters; +use crate::data::pubsub::PubSubCursor; #[cfg(not(feature = "parallel"))] use crate::dynamics::IslandSolver; use crate::dynamics::{IntegrationParameters, JointSet, RigidBody, RigidBodyHandle, RigidBodySet}; @@ -8,7 +9,7 @@ use crate::dynamics::{IntegrationParameters, JointSet, RigidBody, RigidBodyHandl use crate::dynamics::{JointGraphEdge, ParallelIslandSolver as IslandSolver}; use crate::geometry::{ BroadPhase, BroadPhasePairEvent, Collider, ColliderHandle, ColliderPair, ColliderSet, - ContactManifoldIndex, NarrowPhase, + ContactManifoldIndex, NarrowPhase, RemovedCollider, }; use crate::math::Vector; use crate::pipeline::EventHandler; @@ -59,6 +60,18 @@ impl PhysicsPipeline { } } + /// Remove this. + pub fn maintain( + &mut self, + broad_phase: &mut BroadPhase, + narrow_phase: &mut NarrowPhase, + bodies: &mut RigidBodySet, + colliders: &mut ColliderSet, + ) { + // broad_phase.maintain(colliders); + // narrow_phase.maintain(colliders, bodies); + } + /// Executes one timestep of the physics simulation. pub fn step( &mut self, @@ -73,6 +86,7 @@ impl PhysicsPipeline { ) { // println!("Step"); self.counters.step_started(); + self.maintain(broad_phase, narrow_phase, bodies, colliders); bodies.maintain_active_set(); // Update kinematic bodies velocities. @@ -249,55 +263,6 @@ impl PhysicsPipeline { bodies.modified_inactive_set.clear(); self.counters.step_completed(); } - - /// Remove a collider and all its associated data. - pub fn remove_collider( - &mut self, - handle: ColliderHandle, - broad_phase: &mut BroadPhase, - narrow_phase: &mut NarrowPhase, - bodies: &mut RigidBodySet, - colliders: &mut ColliderSet, - ) -> Option<Collider> { - broad_phase.remove_colliders(&[handle], colliders); - narrow_phase.remove_colliders(&[handle], colliders, bodies); - let collider = colliders.remove_internal(handle)?; - - if let Some(parent) = bodies.get_mut_internal(collider.parent) { - parent.remove_collider_internal(handle, &collider); - bodies.wake_up(collider.parent, true); - } - - Some(collider) - } - - /// Remove a rigid-body and all its associated data. - pub fn remove_rigid_body( - &mut self, - handle: RigidBodyHandle, - broad_phase: &mut BroadPhase, - narrow_phase: &mut NarrowPhase, - bodies: &mut RigidBodySet, - colliders: &mut ColliderSet, - joints: &mut JointSet, - ) -> Option<RigidBody> { - // Remove the body. - let body = bodies.remove_internal(handle)?; - - // Remove this rigid-body from the broad-phase and narrow-phase. - broad_phase.remove_colliders(&body.colliders, colliders); - narrow_phase.remove_colliders(&body.colliders, colliders, bodies); - - // Remove all joints attached to this body. - joints.remove_rigid_body(body.joint_graph_index, bodies); - - // Remove all colliders attached to this body. - for collider in &body.colliders { - colliders.remove_internal(*collider); - } - - Some(body) - } } #[cfg(test)] |
