5. Synchronization - a-roy/pacman-mp GitHub Wiki

Network synchronization is primarily based on a rollback mechanism. In order to achieve this, every player has two copies of the game data at all times. One copy lags behind but only updates based on definitive data. The other copy is allowed to run a few frames ahead asynchronously using only the local player's inputs. When new data is received, the synchronized copy is updated and a new asynchronous copy is created from it.

Every player in the game sends their inputs to the server, once per frame but with batches of many frames at once. This duplicity allows for minor hiccups in network communication such as latency, packet drops, or other sources of possible desynchronization. The server collects the input frames from each player and rebroadcasts them to all players, who can then update their games using this data.

In addition, the game will include an input delay setting to smooth the effects of the rollback. This means that the running game will delay for a certain number of frames before reacting to the local player's inputs, but it will send these inputs to the server immediately. Because of the delay, the game will have more time to collect inputs from remote players before updating the screen.