use legion::prelude::*; use std::time::{Duration, Instant}; pub struct Time { pub delta: Duration, pub instant: Option, pub delta_seconds_f64: f64, pub delta_seconds: f32, pub seconds_since_startup: f64, pub startup: Instant, } impl Default for Time { fn default() -> 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, } } } impl Time { pub fn update(&mut self) { let now = Instant::now(); if let Some(instant) = self.instant { self.delta = now - instant; 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; } 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