Jump to content

  • Log In with Google      Sign In   
  • Create Account


Player prediction across clients, minimizing latency


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Ollhax   Members   -  Reputation: 156

Like
0Likes
Like

Posted 13 April 2012 - 02:25 PM

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?

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 4970

Like
1Likes
Like

Posted 13 April 2012 - 03:36 PM

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 };

#3 Ollhax   Members   -  Reputation: 156

Like
0Likes
Like

Posted 14 April 2012 - 02:52 AM

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?

#4 hplus0603   Moderators   -  Reputation: 4970

Like
0Likes
Like

Posted 14 April 2012 - 07:11 PM

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




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.


enum Bool { True, False, FileNotFound };

#5 Guniferd   Members   -  Reputation: 126

Like
0Likes
Like

Posted 16 April 2012 - 05:47 PM

What is the point of having more physics ticks than network ticks?

#6 hplus0603   Moderators   -  Reputation: 4970

Like
1Likes
Like

Posted 16 April 2012 - 09:00 PM

What is the point of having more physics ticks than network ticks?


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 };

#7 Guniferd   Members   -  Reputation: 126

Like
0Likes
Like

Posted 17 April 2012 - 02:33 PM

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.

#8 hplus0603   Moderators   -  Reputation: 4970

Like
1Likes
Like

Posted 17 April 2012 - 05:11 PM

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.

enum Bool { True, False, FileNotFound };

#9 Ollhax   Members   -  Reputation: 156

Like
0Likes
Like

Posted 18 April 2012 - 11:11 AM

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.


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.

#10 0BZEN   Crossbones+   -  Reputation: 2004

Like
0Likes
Like

Posted 19 April 2012 - 05:30 AM

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.


#11 Ollhax   Members   -  Reputation: 156

Like
0Likes
Like

Posted 19 April 2012 - 10:56 AM

Article along those lines.

http://gafferongames...worked-physics/

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


Yup, read them all. It's a good link though!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS