Turns the variable frame time Scene.update(dt) receives into fixed simulation steps.
Game clamps and scales each frame's dt but does not make it constant, so a simulation
that must be deterministic and independent of the display's refresh rate (a physics solver,
a lockstep game) feeds dt here and runs its tick once per returned step instead. The
leftover time carries to the next frame, and maxSubsteps bounds a slow frame so catching
up cannot make the next frame slower still.
Example
import { FixedStepper } from'@datamoc/mwg/core';
conststepper = newFixedStepper(1 / 60); constworld = { step: (h: number) =>console.log('step', h) }; // inside Scene.update(dt), here one 40 ms frame: constdt = 0.04; stepper.advance(dt, (h) =>world.step(h)); constblend = stepper.alpha; // 0..1 into the next step, for interpolated drawing
Turns the variable frame time
Scene.update(dt)receives into fixed simulation steps.Gameclamps and scales each frame'sdtbut does not make it constant, so a simulation that must be deterministic and independent of the display's refresh rate (a physics solver, a lockstep game) feedsdthere and runs its tick once per returned step instead. The leftover time carries to the next frame, andmaxSubstepsbounds a slow frame so catching up cannot make the next frame slower still.Example