use std::time::{Duration, Instant}; use ecs::component::local::Local; use ecs::sole::Single; use ecs::{Component, Sole}; #[derive(Debug, Clone, Default, Sole)] pub struct DeltaTime { pub duration: Duration, } #[derive(Debug, Clone, Default, Component)] pub struct LastUpdate { pub time: Option, } /// Updates the current delta time. /// /// # Panics /// Will panic if no delta time component exists. pub fn update(mut delta_time: Single, mut last_update: Local) { let current_time = Instant::now(); if let Some(last_update_time) = last_update.time { delta_time.duration = current_time.duration_since(last_update_time); } last_update.time = Some(current_time); }