Documentation
    Preparing search index...

    Class RollbackBuffer

    A bounded, ordered ring of simulation snapshots that can rewind its target to any step it still holds (§33 rollback, §34).

    See the module header for why it never re-simulates, and for what else the caller must rewind alongside it.

    Index
    • Parameters

      Returns RollbackBuffer

      FourError if capacity is not a positive integer — a zero-capacity rollback buffer is a buffer that refuses every rewind, which §85 says to reject at construction rather than to discover one dropped frame later

    capacity: number

    The rewind window, in captures.

    The simulation this buffer snapshots and rewinds.

    • get newestStep(): number | undefined

      The most recent captured step, or undefined when empty.

      Returns number | undefined

    • get oldestStep(): number | undefined

      The oldest step still rewindable, or undefined when empty.

      Returns number | undefined

    • get size(): number

      How many snapshots are held. Never exceeds RollbackBuffer.capacity.

      Returns number

    • get steps(): readonly number[]

      The captured steps, ascending — the exact set rollbackTo accepts.

      Returns readonly number[]

    • Snapshots the target as the state at the end of fixed step step.

      Evicts the oldest snapshot once the ring is full. Steps must arrive strictly ascending: a simulation runs forwards, and a repeat or a going-backwards capture means the caller's own step counter disagrees with the one it rewound to — which is exactly the bug this class exists to make impossible to have silently.

      Parameters

      • step: number

      Returns void

      FourError if step is not a non-negative integer, or is not greater than RollbackBuffer.newestStep

    • Forgets every snapshot. The target is not touched.

      Returns void

    • Whether step can still be rolled back to.

      Parameters

      • step: number

      Returns boolean

    • Restores the target to the state captured at step and forgets everything after it, returning how many fixed steps the caller must re-simulate to get back to where it was.

      The returned count is newestStep − step, so re-simulating exactly that many steps lands on the same step number the simulation was on before the rewind. rollbackTo(newestStep) restores and returns 0 — a legitimate call, and the cheap way to discard uncommitted state.

      step itself stays in the buffer: rolling back to the same step twice is ordinary in a network predictor that receives two late inputs for one step.

      Parameters

      • step: number

      Returns number

      FourError if step was never captured or has been evicted; the message names the window still held, because "how far back can I go" is the question the caller has at that moment