Peer replication - Lerping between knowns vs predicting?

Started by
3 comments, last by hplus0603 3 years, 9 months ago

Hey all, I need some help solidifying my understanding of peer replication.

In a networked game setup where the player is ahead in time and peers are behind, I learned that the process for replicating peers is:

  1. The server sends you their state (position, velocity, facing, and inputs).
  2. Wait until you have at least 2 states for that peer.
  3. Lerp between the latest 2 states for that peer.
  4. If you run out of data, keep predicting with their latest inputs. When their data finally comes through, jump them back to the oldest authoritative point and process multiple states until they're caught up.

I'm wondering about steps 2 and 3 though, why not look at 1 state at a time and use your prediction code? If you need to put in the prediction/replay code for #4 anyway, it seems like you would just use that. Something like:

  1. The server sends you their state (position, velocity, facing, and inputs).
  2. Jump them to that state, or verify that your last prediction was correct.
  3. Sim them to their next predicted state (deterministic sim, should be perfect).
  4. If you run out of data, keep predicting with their latest inputs. When their data finally comes through, jump them back to the oldest authoritative point and process multiple states until they're caught up.

You would add some buffer time to try and make sure you can always base your prediction off real data.

Is there something I'm missing that makes the first approach better? It could be that wherever I learned this approach from was just being unclear about the difference between the sim update and the render update (where you are constantly lerping between 2 knowns), so it'll be good to get my understanding straightened out.

Advertisement

This is exactly the “interpolation” versus “extrapolation” question.

Which is more important? Having remote entities be “somewhat close to right, in current time,” or having remote entities be “following the correct path, in past time?”

The choice between these two options depends on your specific gameplay requirements. The Entity Position Interpolation Code illustration/library lets you play with this trade-off: https://www.mindcontrol.org/~hplus/epic/

enum Bool { True, False, FileNotFound };

hplus0603 said:

This is exactly the “interpolation” versus “extrapolation” question.

Which is more important? Having remote entities be “somewhat close to right, in current time,” or having remote entities be “following the correct path, in past time?”

The choice between these two options depends on your specific gameplay requirements. The Entity Position Interpolation Code illustration/library lets you play with this trade-off: https://www.mindcontrol.org/~hplus/epic/

That makes sense to me in the case of “we only interpolate between known data and never extrapolate” vs “we start extrapolating as soon as we get a starting state”, but both of the cases I've listed seem to be a little of both.

In both cases, you wait until you've buffered a couple ticks worth of state. In the first, you then interpolate until you run out of data, then you extrapolate. In the second, you “extrapolate” until you run out of data, then actually extrapolate. By “extrapolate”, I mean that you're always using known data and a deterministic sim, so isn't it as correct as the interpolation?

I guess I'm asking about actual interpolation vs using extrapolation code with authoritative data. I don't see why you would do an actual lerp when you can reuse the prediction code for the same effect?

The cases you describe don't sound like the most common cases to me.

When you extrapolate, you very often start right away, and use position+directional velocity as your state, rather than just two position snapshots.

When you interpolate, you don't HAVE to extrapolate if you miss an update when you expect to get it. You can just stop the entity in its tracks. I'm sure you've played games where other players will stop and then speed up and then stop …. that's basically this effect in action.

You can of course mix and match whatever methods you need for your particular gameplay. For example, if you have two snapshots of position and directional velocity, you can fit a spline to those snapshots and then interpolate “better.”

You cannot use the prediction code for the same effect as interpolation code. For prediction, you got the player at position 10, direction (1,0), and then start drawing the player at position 11, 12, 13, … For interpolation, you got the player at position 5, and later at position 10, at which point you draw the player at position 5, 6, 7, … In the extrapolation case, if it turns out the player actually got to position 11, then turned around and went backwards to 10, 9, 8, … then the extrapolation will significantly overhsoot the position as it renders at 12, 13, 14, … until it gets the next target position, and then it will suddenly move with very high speed towards the next predicted position (or even jump/teleport.)

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement