Saturday, June 16, 2018

networking - How to implement lockstep model for RTS game?


In my effort to learn programming I'm trying to make a small RTS style game. I've googled and read a lot of articles and gamedev q&a's on the topic of lockstep synchronization in multiplayer RTS games, but am still having trouble wrapping my head around how to implement it in my own game.


I currently have a simple server/client system. For example if player1 selects a unit and gives the command to move it, the client sends the command [move, unit, coordinates] to the server, the server runs the pathfinding function and sends [move, unit, path] to all clients which then moves the unit and run animations. So far so good, but not synchronized for clients with latency or lower/higher FPS. How can I turn this into a true lockstep system?


Is the right methodology supposed to be something like the following, using the example from above:


Turn 1 start



  1. gather command inputs from player1

  2. send to the server turn number and commands

  3. end turn, increment turn number



The server receives the commands, runs pathfinding and sends the paths to all clients.


Next turn



  1. receive paths from server, as well as confirmation that all clients completed previous turn, otherwise pause and wait for that confirmation

  2. move units

  3. gather new inputs

  4. end turn


Is that the gist of it? Should perhaps pathfinding and other game logic be done client side instead of on the server, if so why? Is there anything else I'm missing? I hope someone can break down the concept, so I understand it better.





No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...