clock.rs 472 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::utils;

pub struct Clock {
    perf: web_sys::Performance,
    start: f64,
}

impl Clock {
    pub fn new() -> Clock {
        let perf = utils::window()
            .performance()
            .expect("cannot access `window.performance`");
        let start = perf.now();

        Clock { perf, start }
    }

18
19
    pub fn frame_delta(&self) -> f32 {
        0.1
20
21
22
23
24
25
    }

    pub fn wall_time(&self) -> f64 {
        (self.perf.now() - self.start) / 1000.0
    }
}