Module time

Expand description

See time for the system contract and examples. Supplied simulation time, pause/scale control, and drift-free duration timers.

No wall-clock reads. Feed TimeStep::scaled_delta to a fixed clock and advance gameplay timers only with the duration of updates actually executed. Do not also feed them the render-frame delta. For systems outside a fixed update loop, choose scaled_delta for simulation or unscaled_delta for UI:

use ferravex_engine::time::{SimulationTime, SimulationTimer};
use std::time::Duration;

let mut time = SimulationTime::default();
let mut timer = SimulationTimer::repeating(Duration::from_millis(100), 2)?;
assert!(time.set_scale(0.5));
let step = time.advance(Duration::from_millis(250));
assert_eq!(timer.advance(step.scaled_delta)?.expirations, 1);
assert_eq!(timer.elapsed(), Duration::from_millis(25));

time.set_paused(true);
let step = time.advance(Duration::from_millis(250));
assert_eq!(timer.advance(step.scaled_delta)?.expirations, 0);
assert_eq!(timer.elapsed(), Duration::from_millis(25));

Timers apply no additional scale or stall clamp. They preserve the integer nanoseconds supplied by the caller; upstream float conversion/scaling may round. Their optional local pause discards incoming time without accumulating catch-up debt. Keep authoritative network/replay timers advancing under local menus; pause only timers whose owning simulation is actually paused.

Structs§

SimulationTime
SimulationTimer
A reusable, allocation-free timer driven only by supplied elapsed durations.
TimeStep
TimerReport
Expirations produced by one successful SimulationTimer::advance.

Enums§

TimerError
A rejected timer configuration or advance. Errors never change timer state.
TimerMode
Whether a SimulationTimer expires once or at every interval boundary.