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
#![deny(missing_docs)]
extern crate input;
use input::GenericEvent;
pub struct Timer {
pub interval: f64,
pub time: f64,
pub next: f64,
}
impl Timer {
pub fn new(interval: f64) -> Timer {
Timer {
interval: interval,
time: 0.0,
next: 0.0,
}
}
pub fn event<E: GenericEvent, F: FnMut()>(&mut self, e: &E, mut f: F) {
if let Some(args) = e.update_args() {
self.time = self.time + args.dt;
while self.next <= self.time {
self.next = self.next + self.interval;
f();
}
}
}
}