1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::geometry::{ContactEvent, ContactPair, IntersectionEvent};
use crossbeam::channel::Sender;
bitflags::bitflags! {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct ActiveEvents: u32 {
const INTERSECTION_EVENTS = 0b0001;
const CONTACT_EVENTS = 0b0010;
}
}
impl Default for ActiveEvents {
fn default() -> Self {
ActiveEvents::empty()
}
}
pub trait EventHandler: Send + Sync {
fn handle_intersection_event(&self, event: IntersectionEvent);
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, _contact_pair: &ContactPair) {}
}
pub struct ChannelEventCollector {
intersection_event_sender: Sender<IntersectionEvent>,
contact_event_sender: Sender<ContactEvent>,
}
impl ChannelEventCollector {
pub fn new(
intersection_event_sender: Sender<IntersectionEvent>,
contact_event_sender: Sender<ContactEvent>,
) -> Self {
Self {
intersection_event_sender,
contact_event_sender,
}
}
}
impl EventHandler for ChannelEventCollector {
fn handle_intersection_event(&self, event: IntersectionEvent) {
let _ = self.intersection_event_sender.send(event);
}
fn handle_contact_event(&self, event: ContactEvent, _: &ContactPair) {
let _ = self.contact_event_sender.send(event);
}
}