Members - Reputation: 432
Posted 04 June 2012 - 10:54 AM
Basic activities have so far been pretty simple. A Unit moves, send a MoveUnit command to the client. Building gets destroyed, send a DestroyBuilding command to the client.
But now I'm starting to get into more complex activities. For example, let's say you have an action you perform at a building, which gathers multiple idle units of different types, sets them to move to the selected building, and then once they all arrive, merge them to create a new super unit. From the player's perspective, they just performed a single command. But on the server, multiple things are happening. Moving units, changing each unit's home building, creating a list of required units and waiting for each one to arrive, then destroying all of them and creating the new super unit.
My first thought was to send each little action as a separate command to the client, as I was doing before with the simple activities. Essentially, treating the client as a puppet and telling it exactly what to do at every step. However, I'm thinking that this will be overkill in terms of network traffic. And, in some cases, I wonder if the client should know more about the bigger picture, in order to better communicate that to the player.
The alternative would be to send a single command regarding the creation of the super unit, communicate the list of units to be used and what building to use, and then let the client figure out the details of navigating units and such. That fixes the bandwidth concerns and lets the client know more about what is going on. But it also makes me wonder if I would be risking the client and server going out of sync if I leave details up to the client. Just "assuming" the client is doing things right.
I know that if the server and client are running the same code for performing this command, then there shouldn't be any issues (in theory) with them making different decisions on how to perform the command. But, because the client isn't really simulating the game, only being told what is going on after the fact, I wonder if there might be issues with it not knowing enough about the game environment to simulate it properly. The client starts moving a unit to the building, but the unit passes over a part of the map that the client hasn't seen. The server knows there is an enemy building in the way, but the client doesn't yet. As soon as the unit gets close, the server tells the client about the building. But now it is up to the client to change the unit path to navigate around it properly. Is it going to make the same decision as the server, with the server knowing everything? What if the client is still navigating those units to the building when the server decides they should have already arrived, and the server starts sending commands to move the super unit, which the client hasn't created yet?
Am I being overly paranoid? Is it best in this sort of situation to treat the client as a puppet and feed it every little step, at the expense of network bandwidth, or are there ways of safely generalizing commands for the client to perform on its own?
Crossbones+ - Reputation: 7117
Posted 04 June 2012 - 10:58 AM
Edited by SimonForsman, 04 June 2012 - 10:59 AM.
The voices in my head may not be real, but they have some good ideas!
Moderators - Reputation: 18214
Posted 04 June 2012 - 11:00 AM
If your server is authoritative for things like units moving, then it needs to be authoritative more or less uniformly. Allowing clients to do their own thing based on high-level commands is indeed begging for desyncs unless you have taken extreme care to keep everything in lockstep from day one. You might be unpleasantly surprised about how much drift you can get between client and server based on trivial things that you'd never think about, especially if you do any floating-point arithmetic.
Determinism is certainly possible with enough effort, but if you haven't aimed for it from day one (or if you aren't willing to do a huge amount of re-engineering) then it's a pipe dream.
I would suggest compiling some actual numbers for your bandwidth usage. If your list of commands to accomplish the super-unit construction is only 200 bytes, then who cares? If your single Move command is 200 bytes, then you need to do some more fundamental optimization to begin with.
Some context on how much you're actually sending across the wire would be very useful.
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]