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
104
105
106
107
108
109
110
111
use crate::query::Proximity;
use std::iter::IntoIterator;
use std::slice::Iter;
pub struct EventPool<E> {
events: Vec<E>,
}
pub type ContactEvents<Handle> = EventPool<ContactEvent<Handle>>;
pub type ProximityEvents<Handle> = EventPool<ProximityEvent<Handle>>;
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)
}
#[inline]
pub fn len(&self) -> usize {
self.events.len()
}
}
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<Handle> {
Started(Handle, Handle),
Stopped(Handle, Handle),
}
#[derive(Copy, Clone, Debug)]
pub struct ProximityEvent<Handle> {
pub collider1: Handle,
pub collider2: Handle,
pub prev_status: Proximity,
pub new_status: Proximity,
}
impl<Handle> ProximityEvent<Handle> {
pub fn new(
collider1: Handle,
collider2: Handle,
prev_status: Proximity,
new_status: Proximity,
) -> Self {
assert_ne!(
prev_status, new_status,
"The previous and new status of a proximity event must not be the same."
);
Self {
collider1,
collider2,
prev_status,
new_status,
}
}
}