3
\$\begingroup\$

In games like Half-Life 2, Team Fortress 2 etc, when you play against other players online, your local game communicates with a game server.

If you've built one of these games, what sort of information is sent by your local game to the game server, and what sort of information is sent to you by the game server?

I recall reading that in Team Fortress 2, the computer tracks the trajectory of every projectile including every bullet, rocket. It seems like that would generate a tsunami of messages, yet my game works reasonably well over distinctly average broadband.

I've noticed gaps in the magician's curtain when severe lag occurs. Sometimes other players "teleport"; they're not where I think they are. Other times, I can peer around a corner and be killed when there's no-one there; except shortly after I see the other victorious player.

So roughly, what is being communicated over the network to create the illusion of real time?

I'm generally interested in simulation games but have never built one. I'm just trying to get a feel for how it's done.

Let's start with

  • The position x, y, z, speed, and direction of every player.
  • Player switches weapon
  • Player fires/stop firing.
\$\endgroup\$
0
\$\begingroup\$

I have not implemented a network strategy myself, but I have already read some related texts and thought about network solutions for my game engine project. So maybe I can give you a small overview.

I recall reading that in Team Fortress 2, the computer tracks the trajectory of every projectile including every bullet, rocket. It seems like that would generate a tsunami of messages, ...

It isn't really necessary to update everything every frame of your game loop. Many things can be omitted. For example: For a bullet, all you need to know to describe it's movement is the time and direction it was fired and some additional data that influences the trajectory like initial movement speed and external forces (gravity, drag, etc.). With this information, every computer can calculate the current position on its own. They might come to slightly different results due to different time steps, floating-point errors or hardware, but as long as they do not have relevant impacts on the worlds state (hitting a player/destroyable object, change environment states, etc.) it doesn't really matter if the point of impact varies by 2cm between 2 computers. So you just need to sync those projectiles that might affect the game world's global state and only in the time range where this is going to happen.

It is not really that much different for player movements. The player just hits a button at a certain time to trigger an action. It is not like the player is actually controlling every limp himself. His computer calculates the resulting animation state and movements which can be recalculated on every other computer that has the same information. So you just need to know at which time another player performs which action and you computer can more or less predict his movement and animations in the next frames.

Another optimization is to just let the server send data to a player that is actually relevant for him. Something a player can't see and that can't affect him doesn't need to be synchronized. So the server can decide based on the player's location and viewing direction what is relevant for him.

I've noticed gaps in the magician's curtain when severe lag occurs. Sometimes other players "teleport"; they're not where I think they are. Other times, I can peer around a corner and be killed when there's no-one there; except shortly after I see the other victorious player.

Due to the network latency, all the updates you get from the server arrive usually "too late". You get the information about what another player did a certain amount of milliseconds ago. However, your computer can predict what he is probably doing "now" from that information. There are some techniques to avoid jumps in movements and animations due to getting updates too late.

For example, if you get the information that a player changed his movement 100ms ago and your computer mispredicted it, instead of instantaneously moving him to the correct position you can just speed up his movement into the correct direction so that his position on your computer will be synchronized again a few frames later. Usually, you won't notice the slightly increased speed. Of course, if the latency gets too high (lag), you can't hide such mispredictions anymore and it is probably better to just resync everything with a big jump even though I have seen games where everything turns into turbo mode for a short time.

If you've built one of these games, what sort of information is sent by your local game to the game server, and what sort of information is sent to you by the game server?

A player only needs to send changes in his direct actions to the server (movements, firing, using stuff). He might send additional data on how his computer predicts the outcome of his actions (who/what did he hit), but this depends on how your network system handles latency related conflicts. The server, on the other hand, only needs to send data to a player that does affect him and what he sees, and that invalidates previous updates the client got.

Conclusion

Generally, you only need to update the state of moveable objects over the network if their behavior changes in a way a computer can't predict with the information he has. For example changes in animation state, velocity, movement direction, etc. Additionally, you only need to update the data if it is relevant for the client.

You might also perform resyncs for every object from time to time to avoid obvious jumps due to the accumulation of small prediction errors, but depending on the object and your game this can be done at very low frequencies so that it doesn't affect the network traffic significantly.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

It's less a matter of what data is passed, though that which can be made deterministic would be better so, and more a matter of how often that data must be passed.

Michael Abrash talks a bit about perceptual latency reduction:

http://www.jagregory.com/abrash-black-book/#how-we-spent-our-summer-vacation-after-shipping-quake

In the subsection on QuakeWorld.

From personal experience playing HL2DM with another player sitting at my desk, only the larger sub-set of physical objects align, instance to instance. The scrap is primarily for glitz and appears to be randomly perturbed client-side.

On TF2, I doubt very much they are tracking each bullet in any literal sense(rockets are another story). I suspect the bullet is spawned with a directional vector and length(this would be shared over network), and any dynamic object that intersects over a short life-span can be hit-detected. Think laser logic.

In the long run, and the biggest data hog, the real problem is with cheat protection and prevention. Even with a total client-side data set being passed to server, the server would still have to have a complicated rule-set by which it determines the feasible viability of any given client-side state in relativity to the game state as a whole. In this day and age bandwidth is hardly as expensive as server-side processing cycles.

On a final note, and academically interesting, if not directly to your question, Korean shooters, Gunz by MAIET, for example, seem to pass almost nothing to server, and very rarely. They are almost unchanged in behavior by a 120ping. This is self evidently achieved in two ways: One, the other player-characters are, for all intents and purposes, AIs that are bound to the approximate location determined by the opposing-player client, targeting the antagonistic-player avatar that is being targeted, using the correct weapon, and not dead; Point two, player health is extremely fuzzy and plentiful, allowing for a whole lot of slop. That isn't to say these games can't be fun, just apples and oranges to the precision tournament-shooters of old.

Dave Oshry discusses the relative failure that is DuskWorld as well as the laggy hit-detection of the modern-shooter: https://www.youtube.com/watch?v=-FoFXPrEphM

| improve this answer | |
\$\endgroup\$

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.