Game State Synchronization
Author: Samuel Williams When: Saturday, 18 April 2009April 2009
May 2009
August 2009
September 2009
October 2009
- Building a Concrete Bath
- LED Lighting Comparison
- Thinking about Programming Languages
- How To Be A Consultant
- Lucid Programming Dojo
- Exim4 + ClamAV + SpamAssassin
- Secure login using AJAX
- Ramaze And Rack
- ActiveMerchant
- Concurrency And Immutability
- Floating Point Numbers
- Programming And Debugging
- Useful jQuery Plugins
- Loading Anonymous Ruby Classes
- 尺八 (Shakuhachi)
- Card Trick
- Object Oriented C
- Gemcutter
- Writing Clearly
- Richard Stallman In Christchurch
- Magnatune
- Client Side Graphing
- Zena CMS
November 2009
February 2010
March 2010
April 2010
May 2010
June 2010
July 2010
August 2010
September 2010
December 2010
January 2011
March 2011
May 2011
August 2011
September 2011
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 incorrect, although this can be corrected by sending a "keyframe" of the simulation state to bring the simulation back on track.
- An event signals some sort of state change to the world
- State change may need processing to apply
- Event based system is generally easier to implement
- Events can minimize traffic as much data can be evaluated on the client
- Events from clients can be
- Events sent to clients can be filtered programmatically based on proximity or relevance, thus reducing bandwidth even more.
- An example of an event is an encapsulated transmission of the IWorldEvents object. This contains a discrete event that changes the state of the world.
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 set out across the wire. This is more heavy handed than event based state management, however it has the benefits of being simpler to implement - i.e. there are a limited set of messages to transmit, but it is verbose in that a single event may cause many objects to change.
- Synchronize state between client and server
- Server maintains world state
- Set of objects, relationships and state
- Client needs to know a portion of the world state
- Subset of objects, relationships and state
- Client state needs to be updated
- Change state (primitive type change)
- Instantiate object
- Destroy object
- Update relationships
An example of a synchronised system is the Cocoa bindings system (Mac OS X UI framework). This is done using key paths. Key paths are strings such as myAccount.owner.name. A key path represents an individual piece of state that can change and be updated. When a user interface element is bound to a key path, it (simply) will be informed if the value changes. Conversely, if the user interface element has its value changed, it will update the value at the key path.
Comments
Please note, you can leave a comment that uses (limited) XHTML and Textile syntax.