From 826ce5f014281fd04b7a18238f102f2591d0b255 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 1 Jun 2021 12:36:01 +0200 Subject: Rework the event system --- src/pipeline/event_handler.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/pipeline/event_handler.rs') diff --git a/src/pipeline/event_handler.rs b/src/pipeline/event_handler.rs index 9d7b17a..4ee5387 100644 --- a/src/pipeline/event_handler.rs +++ b/src/pipeline/event_handler.rs @@ -1,6 +1,23 @@ -use crate::geometry::{ContactEvent, IntersectionEvent}; +use crate::geometry::{ContactEvent, ContactPair, IntersectionEvent}; use crossbeam::channel::Sender; +bitflags::bitflags! { + #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] + /// Flags affecting the behavior of the constraints solver for a given contact manifold. + pub struct ActiveEvents: u32 { + /// If set, Rapier will call `PhysicsHooks::FILTER_CONTACT_PAIRS` whenever relevant. + const INTERSECTION_EVENTS = 0b0001; + /// If set, Rapier will call `PhysicsHooks::filter_intersection_pair` whenever relevant. + const CONTACT_EVENTS = 0b0010; + } +} + +impl Default for ActiveEvents { + fn default() -> Self { + ActiveEvents::empty() + } +} + /// Trait implemented by structures responsible for handling events generated by the physics engine. /// /// Implementors of this trait will typically collect these events for future processing. @@ -13,12 +30,12 @@ pub trait EventHandler: Send + Sync { /// /// A contact event is emitted when two collider start or stop touching, independently from the /// number of contact points involved. - fn handle_contact_event(&self, event: ContactEvent); + fn handle_contact_event(&self, event: ContactEvent, contact_pair: &ContactPair); } impl EventHandler for () { fn handle_intersection_event(&self, _event: IntersectionEvent) {} - fn handle_contact_event(&self, _event: ContactEvent) {} + fn handle_contact_event(&self, _event: ContactEvent, _contact_pair: &ContactPair) {} } /// A physics event handler that collects events into a crossbeam channel. @@ -45,7 +62,7 @@ impl EventHandler for ChannelEventCollector { let _ = self.intersection_event_sender.send(event); } - fn handle_contact_event(&self, event: ContactEvent) { + fn handle_contact_event(&self, event: ContactEvent, _: &ContactPair) { let _ = self.contact_event_sender.send(event); } } -- cgit From 7153eb7779a29853289df90f28efaac738620386 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 1 Jun 2021 17:59:07 +0200 Subject: Add ActiveCollisionTypes to easily enable collision-detection between two non-static rigid-body. --- src/pipeline/event_handler.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pipeline/event_handler.rs') diff --git a/src/pipeline/event_handler.rs b/src/pipeline/event_handler.rs index 4ee5387..c54acc2 100644 --- a/src/pipeline/event_handler.rs +++ b/src/pipeline/event_handler.rs @@ -3,11 +3,11 @@ use crossbeam::channel::Sender; bitflags::bitflags! { #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting the behavior of the constraints solver for a given contact manifold. + /// Flags affecting the events generated for this collider. pub struct ActiveEvents: u32 { - /// If set, Rapier will call `PhysicsHooks::FILTER_CONTACT_PAIRS` whenever relevant. + /// If set, Rapier will call `EventHandler::handle_intersection_event` whenever relevant for this collider. const INTERSECTION_EVENTS = 0b0001; - /// If set, Rapier will call `PhysicsHooks::filter_intersection_pair` whenever relevant. + /// If set, Rapier will call `PhysicsHooks::handle_contact_event` whenever relevant for this collider. const CONTACT_EVENTS = 0b0010; } } -- cgit