views:

191

answers:

2

Hi, just wondering what tips people have for avoiding game synchronisation issues in multiplayer games and replays recorded off of game logic using the model in a model view controller pattern

so far im aware that its not a good idea to give non const access to the model anywhere outside of it, but apart from that im a little stuck and still have a number of sync issues

thanks

A: 

By synchronization do you mean multithread synchronization? If it is the case I would use a mutex. If you meant communications synchronization can you explain a bit more what is happening?

Partial
+1  A: 

To achieve distributed synchronisation, you need a designated single master model, ideally on a separate game server. Control events go to that, get timestamped, the interactions of everything going on gets calculated, and timestamped update events get sent out. Replays can be done just by storing and replaying the update events.

As the model is running on a separate server, you can't even give the view const (synchronous) access to it. General purpose MVC isn't really the right approach, it is more:

model -> event stream -> local model -> view
^                             | 
|                             v
selector <- action stream <- controller

Where the two streams are definitely asynchronous and probably UDP, so lossy.

Avoid multithreading, if you have any it should be entirely localised within one of the above components (for example thread pooling within the selector, one thread per zone in the model).

For a lot of games, for performance reasons you will need to break that model and have the controller update some parts of the local model directly (e.g the way you can walk around in Wow with your internet connection unplugged). This will definitely lead to sync problems, but probably can't be avoided for a realtime game on a network with ping time > human reaction time.

soru