Netcode Concepts Part 3: Lockstep and Rollback

A series on general concepts in Netcode

Index

Synchronising game state using Lockstep

Basic Lockstep

An example of lockstep running on one game client. The client sends out its own character inputs, and then waits for inputs from other players, before processing a game tick. It waits as long as necessary to receive that data.
An example of Player 2 (Orange) lagging. Although there’s some variation in how long each tick lasts, Player 1 (Teal) client must wait for the data to arrive. Both clients stay in step.

Asynchronous lockstep

Deterministic lockstep

Deterministic lockstep with input delay

An example of a three-tick input delay. Inputs are transmitted, and buffered for 3 ticks before being used. This gives data time to transmit
If Player 2 (orange) starts lagging after INPUT 6 is sent, as long as that data arrives at Player 1’s client before it is needed, there is no impact on gameplay from the lag.

Prediction and Rollback

An example of rollback: When no data is received, ticks are made using a predicted input. When the actual input arrives, the state is rolled back to that point, and reprocessed forward with the input.
Rollback combined with 2-tick input delay: this reduces the need to continuously rollback the game state, and only employs rollback to deal with momentary lag. In this diagram, Player 2 (orange)’s input 5 packet gets delayed. This causes Player 1 to need to predict tick 5, and later rollback when it is received.

Limitations

Demo

🤖 Build robots, code in python. Former Electrical Engineer 👨‍💻 Programmer, Chief Technology Officer 🏆 Forbes 30 Under 30 in Enterprise Technology