track time since startup
This commit is contained in:
parent
a463c040d7
commit
19bf386de9
@ -6,6 +6,8 @@ pub struct Time {
|
|||||||
pub instant: Option<Instant>,
|
pub instant: Option<Instant>,
|
||||||
pub delta_seconds_f64: f64,
|
pub delta_seconds_f64: f64,
|
||||||
pub delta_seconds: f32,
|
pub delta_seconds: f32,
|
||||||
|
pub seconds_since_startup: f64,
|
||||||
|
pub startup: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Time {
|
impl Default for Time {
|
||||||
@ -13,7 +15,9 @@ impl Default for Time {
|
|||||||
Time {
|
Time {
|
||||||
delta: Duration::from_secs(0),
|
delta: Duration::from_secs(0),
|
||||||
instant: None,
|
instant: None,
|
||||||
|
startup: Instant::now(),
|
||||||
delta_seconds_f64: 0.0,
|
delta_seconds_f64: 0.0,
|
||||||
|
seconds_since_startup: 0.0,
|
||||||
delta_seconds: 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.as_secs() as f64 + (self.delta.subsec_nanos() as f64 / 1.0e9);
|
||||||
self.delta_seconds = self.delta_seconds_f64 as f32;
|
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);
|
self.instant = Some(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn time_since_startup(&self) -> Duration {
|
||||||
|
Instant::now() - self.startup
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timer_system(mut time: ResMut<Time>) {
|
pub fn timer_system(mut time: ResMut<Time>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user