I currently have a piece of coursework that requires 3 or more 3d simulations connected via p2p to maintain a simulation that is visually consistent amoung all peers. A big issue is that I'm not allowed to use any form of authoritative server/peer logic and I'm struggling with potential designs.

The coursework has the following relavant constraints

  • each peer must be connected at the start and will have the same initial empty simulation
  • The network will be LAN only
  • Hardware is consistent in all computers in the network

I'm thinking about implementing it along the lines of

  1. Each peer will regularly create a snapshot of all objects that have moved since the last snapshot
  2. Each peer will maitain a local copy of the snapshot in addition to broadcasting it to all other peers
  3. Each peer will combine the other snapshots possibly via averaging and and adding it to the current local state. I'm thinking I could also possibly use timestamps of each snapshot to weight the combination.
  4. each peer runs their local simulation briefly then repeat the process

Can anybody see any potential problems with this or recommend anything?

  • \$\begingroup\$ You might want to specify the type of simulation. \$\endgroup\$
    – Vaillancourt
    Commented Apr 24, 2015 at 22:25
  • \$\begingroup\$ It's a kerplunk style game where you have a tower and you insert balls from the top, they interact with the tower's contents then fall out from the bottom \$\endgroup\$ Commented Apr 24, 2015 at 22:41

3 Answers 3


The key to large-scale synchronization is determinism. Basically, if you can plug X into a function and get the same Y on all computers, you can send X instead of Y.

For example the de facto RTS game sends commands rather than health, positions, rotations, etc. since syncing 500+ positions can use up quite a bit of bandwidth.

For example, the command "Units {6,13,15,19,102}: move to -> (32,-7)" is sent. This command gets sent by the caster then received and interpreted on everyone's computer.

For something like a tower with balls falling through, you can send commands like "Ball 1: Apply velocity -> (2,3)". Once the message reaches everyone, the velocity is applied. Things like gravity don't need to be synced - only information that not everybody has.

Note that this networking system, called Lockstep, is considerably more difficult to implement than simulating physics locally and sending out the resulting data. If you don't have too many simulation objects, you can simply simulate everything on 1 player's computer then distribute that information. I'm not too sure about "hashing" the game state but serializing everything in 1 neat package per sync frame will definitely work. Don't worry about averaging or anything - simply interpolate the data on everyone's computer except the guy producing it.

With a bit more work though and the same hardware, I think you can make Unity's PhysX produce the same output given the same input. From my tests, Box2D leans towards the arbitrary side even on the same platform.

Here's an example implementation I've been working on: https://www.youtube.com/watch?v=VvhKNWOML2c. If you need a cross-platform deterministic 2D physics engine, I might be able to help you with that.


JPtheK9 makes a good point about sending a command to move the objects in the simulation, but my 2 cents would be that I think you are on the right track.

So each time it runs, i will call that a step to make it easier, since it will send changes and save the snapshot after each step. As far as the design goes, this is how i would set it up to run.

Using what you wrote, it can be broken into a few processes on each simulation. This assumes the simulations have connected, so i will skip that part.

Create beginning snapshot > If objects were randomly created, send snapshot to each sim > simulation runs > while sim runs, run loop (update snapshot > send and receive snapshots > update sim)

So basically, while the sim runs, either in between each step or as it receives changes, it will create a snapshot, send/receive, then update the sim. If you need to, set up a queue to collect all the commands, then run through it on each update. Hope this helps or gives you any other ideas to work with.


Try a hash of your entire "synchronized game state" instead of averaging data. There are some nice benefits to it, and is basically the standard for the RTS genre.

  • 3
    \$\begingroup\$ Hashes can't be efficiently reversed so you'd be converting the game state into something that can't be interpreted - effectively making the data useless for synchronization. Do you mean serialize? If yes, RTS games don't do that either. They sync input - not output. \$\endgroup\$
    – JPtheK9
    Commented Apr 26, 2015 at 22:15
  • \$\begingroup\$ Read the determinism answer then think about how you can be sure the simulations are really synchronized (in case of bugs or cheating attempts). Networking the hash of the synchronized game state will let all players be sure that nobody is cheating and that the simulation is synchronized (: \$\endgroup\$
    – Alan Wolfe
    Commented Apr 28, 2015 at 1:10
  • \$\begingroup\$ 1. That wasn't what was asked for. 2. I wrote the determinism answer. 3. The only person someone would be cheating is himself by modifying his local gamestate. 4. Bugs need to be fixed - not checked for in-game. If a desync bug were detected, how can it be fixed? \$\endgroup\$
    – JPtheK9
    Commented Apr 28, 2015 at 2:08
  • \$\begingroup\$ If you don't want to learn its up to you :p \$\endgroup\$
    – Alan Wolfe
    Commented Apr 28, 2015 at 2:09
  • 1
    \$\begingroup\$ Sorry, I do. Maybe hashing the game state might be useful but you haven't described how to hash it or why it's (realistically) useful, much less why it's relevant. \$\endgroup\$
    – JPtheK9
    Commented Apr 28, 2015 at 2:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .