New timer struct.

Fix frame rate for animated sprites.
This commit is contained in:
2016-05-30 22:58:38 +02:00
parent 2c7d5cc1d6
commit 20557bbf79
5 changed files with 31 additions and 50 deletions

View File

@@ -1,5 +1,21 @@
extern crate time;
use std::time::{Duration, Instant};
pub fn current_time() -> f64 {
(time::precise_time_ns() / 1_000_000) as f64
pub struct Timer {
time: Instant
}
impl Timer {
pub fn new() -> Timer {
Timer {
time: Instant::now()
}
}
pub fn current_time(&self) -> f64 {
let secs = self.time.elapsed().as_secs() as f64;
let nanos = self.time.elapsed().subsec_nanos() as f64;
secs * 1_000.0 + nanos / 1_000_000.0
}
}