+ All Categories
Home > Documents > Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Date post: 02-Jan-2016
Category:
Upload: wylie-durham
View: 43 times
Download: 0 times
Share this document with a friend
Description:
Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization. I’m Curtis. Networked FPS games are difficult to make But not too interesting if they’re not networked Broadband is pretty nice But we can’t rely on it . Basic Architecture. Client / Server set up - PowerPoint PPT Presentation
30
Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization I’m Curtis
Transcript
Page 1: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Latency Compensating Methods in Client/Server In-game Protocol

Design and Optimization

I’m Curtis

Page 2: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• Networked FPS games are difficult to make– But not too interesting if they’re not networked

• Broadband is pretty nice– But we can’t rely on it

Page 3: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Basic Architecture

• Client / Server set up– Server handles logic– Clients (initially) just to get player input

• Simplified version below

Page 4: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Client Frame Loop

• Sample clock to find start time• Sample user input• Package up and send movement command using simulation time• Read any packages from the server from the network system• Use packets to determine visible objects and their state • Render scene• Sample clock to find end time• End time minus start time is the simulation time for the next frame

• What about ‘framerate jitter’?

Page 5: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Server Loop

• Sample clock to find start time• Read client user input messages from network• Execute client user input messages• Simulate server-controlled objects using

simulation time from last full pass• For each connected client, package up visible

objects/world state and send to client• Sample clock to find end time• End time minus start time is simulation time for

the next frame

Page 6: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Not the only way to do it

• Suggestions?

Page 7: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Half-Life User Input

• Most important fields in the struct are– Interpolation time on client– Duration in ms of command– Command view angles– Forward/Sideways/Upwards velocity– Attack buttons– Other stuff

– Any comments?

Page 8: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

So here’s what happens

• Client creates and sends a user command to the server

• Server executes the command and sends updated positions of everything back

• Client then renders the scene

• Simple, and doesn’t do well in real situations. Why?

Page 9: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Client is too stoopid

• All it does is react. If there’s a certain amount of latency the client has no choice but to wait.

• So what does the client need to do?

Page 10: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Client Side Prediction

• One option: perform it locally and assume the sever is going to be cool with it.– Client still not in control– Server will shove objects back where they

should be– Can look pretty crappy

Page 11: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

A better way

• Client samples input (same)• Client sends off the commands (same)• Client keeps a copy of each command and

when it was generated (different!)• First perform the last acknowledged

movement from server• Then performs any outstanding

commands in a similar method as the server would.

Page 12: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Algorithm for last slide

“from state” /*state after last command acknowledged by server*/

“command” /*first command after the from state*/

while (true){

run “command” on “from state” to generate “to state”;

if (this was the most up to date “command”)

break;

“from state” = “to state”;

“command” = next “command”;

};

Page 13: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• Client will run same commands over and over until acknowledged

• Sounds should not be re-created

• Server should not send info predicted by the client.

• Client still has to re-run the old commands

• Fix: client marks those not yet predicted and only plays if it’s the first time

Page 14: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Client only state data

• If none, just use last state from server as a starter and run prediction commands

• If any, you need to store the intermediate results of prediction

• Store them in a ‘sliding window’

• Actuate them as they should be, using server acknowledgment

• So far, just using this for movement

Page 15: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Weapon firing

• We can do the same as the last slide for weapon firing

• Need to know– Which weapons are being held– Which is active– How much ammo each has

• Can be complicated if client and server shooting logic is difficult

Page 16: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Why stop there?

• This leads us to also predict . . .– Weapon switching– Deployment– Holstering

• “Umm, This is a Lot of Work”– Do they expect us to do this for MazeWar?

Page 17: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization
Page 18: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• You still need to have a feel for your latency to determine how to lead your targets

• Quake3 made a sound when you hit someone to make it easier

• Jitter will make it very hard to get a good feel

Page 19: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

But enough about me . . .

• Now we need to worry about rendering the other players correctly

• Two main methods – Extrapolition and Interpolition

Page 20: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Extrapolation

• Other players/objects simulated forward in time• Works nicely for people running in straight lines• Bad news: many players move like Mexican

jumping beans with too much coffee• Can clean this up a bit by putting a limit on the

extrapolation time• This can make it so there is less warping, which

will hurt gameplay and nullify the reason for putting extra work in

Page 21: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Interpolation

• Always moving objects in the past

• Slow render a bit to compensate for some lag

• Missed a packet?– Extrapolate the player position– Or have the player rest (and stutter the

movement)

Page 22: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Interpolation Algorithm

Each update contains the server time stamp for when it was generated

From the current client time, the client computes a target time by subtracting the interpolition time delta (100 ms)

If the target time is between the timestamp of the last update and the one before that, then those timestamps determine what fraction of the time gap has passed.

This fraction is used to interpolate any values (e.g., position and angles

Page 23: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• It’s basically buffering an additional 100 ms of data on the client

• Any longer is a trade off, since the smoother vision will make others harder to hit

• It requires a fixed time interval between server updates

• Problems?

Page 24: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Interpolation visual quality

• For example: if the player is jumping around they spend the average of the time at the middle of their jump

• If we interpolate at the last position they might just be seen floating up and down without ever reaching the ground or the height of their jump.

Page 25: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Vision fix

• Each server update creates a new position history entry

• Search backwards through the history looking for a pair that straddles the target time

• What if something was SUPPOSED to teleport?

• Set a flag

Page 26: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

Lag Compensation

• Normalizing server-side the state of the world for each player as that player’s user commands are executed.

• Algorithm on the next page

Page 27: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• Before executing a player’s current user command, the server:– Computes a fairly accurate latency for the player– Searches the server history (for the current player) for the world

update that was sent to the player and received by the player just before the player would have issued the movement command

– From that update (and the one following it based on the exact target time being used), for each player in the update, move the other players backwards in time to exactly where they were when the current player’s user command was created. This moving backwards must account for both connection latency and the interpolation amount8 the client was using that frame.

• Allow the user command to execute (including any weapon firing commands, etc., that will run ray casts against all of the other players in their “old” positions).

• Move all of the moved/time-warped players back to their correct/current positions

Page 28: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• Now a player can directly aim at other players without wondering if they’re actually there.

• Is this fair?

Page 29: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• Well, someone with a lot of lag could shoot someone with less lag after that person had taken cover . . .

• But does that happen very often?

• Who is right in those cases?

• Half-Life gives the points to the shooter

• Probably because it’s more fun to shoot

Page 30: Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization

• So, it’s still inconsistent with a perfect view of the world

• But the benefits still outweigh those inconsistencies

• Benefits?


Recommended