[ad_1]
I’ve made a TCP-networked RTS, through which I handed the instructions themselves, reasonably than the outcomes of the instructions. For occasion, a participant provides a transfer order. If the transfer order is legitimate in response to that shopper, it’s despatched to the server. The server then sends it again to all purchasers, who validate and execute it.
So all shopper machines run the sport themselves, the server code accepts messages and sends them again to all purchasers. If a shopper provides a transfer order, it will not begin executing it till it’s acquired again from the server.
The server sends a ‘tick’ quantity at which to execute the command as nicely, which is a couple of ticks forward of the ‘present’ tick. This manner all instructions may be executed on the similar ‘tick’ on all machines.
One profit this methodology is that it does not rely on any particular person shopper machine to validate the command. If I handed the outcomes of the transfer, I’d have the ability to hack it to maneuver my models sooner. All purchasers must execute the identical command and if one machine executes it otherwise, it will likely be apparent.
Validating the command client-side earlier than sending it to the server is not obligatory, however in principle it saves community visitors. I used the identical validation code to inform the UI that the transfer was potential, so it did not require writing further code.
As for what the messages may appear like. I wasn’t involved with extremely effectivity because it was my first networked sport. I handed instructions as strings. The instructions could be formatted like this: "<player_id>:<command>:<parameters>"
For a contrived instance, a transfer command may appear like this: "3:transfer:522:100:200". This means Player 3 needs to transfer unit 522 to (100,200).
The server passes the command on to all purchasers, together with the one who despatched it, with a tick quantity hooked up like this: "153238:3:transfer:522:100:200".
Then the purchasers would all execute this command when tick 153238 is executed.
[ad_2]