Eli5- How does video game de-sinc work?


I remember a while ago me and a buddy were driving around in GTA in my car. Then a weird thing happened where on his screen we slammed into a wall and on my screen we teleported up into the air. A second later everything was normal and I kept driving as if nothing happened. And yet my bumper was damaged as if I had run straight into the wall that my friend had seen for a split second. So what actually happened? How dies this stuff work?

In: 1

So, you’re playing a game with your buddy on the couch. For simplicity, let’s put GTA aside and imagine it’s a really simple game, like pong. You move your controller – the console updates the position of the bat and you see it move on screen. He moves his controller and the console moves his bat. It can update fast enough that as far as you can tell there’s no delay.

Now, take that same game but you’re in different locations playing over the internet, with a distant server keeping track of the bat and ball positions. Trouble is, now there’s a noticeable signal delay between between you and the server. If you have to wait for the signal to get to the server and back before you see the bat move, the game will feel very laggy – possibly unplayably so. So your and your buddy’s consoles keep their own versions of the game state, so they can update responsively. But they can disagree about what’s going on in game, because they get inputs at different times. In this case, they defer to the server as the definitive source of what’s going on. You might see on screen that you hit that ball, but if the server says you missed, then your screen has to change to agree with it.

Imagine you and a friend try to play chess over the phone. Each of you has a board in front of you and on your turn you tell your friend what piece you want to move to which tile, allowing both of you to adjust the boards accordingly. That’s already pretty close to how synchronisation works.

Now, since both of you are way too trusting we need a 3rd party to make sure your moves are actually legal. Let’s call that guy Sever. When you decide on your move, you execute it on your board, then you tell server about the move who in turn matches the move on his board, checks if its legal and at last fowards it to your friend.

Server, however, is a rather impatient guy. So when you forward him a move that would be illegal, let’s say moving your king 2 spaces forward, he will just move it 1 space, tell that to your friend and tell you to move yours 1 space back (That’s what probably happened in your case). Another example would be either you or your friend losing connection. This doesn’t work with the whole chess example but the server would basically treat it as you just continuing whatever you were doing when it happened, e. g. If your char was running forward you would continue until you reconnect or the server notices you’re missing and kicks you.

This is of course very generalised for the sake of eli5. Like most things in software, synchronisation works the way the programmer decided it should. For multiplayer games it’s common for the server to check if the whatever one player does is legal. That’s why minecraft spamms you with messages about flying not being allowed if you move faster then what should be possible for example. In the earliest days of World of Warcraft the server didn’t check what spells you were allowed to cast so you could edit the outgoing packages to pretty much anything including spells belonging to raid bosses. Every game that allows you to host something skips the whole extra server bit by essentially turning the hosts game into the server.