1
\$\begingroup\$

Wondering how state synchronization works in games with lots of players like MMOs. It seems like a hard problem to solve and I am not aware if there are standard solutions. Specifically, synchronizing game clients (users playing game) with an array of centralized servers, and then broadcasting and merging the state with all the same connected clients. How it is done (and how efficiencies are implemented) typically, and what the structure of the game state is like.

To simplify this question, I am thinking in terms of a simple asteroids game:

enter image description here

You have n number of players, and the asteroids, players, and bullets are synchronized across clients. I am not familiar with how the game state should be modeled (if it's some quadtree thing you are sending around, or just a vector of patch/updates, etc.). There could be players all over the world, so latency is a factor.

\$\endgroup\$
  • 1
    \$\begingroup\$ Possible duplicate of What data to exchange in multiplayer real time games? \$\endgroup\$ – Ferreira da Selva Jul 3 '18 at 2:40
  • \$\begingroup\$ "How games do X" rarely has a clear concise answer, since there are many games, using many.different techniques to solve different related problems. You'll often get better, more actionable answers, faster too, by asking "How can my game do X?" together with a detailed description of the context of your game and the particular needs of the feature / constraints of the problem you're solving. \$\endgroup\$ – DMGregory Jul 3 '18 at 3:42
  • \$\begingroup\$ @DMGregory I've narrowed it down to Asteroids, let me know if I can simplify further. Thank you for your help. \$\endgroup\$ – Lance Pollard Jul 3 '18 at 4:48
  • \$\begingroup\$ This is still extremely broad. Can you walk us through a concrete example of the synchronization scenario you're having trouble with? (eg. "Player 1 sends their movement vector to the server, the server validates that movement and updates Player 1's position, and updates the sector Player 1 is in. In the next tick, the server sends Player 1's position to all players in adjacent sectors...") \$\endgroup\$ – DMGregory Jul 8 '18 at 15:16
3
\$\begingroup\$

Is it possible to save the game's current state to disk?

If yes (hint, the answer is always yes) then you have a means by which you can synchronize players. Even if it is horribly inefficient. But optimization is just a matter of working out which bits and bytes any given player doesn't need, either because:

  • they already know (eg, what level is being played and it hasn't changed)
  • they are the data source (eg a player doesn't need their own user name)
  • they can't know (eg stealthed players in WoW are not sent to other players until detected otherwise someone could write an external program that could detect and display that information, bypassing the mechanic1 )
  • they don't need to know (eg. That other player on another level is irrelevant)

If no, you need to refactor.

1 The "stealth broken" / "hidden player detected" sound effect was actually an accident of this. When the client got told about the stealthed player, it spawned them an immediately applied all of their buffs, playing the associated sound effect for each one. This was fixed during development to only play the "entering stealth" sound to avoid eat-bleed, but the audible clue hasn't been planned and ended up being an elegant solution to an unknown problem.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.