Rollback netcode for real-time action games (GGPO-style). Stores frame snapshots and re-simulates on late remote input.
Usage:
const rollback = new RollbackManager<GameState, Input>({ maxRollbackFrames: 8, serialize: state => JSON.parse(JSON.stringify(state)), simulate: (state, inputs) => gameStep(state, inputs),});rollback.saveFrame(0, currentState);rollback.addLocalInput(0, localInput);// When remote input arrives late:rollback.addRemoteInput(frameNum, remoteInput);const result = rollback.rollbackIfNeeded(currentFrame); Copy
const rollback = new RollbackManager<GameState, Input>({ maxRollbackFrames: 8, serialize: state => JSON.parse(JSON.stringify(state)), simulate: (state, inputs) => gameStep(state, inputs),});rollback.saveFrame(0, currentState);rollback.addLocalInput(0, localInput);// When remote input arrives late:rollback.addRemoteInput(frameNum, remoteInput);const result = rollback.rollbackIfNeeded(currentFrame);
Optional
Input delay in frames (adds latency but reduces rollbacks)
Max frames we can roll back
Deep-copy function for state snapshots
Simulate one frame given state and all player inputs
Rollback netcode for real-time action games (GGPO-style). Stores frame snapshots and re-simulates on late remote input.
Usage: