📜 ⬆️ ⬇️

Do not use Lockstep in RTS strategies

Hi, Habr! I present to your attention the translation of the article Don't use Lockstep in RTS games .


Lockstep lost! The client-server model won and became the standard for most games. Real-time strategies were the latest, but Lockstep is used less and less. Let's find out why, but first, what is Lockstep?



In games there are several players playing the game on the client. But how to make sure that they play the same game? Using Lockstep, all clients run the same code, with the same parameters and input data. For example, if one of the players orders the army to go to the specified point, this command is transferred to all customers and all of this army moves to the specified point. Even a generator random pseudo-random numbers should be the same for everyone, usually this is done by using the same seed at the beginning of the game and doing everything in the same order. This is very effective from a network point of view, because only commands are transmitted. Things like an order or action take up very little space in a network package.


Lockstep is a very effective model of network interaction, but is difficult to implement due to out of sync problems or differences between compilers / different platforms. Lockstep was used in the past because network bandwidth was very low. It worked great. Conceptually, it is very easy to add it to an existing game. For example, DOOM, which was already written and everything worked. To add multiplayer, John Carmack had to run commands on each computer. This is very easy in theory, before the delays or differences in architecture ruin everything. In practice, it is difficult to do. The programmer must make sure that all commands are executed in the same order on each client. What if someone didn't get the team on time? The client must wait for confirmation of receipt of the team from all clients. What happens if someone reconnects? The first thing that comes to mind is to simulate the whole game from the very beginning, which can take quite a long time.



Using Lockstep, the programmer must make sure that the compiler does not optimize operations with floating point numbers, because different processor architectures may have small differences as a result of the same calculation. This is especially noticeable if you try to synchronize your PC and iPad. Architectural differences are a nightmare for Lockstep. If you are working with HTML5 -Javascript, JIT can optimize computations in different ways, making small errors that can lead to big changes. Programming Lockstep - how to hold a lot of weight on the tip of a knife.


If this is not enough for you, Lockstep uses p2p, inheriting all the problems of the second. If you are using TCP, you will not be able to connect any two computers via the Internet due to firewalls, NATs, proxies, VPN ... etc. With UDP, there is a chance to make hole punching. Fortunately, browsers support webRTC , which works via UDP and has an API for hole punching via a STUN server. Though this part can be made using HTML5.


What is the client-server model? It's easy when a client joins the server and the server sends updates to the client. Done! The server and client can use different code, in different languages ​​and even platforms. The server has full control over the game. There is no knife, on the tip of which you need to hold something. The main problem is that the server should send more updates. This is because the movement of each unit, the bullet shot, the change in health must be synchronized. Fortunately, the network channel of users is expanding and cheaper than the time of the programmer.


The reason why RTS used Lockstep was the width of the channel. In FPS, the movement of 32 people does not require a lot of traffic. At RTS, a 1000 movement requires more traffic, but the channel width allows it.


Client-Server model is more resistant to cheaters. Using Lockstep, every client knows everything about the whole game. For example, the fog of war is the client part, the client in reality knows what is behind the fog, but does not show it. Also, everyone knows the IP and open each of the clients and can spam enemies - micro DDOS. In the Client-Server model, the server simply does not send updates beyond the fog of war, and only the server knows the IP of other clients. Of course, a client can make a DDOS attack on the server, but servers can more easily counteract attacks and can block clients with suspicious activity.



Lack of servers - they cost money, while for Lockstep servers are not needed, all are p2p. It is good that there are providers who can rent a server. But if it is still too expensive, you can run one server on one of the clients ... it looks like Lockstep ... except that there is one authorized client, and that it has more load.


Examples:


  1. StarCraft 1 used Lockstep, while StarCraft 2 uses the Client-Server model.
  2. Supreme Commander 1 uses Lockstep when newer games, such as Planetary Annihilation, use the Client-Server model.
  3. DotA was launched on the Warcraft 3 engine that used Lockstep, but Valve uses the Client-Server model for Dota 2.
  4. DOOM used Lockstep but Quake uses the Client-Server model, Lockstep was not at all popular in FPS.
  5. MMO never used Lockstep because it is not applicable to so many players.

The development of programming, cheaper computers, and modern Internet speed make Client-Server easier to apply than Lockstep. Lockstep will be used less and less.


')

Source: https://habr.com/ru/post/337374/


All Articles