Samuel Williams Saturday, 18 April 2009

When dealing with state, synchronization between multiple simulations may become important. For example, with a client-server model network game, or when distributing the simulation processing.

There are two approaches to state synchronization within this model, which ultimately are two sides of the same coin.

Event based state management

We maintain state by sending the same events to every simulation. If events are dropped or lost, or not applied in time, the simulation may become incorrect1, although this can be corrected by sending a "keyframe" of the simulation state to bring the simulation back on track.

Event based systems are generally easier to implement but maintaining a consistent simulation across multiple discrete processes can be difficult2 3. They are typically used for real-time games and simulations. Differences in host processor (e.g. floating point accuracy, word size, operating system and standard library implementation) can cause a wide variety of difficult to handle bugs.

Synchronization based state management

We maintain state by keeping track of individual state values, and noting when they change. These changes are then serialised and sent out across the wire. In effect this is a structured event based state management, but with the effect that events may be coalesced or discarded if they are not important.

State synchronization is better for systems where precise step-by-step simulation is not so important, but rather that the final world state needs to be correct regardless of simulation behavior. They are typically used for turn-based games and user-interfaces.

Further Reading

  • Synchronous RTS Engines and a Tale of Desyncs.
  • Synchronous RTS Engines 2: Sync Harder.
  • 1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond.
  • EVE Online: Facing Destiny.
  • Comments

    Leave a comment

    Please note, comments must be formatted using Markdown. Links can be enclosed in angle brackets, e.g. <www.codeotaku.com>.