Expand description
Fixed-timestep scheduler for deterministic time-stepped simulation.
Rendering can happen at any cadence, but physics, gameplay, or any other deterministic simulation runs in fixed slices (60 Hz by default). When rendering falls behind, the scheduler catches up by running multiple simulation steps before the next draw, capped so a long pause or slow frame never turns into one huge step.
Useful well beyond games: gesture inertia, physics-based UI animations (fling-scroll, spring-damped panels), demos/visualizations, and any retained widget that wants stable simulation independent of render rate.
§Example
use agg_gui::timestep::FixedTimestep;
let mut timestep = FixedTimestep::new();
// Inside the host's per-frame callback, with `elapsed` the wall-clock
// delta since the previous frame:
let batch = timestep.advance(elapsed);
for _ in 0..batch.steps {
// step_simulation(batch.dt);
}Structs§
- Fixed
Timestep - Accumulating fixed-timestep scheduler.
- Step
Batch - One scheduling decision: how many fixed steps to run, with what
dt, plus any wall-clock time that was dropped to avoid catastrophic catch-up.
Constants§
- FIXED_
DT - Default fixed simulation step in seconds (
1.0 / SIMULATION_HZ). - MAX_
STEPS_ PER_ DRAW - Default maximum simulation work before one draw.
- SIMULATION_
HZ - Default simulation frequency (Hz).