Network‎ > ‎

Latency

Lag :(

Network latency is the time it takes a data packet to travel across the network from sender to receiver. The affect of this in a multiplayer game is a delay between the input of a player and the result of the action. That delay is known as lag and it's a word that should always be screamed out in anger. A game need to be able to handle the constant latency that the player experience up to a expected max latency allowed. What that max latency is varies with the game as some games have less problems with latency then others. Around 150 ms for action games. Then the game need to be able to handle that there are spikes of higher latency as networks messages get lost, corrupted and resent. If there is to high delay so the game fails to continue the peer will be disconnected with a timeout. Latency is not only a technical problem but also a design one as the design need to be made to minimize the problem with it.

Server
When the server sees the control data from the clients they are for actions that the player wished to perform some time in the past. As they arrive they are already latancy milliseconds old and the world the player did base his actions on was also latancy milliseconds behind the server. This can be a problem in games with fast gameplay. In a shooter someone can move so much that another miss a headshoot or in a fighthing game one can miss a block and die.

Nothing (server side)
For games with indirect control it might not matter if a message is handles with a small delay. A RTS game can hide the delay by making the unit's respond with voice conformation and then start the movement when the message arrive at the server. To hit your target in a first person shooter with a instant hit weapon you would need to lead your target where it would be in the future depending on your latency to the server.

Rewind (server side)
The server keep a history of the states of the important object in the game, players in a first person shooter. The history only needs to be a second or two long. When a fire message arrive from a player the server can look when in time the player fired the shoot and look up in the history where everyone was and who would have been hit.
Thrust (Client side)
The client can tell the server what they are doing and the result for it. So if the client shoot someone they tell the server that they fired the gun and what they hit. That makes it a bit easy to cheat for the client. Verifications test can be performed on the server to verify that the hit the clients gives seems plausible.


Client
As states arrive they are latancy times old so the clients world is behind the server. One now needs to pick what to do with the new state that has arrived. There are two main options, extrapolation and interpolation.

Extrapolation
When a object state is received from the server the client set it as the new state. Then until a new update arrive it extrapolate the objects future state based on the last one. If something moves the client will assume it keeps moving. When a state update arrive the client will update the object again and the goal is that it will almost in the correct state already. Different types of objects can use different extrapolation rules so a plane does not act the same as a helicopter.
Interpolation
Interpolation adds a artificial delay to the game to get a smoother display of the world. The client takes the last state and the new state and interpolate towards the new state. When a new state arrives it starts interpolating towards that state instead. So it will add an extra delay of time between state updates to the percived latancy. If a new state does not arrive in time the client starts to extrapolate the objects until a new state arrive.

Client Side Prediction
The client have all the input it will send to the server. It can use that to predict the behavior of objects the client interact with. That is called Client Side Prediction and later when a new state arrive it will hopefully verify what was predicted. If not we have to interpolate our version of the game object to fit the one the server gave us. The common objects to predict are the ones the player control directly such as his character, the car he drives of the plan he flies.

Fighting Latency on Call of Duty Black Ops III - 2016


Comments