Player prediction across clients, minimizing latency

Started by
9 comments, last by Ollhax 12 years ago
Hi there! I'm working on my network code and I've run into a minor snag that someone perhaps can help me with. I went with the Quake 3 network model and I've used Gabriel Gambetta's excellent blog posts as a reference when implementing the finer points such as server reconciliation.

However, there's a situation that occur when there's more than one client in the picture. Lengthy example ahead:

Say that Client A runs three frames, then decides to send an update to the server. I.e, three input structures are sent to the server.

The server receives the update after a few moments, say SendTime(Client A) or ST(A) time units later. The three inputs are queued for Client A for three server update ticks in the future, meaning that the server will be fully up to date with the client after ST(A) + 3 ticks. This is all fine and dandy, since Client A's prediction and server reconciliation will hide all this latency for Client A.

What bothers me is when Client B enters the picture. One could argue that he should be able to know Client A's newest position after ST(A) + ST(B) time units, but if the system is implemented exactly as described above, the input may not show until ST(A) + ST(B) + 3 ticks. This is because the server would have to update the state in order for the input's effect to show. Exactly how much delay Client B would experience also depends on how often the server sends updates.

My question is, do I have a fault in this design or is this how it usually is? One improvement I can see now would be for the server to send over A's remaining inputs to B when doing an update, letting B predict some of A's "future" inputs also. Another thing to try out would be to let Client B just extrapolate A's previous input until the server sends fresher updates. Any more takes on this?
Advertisement
You have to be careful about your "frames." There may be render frames, physics frames, and network tick frames. The latency in question will be a combination of network tick frames.
For example, if you have three physics frames per network frame, then the batching of commands will add three physics frames' worth of latency.
Also, if the data for a player arrives "early" on the server, then the server has the choice to immediately forward it to the other clients, or to only forward it after it's been simulated and verified. How much latency there is from player A to player B depends on this choice as well.
enum Bool { True, False, FileNotFound };

You have to be careful about your "frames." There may be render frames, physics frames, and network tick frames. The latency in question will be a combination of network tick frames.
For example, if you have three physics frames per network frame, then the batching of commands will add three physics frames' worth of latency.
Also, if the data for a player arrives "early" on the server, then the server has the choice to immediately forward it to the other clients, or to only forward it after it's been simulated and verified. How much latency there is from player A to player B depends on this choice as well.


Yes, one of the problem is that network ticks run slower than physic frames, which is why I have to queue up the inputs.

Good idea about forwarding inputs immediately, but I'm a bit worried over the overhead in a situation where lots of player inputs arrive spread out over different frames, this would trigger a lot of data sending. I guess I could also let clients send this kind of info directly to all other clients in the game, but that would complicate things a bit I think.

Anyhow, am I being paranoid about this thing or is it something you generally need to deal with?

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Anyhow, am I being paranoid about this thing or is it something you generally need to deal with? [/background]

[/font]

[/quote]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Lag, and how to provide a fun and fair game experience in the presence of it, is what network game development is ALL ABOUT. There is no perfect solution, only various trade-offs in game design and presentation.[/background]

[/font]

enum Bool { True, False, FileNotFound };
What is the point of having more physics ticks than network ticks?
What is the point of having more physics ticks than network ticks? [/quote]

Much better feeling gameplay. You get higher latency from the bunching, but you still get to play a 60 Hz (or 100 Hz, or whatever) game. The feel for action-based games is significantly different between at 60 Hz input-and-physics game that sends three frames per packet, and a 20 Hz input-and-physics game that sends one frame per packet.

enum Bool { True, False, FileNotFound };
Do you actually send three game states per packet bunched together? Sending three game states per packet vs one game state per packet three times as often seems like a minimal difference bandwidth-wise. What would the client do with the first two of the three game states?

If a server was running 60Hz physics and sends out game states at 20Hz, does the server still read usercmds at every physics tick, rather than every third physics tick? It seems like higher-resolution physics makes no difference unless it comes with a corresponding increase in responsiveness, though I could see how physics could provide "smoother" trajectories and such with more ticks per second even without an increase in responsiveness, depending on how exactly you implement the physics.
Do you actually send three game states per packet bunched together?[/quote]

No, you probably send three sets of simulation inputs, and perhaps one game state.

You don't generally want to just dump full network states across the wire at full frame rate, because of the bandwidth usage. However, by sending the inputs, you can get a very good replica of what the entity is doing, without using much bandwidth. Typically, you can get away with sending a baseline/checkpoint for an entity only once every few seconds, and do inputs for all the simulation steps in between.

To avoid burstiness, you could send the inputs for all entities for the three steps, and a state dump of one entity, per packet. Keep a queue of entities, and rotate through which one gets state-dumped per packet.
enum Bool { True, False, FileNotFound };

Do you actually send three game states per packet bunched together?


No, you probably send three sets of simulation inputs, and perhaps one game state.

You don't generally want to just dump full network states across the wire at full frame rate, because of the bandwidth usage. However, by sending the inputs, you can get a very good replica of what the entity is doing, without using much bandwidth. Typically, you can get away with sending a baseline/checkpoint for an entity only once every few seconds, and do inputs for all the simulation steps in between.

To avoid burstiness, you could send the inputs for all entities for the three steps, and a state dump of one entity, per packet. Keep a queue of entities, and rotate through which one gets state-dumped per packet.
[/quote]

From the server, I send only the latest game state and all queued (and not yet used) inputs. I decided to fix this and yes, it did improve the responsiveness of the game.
Article along those lines.

http://gafferongames.com/game-physics/networked-physics/

Maybe contains some extra stuff that would be useful to you.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement