1
\$\begingroup\$

I know this question has been asked and answered in some threads, but I'd like a more beginner dumbed down explanation.

So player information, specifically direction and position, need to be updated constantly, for tons of players at the same time.

Let's just say 10 players in the same room move an inch in some direction. All of the other players need to see that instantly, obviously. I realize that saving the location to the database, and getting the location for everyone to see is a horrible idea.

So I guess my question is... how does this work? What happens if a player alt-f4's or kills the game process without saving or doing a "normal" exit? How often should I save the location to the database?

Thanks

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

This is handled by what some networking APIs call "ghosting". When a player's position changes it marks a flag (boolean or bit) dirty, and periodically (every 300-500ms or so) the networking system will grab all information that has been marked dirty and send it to every player that is in range of the player whose information is dirty. Additionally, whenever a player comes in range of another player, both of those players are sent the entirety of each others information (only the info that they need to know about each other, such as position, or rotation).

Here's some more information I've written about ghosting: http://nic-gamedev.blogspot.com/2011/11/mmo-architecture-creating-ghosting.html

An example of this. Let's imaging there are 2 players in range of each other (Players #1 and #2), and a 3rd player just out of range (Player #3).

  1. Player #1 moves around a bit. This marks his position as being dirty, the networking system records this change.
  2. Sometime in the next few hundred milliseconds, the networking system goes through all dirty flags it finds, and finds that Player #1's position is marked dirty. It then adds that information, and any other information about player #1 to a packet and sends a copy of that packet to any player in range.
  3. Player #2 receives the packet and updates the information that it has for player #1. Generally prediction algorithms come into play here so that player #1 doesn't just teleport to the new known position, but rather interpolates towards it over time.
  4. Player #3 walks into range of player #1 and player #2.
  5. The networking system sees that player #1 and #2 are new to player #3, and player #3 is new to player #1 and #2, so it sends player #3 all of the necessary information from player #1 and #2, and sends them player #3's information as well.

Any player that leaves range results in a message to other players that had the player in range, so that they may remove them from their client. Generally the client will keep information about a player leaving range around for about 30 seconds in the case that the player continues to enter and leave range, so the server doesn't have to continuously send down all of that player's information every time the player re-enters range.

\$\endgroup\$
1
  • \$\begingroup\$ Very cool stuff. Thanks for the reply, and I'll definitely read your post on ghosting. \$\endgroup\$
    – Jesse
    Commented Apr 24, 2012 at 19:59
0
\$\begingroup\$

In simple terms the Server is running a master copy of the game and each player's Client is merely acting like a playback of what the Server tells it is happening. This leads to more pieces directly related to your question.

First piece is that the client sends commands to the server like "I want to move over here(xy)" and the server is what actually moves the player. The player's client then receives an update with his move. In this way no matter what the client says the server is in control. Because this raw data is jumpy you will see terms like "client side prediction" which is used to smooth out these updates.

Second piece is that the fastest parts of the game on the server are kept in memory and only occasionally saved out to a database, this is called "persistence," or "persisting the game world;" someone who kills their game stops sending commands to the server and whatever their last info was is what gets stored into the database and restored when that player logs back in again.

That's really all there is to it, without all the complex technique names and details getting in the way.

\$\endgroup\$
2
  • \$\begingroup\$ I left out "how often," and the answer varies. Some big MMOs seem to cycle simple database saves every 5 seconds and complex, full state saves every few minutes. Smaller games may save more often because the load isn't as great. Players are obviously most happy if they never lose any "time" to a crash so it's all a tradeoff of processing and database speed. \$\endgroup\$ Commented Apr 24, 2012 at 19:56
  • \$\begingroup\$ Ahh, alrighty, thanks. I have some google search terms now! :D \$\endgroup\$
    – Jesse
    Commented Apr 24, 2012 at 20:00

You must log in to answer this question.

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