2020-04-06 03:19:02 +00:00
|
|
|
use legion::prelude::*;
|
2019-12-03 08:30:30 +00:00
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
|
|
|
|
pub struct Time {
|
|
|
|
pub delta: Duration,
|
|
|
|
pub instant: Instant,
|
2020-03-27 22:03:47 +00:00
|
|
|
pub delta_seconds_f64: f64,
|
2020-01-11 10:11:27 +00:00
|
|
|
pub delta_seconds: f32,
|
2019-12-03 08:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Time {
|
|
|
|
pub fn new() -> Time {
|
|
|
|
Time {
|
|
|
|
delta: Duration::from_secs(0),
|
|
|
|
instant: Instant::now(),
|
2020-03-27 22:03:47 +00:00
|
|
|
delta_seconds_f64: 0.0,
|
2019-12-03 08:30:30 +00:00
|
|
|
delta_seconds: 0.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn start(&mut self) {
|
|
|
|
self.instant = Instant::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn stop(&mut self) {
|
|
|
|
self.delta = Instant::now() - self.instant;
|
2020-03-27 22:03:47 +00:00
|
|
|
self.delta_seconds_f64 =
|
|
|
|
self.delta.as_secs() as f64 + (self.delta.subsec_nanos() as f64 / 1.0e9);
|
|
|
|
self.delta_seconds = self.delta_seconds_f64 as f32;
|
2019-12-03 08:30:30 +00:00
|
|
|
}
|
2020-01-11 10:11:27 +00:00
|
|
|
}
|
2020-04-06 03:19:02 +00:00
|
|
|
|
2020-04-30 23:13:21 +00:00
|
|
|
pub fn start_timer_system(mut time: ResourceMut<Time>) {
|
|
|
|
time.start();
|
2020-04-06 03:19:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 23:13:21 +00:00
|
|
|
pub fn stop_timer_system(mut time: ResourceMut<Time>) {
|
|
|
|
time.stop();
|
2020-05-01 05:30:51 +00:00
|
|
|
}
|