Skip to main content

Module timestep

Module timestep 

Source
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§

FixedTimestep
Accumulating fixed-timestep scheduler.
StepBatch
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).