bevy/src/core/time.rs

31 lines
732 B
Rust
Raw Normal View History

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
}