0
\$\begingroup\$

I am currently programming a multiplayer game. The basic idea is that the game uses Command Pattern for any actions that happens in the game. If the player right clicks to move then a command is issued to the selected object to move to the location.

I implemented gRPC to include multiplayer. Here is my problem, when the player right clicks on the ground I send a gRPC call with that command then the server acknowledges the commands and sends it back to all the clients, the client then processes the command and everything goes well. Now if the player enters the game while a command is underway the client never received that command so its never process on the client.

What would be a good way to fix this problem without sending the info of all the actors (x,y,z) and what they are doing at each server ticks?

Thanks!

\$\endgroup\$
2
0
\$\begingroup\$

The way I'm handling this in the server I'm writing at the moment is to have the server keep track of the current game state after applying each command. The commands are instantaneous transactions that modify that state.

That doesn't mean we teleport the unit all the way to the destination. Rather, it means we instantaneously set them into a "moving" state, with state information about their destination or path.

That means there's never a command "underway" or "in progress". Any command whose ultimate result takes time to execute has an immediate result, putting the game entities into a persistent executing state. Now the command can be forgotten, and the state carries on the work.

When a new player joins, the server sends them a complete dump of the world state as of all the commands and game simulation ticks it's processed at that time. So they have the net result of all past commands, giving them the same starting point for any future commands.

As an example: if you told a unit to move from 0 to 10, and I log on when the server's copy of the unit has reached 5, my state dump says "Unit at {position 5}, in state {moving to {position 10}}"

Now I can continue to apply command deltas on top of that state, in the same order they were processed on the server, to obtain a state consistent with the consensus.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the reply that should do the trick, what frequency would the server send update to all other clients ? \$\endgroup\$ – Mathieu Landry Nov 11 '20 at 18:52
  • \$\begingroup\$ That depends on your game. I'm making a somewhat turn-based game, so my updates can probably get away with being much less frequent than yours. \$\endgroup\$ – DMGregory Nov 11 '20 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.