mirror of
https://github.com/bevyengine/bevy
synced 2024-12-21 10:33:08 +00:00
26 lines
586 B
Rust
26 lines
586 B
Rust
|
use std::time::{Duration, Instant};
|
||
|
|
||
|
pub struct Time {
|
||
|
pub delta: Duration,
|
||
|
pub instant: Instant,
|
||
|
pub delta_seconds: f32
|
||
|
}
|
||
|
|
||
|
impl Time {
|
||
|
pub fn new() -> Time {
|
||
|
Time {
|
||
|
delta: Duration::from_secs(0),
|
||
|
instant: Instant::now(),
|
||
|
delta_seconds: 0.0,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn start(&mut self) {
|
||
|
self.instant = Instant::now();
|
||
|
}
|
||
|
|
||
|
pub fn stop(&mut self) {
|
||
|
self.delta = Instant::now() - self.instant;
|
||
|
self.delta_seconds = self.delta.as_secs() as f32 + (self.delta.subsec_nanos() as f32 / 1.0e9);
|
||
|
}
|
||
|
}
|