track time since startup

This commit is contained in:
Carter Anderson 2020-05-30 21:32:47 -07:00
parent a463c040d7
commit 19bf386de9

View file

@ -6,6 +6,8 @@ pub struct Time {
pub instant: Option<Instant>,
pub delta_seconds_f64: f64,
pub delta_seconds: f32,
pub seconds_since_startup: f64,
pub startup: Instant,
}
impl Default for Time {
@ -13,7 +15,9 @@ impl Default for Time {
Time {
delta: Duration::from_secs(0),
instant: None,
startup: Instant::now(),
delta_seconds_f64: 0.0,
seconds_since_startup: 0.0,
delta_seconds: 0.0,
}
}
@ -28,8 +32,15 @@ impl Time {
self.delta.as_secs() as f64 + (self.delta.subsec_nanos() as f64 / 1.0e9);
self.delta_seconds = self.delta_seconds_f64 as f32;
}
let duration_since_startup = now - self.startup;
self.seconds_since_startup = duration_since_startup.as_secs() as f64 + (duration_since_startup.subsec_nanos() as f64 / 1.0e9);
self.instant = Some(now);
}
pub fn time_since_startup(&self) -> Duration {
Instant::now() - self.startup
}
}
pub fn timer_system(mut time: ResMut<Time>) {