How do online multiplayer games work so well despite so many differences in the systems behind each user (processing power, internet speed, display refresh rates)?

718 views

How do online multiplayer games work so well despite so many differences in the systems behind each user (processing power, internet speed, display refresh rates)?

In: Technology

7 Answers

Anonymous 0 Comments

Game developers use several tricks to make the process seem seamless:

1. Most of the stuff you see in the game is never sent to the server. All of the pretty graphics and character models and level design is just ignored. You can load the level map once at the start of the match, and just keep a copy on the server, instead of sending it back and forth, for instance. What’s actually sent back and forth is really just a short list of numbers: the position, speed, and acceleration of each player, along with which way they were looking, as well as the same for any projectiles, abilities, etc. Each one of these is sent with a timestamp, for reasons I’ll come back to. So, if you have 20 people in the server, plus bullets, spells, npcs, etc. you only have to send a couple hundred numbers back and forth, which is less than a kilobyte of data. This gives a reasonable chance of sending everything quickly enough.

2. The server stores a short “history” of what happened over the last fraction of a second. This is where the time stamp comes in. By the time the notification that you shot your gun gets to the server, it has been a little while since it happened. The server takes the timestamp when the shot occurred, and looks up where everybody was at that time, and decides whether your shot hit at the moment you fired it, and then sends its decision to you and the other players. This is why you can sometimes get hit behind cover, you were shot at a few milliseconds ago, and by the time the server realized you got hit and sent that information back to you, your local computer thought you had safely made it to cover, and has to “catch up” and retroactively apply the damage.

3. The server isn’t updating constantly, only in predefined “ticks”, typically say 60 per second. So, every 1/60 of a second, the server checks if anything happened that needs to be told to all of the player’s computers and sends that out as a batch. If the server wants to store the last 0.2 seconds of gameplay to account for lag as I described above, that’s just the last 12 “ticks” that get stored. This means that it doesn’t matter if the computers of the various players are running at different rates, so long as they can connect to the server around 60 times per second, and never wait more than 0.2 seconds the connection will appear seamless.

4. You only notice problems if your latency is longer than the longest time that the server stores, then your local machine guesses what happened based on its last good information, and you abruptly snap to a different position when the server finally does reconnect to your computer and tells you where everybody actually is. This is what causes the symptoms of “lag”.

You are viewing 1 out of 7 answers, click here to view all answers.