- Introduced ECSRenderer struct to manage the connection between the renderer and the ECS. - Implemented methods for spawning and despawning meshes within the ECS. - Updated main function to utilize ECSRenderer for rendering and object management. - Added a new Time module to handle frame timing and updates.
34 lines
No EOL
676 B
Rust
34 lines
No EOL
676 B
Rust
use std::time::{Duration, Instant};
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Time {
|
|
last: Instant,
|
|
delta: Duration,
|
|
total: Duration,
|
|
}
|
|
|
|
impl Time {
|
|
pub fn new() -> Self {
|
|
let now = Instant::now();
|
|
Self {
|
|
last: now,
|
|
delta: Duration::ZERO,
|
|
total: Duration::ZERO,
|
|
}
|
|
}
|
|
|
|
pub fn tick(&mut self) {
|
|
let now = Instant::now();
|
|
self.delta = now - self.last;
|
|
self.total += self.delta;
|
|
self.last = now;
|
|
}
|
|
|
|
pub fn delta_seconds(&self) -> f32 {
|
|
self.delta.as_secs_f32()
|
|
}
|
|
|
|
pub fn total_seconds(&self) -> f32 {
|
|
self.total.as_secs_f32()
|
|
}
|
|
}
|