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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use std::slice::Iter;
use std::iter::IntoIterator;
use query::Proximity;
use pipeline::world::CollisionObjectHandle;
pub struct EventPool<E> {
events: Vec<E>,
}
pub type ContactEvents = EventPool<ContactEvent>;
pub type ProximityEvents = EventPool<ProximityEvent>;
impl<E> EventPool<E> {
pub fn new() -> EventPool<E> {
EventPool { events: Vec::new() }
}
pub fn clear(&mut self) {
self.events.clear();
}
pub fn push(&mut self, event: E) {
self.events.push(event);
}
pub fn iter(&self) -> Iter<E> {
self.events.iter()
}
pub fn retain<F>(&mut self, filter: F)
where
F: FnMut(&E) -> bool,
{
self.events.retain(filter)
}
}
impl<'a, E> IntoIterator for &'a EventPool<E> {
type Item = &'a E;
type IntoIter = Iter<'a, E>;
fn into_iter(self) -> Iter<'a, E> {
(&self.events).into_iter()
}
}
#[derive(Copy, Clone, Hash, Debug)]
pub enum ContactEvent {
Started(CollisionObjectHandle, CollisionObjectHandle),
Stopped(CollisionObjectHandle, CollisionObjectHandle),
}
#[derive(Copy, Clone, Debug)]
pub struct ProximityEvent {
pub collider1: CollisionObjectHandle,
pub collider2: CollisionObjectHandle,
pub prev_status: Proximity,
pub new_status: Proximity,
}
impl ProximityEvent {
pub fn new(
collider1: CollisionObjectHandle,
collider2: CollisionObjectHandle,
prev_status: Proximity,
new_status: Proximity,
) -> ProximityEvent {
assert!(prev_status != new_status);
ProximityEvent {
collider1,
collider2,
prev_status,
new_status,
}
}
}