vigilant_lamp/engine/
clock.rs

1use std::{time::{Duration}};
2use instant::Instant;
3
4/// Usefull util to keep track of time deltas
5#[derive(Clone, Copy)]
6pub struct Clock (Instant);
7
8impl Clock {
9    pub fn new () -> Clock {
10        Clock(Instant::now())
11    }
12
13    pub fn delta (&mut self) -> Duration {
14        let now = Instant::now();
15        let dt = now - self.0;
16
17        self.0 = now;
18        dt
19    }
20}