Commit 0d0c99fe authored by Rahix's avatar Rahix 🦀
Browse files

clock: Don't query wall_time() on the fly

We do know the update timestamp already as it is passed in via
Clock::update() and saved as Clock.last_tick.  Make use of this value
instead of calling into a browser API each time.
parent 9d4d2b81
use crate::utils;
pub struct Clock {
perf: web_sys::Performance,
start: f64,
last_tick: f64,
frame_delta: f32,
pub max_delta: f32,
......@@ -10,16 +6,9 @@ pub struct Clock {
impl Clock {
pub fn new() -> Clock {
let perf = utils::window()
.performance()
.expect("cannot access `window.performance`");
let start = perf.now();
Clock {
perf,
start,
frame_delta: 0.03,
last_tick: start,
last_tick: 0.0,
max_delta: 0.1,
}
}
......@@ -35,6 +24,6 @@ impl Clock {
}
pub fn wall_time(&self) -> f64 {
(self.perf.now() - self.start) / 1000.0
self.last_tick
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment