mwg API
    Preparing search index...

    Class FixedStepper

    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.

    import { FixedStepper } from '@datamoc/mwg/core';

    const stepper = new FixedStepper(1 / 60);
    const world = { step: (h: number) => console.log('step', h) };
    // inside Scene.update(dt), here one 40 ms frame:
    const dt = 0.04;
    stepper.advance(dt, (h) => world.step(h));
    const blend = stepper.alpha; // 0..1 into the next step, for interpolated drawing
    Index
    maxSubsteps: number
    step: number
    • get alpha(): number

      how far into the next step the leftover time reaches, 0 up to (not including) 1

      Returns number

    • Adds dt seconds and runs tick(step) for every whole step now due.

      Parameters

      • dt: number
      • tick: (step: number) => void

      Returns number

      how many steps ran; time beyond maxSubsteps steps is dropped, not banked