Keep a little history.
Rollback needs more than one saved state. This worker maintains a bounded snapshot ring, accepts a deliberately late input, rewinds to the nearest checkpoint, and verifies the correction is reproducible.
Creating the main-thread scene while the worker loads deterministic Rapier...
- physics
- -
- bodies
- -
- ring
- -
- checkpoint
- -
- late tick
- -
- reconcile
- -
- events
- -
- step ms
- -
- fps
- -
The worker is loading deterministic Rapier. Once ready, the selected index will address one fixed-tick body command.
ring.push({ tick, bytes })retain recent world statesring.shift()evict the oldest checkpointlateEvent.tick < currentTickaccept a past inputWorld.restoreSnapshot(bytes)rewind to the nearest statereplay(events, from, to)rebuild the corrected branchpostMessage(bytes, [buffer])publish checkpoint historyA late input invalidates later checkpoints. The worker evicts stale future entries, restores the nearest valid ring slot, replays the input log, then runs the corrected branch twice to verify identical serialized bytes.
The worker is loading deterministic Rapier. Restored body order will remain mapped to these instance slots.
Based on the official Three.js worker guidance, Rapier serialization guide, determinism guide, World API, and InstancedMesh docs. Measurements are local browser evidence, not a universal networking or rollback claim.