Improving interpolation
Here's how our new interpolation will work, inspired by the methods employed in the Source game engine:
As we receive network states, we buffer them up
Each network state is timestamped with network time
We subtract a value from time to find a time in the past (in source, this value is 0.1 by default—so entities are always shown one tenth of a second in the past)
We find the two states on either side of this time value, and interpolate between them
Let's get started
First, we need some kind of struct
to store a snapshot of the network state:
// a snapshot of values received over the network private struct networkState { public Vector3 Position; public double Timestamp; public networkState( Vector3 pos, double time ) { this.Position = pos; this.Timestamp = time; } }
We'll keep a buffer of these to interpolate in between. Note our use of arrays for this purpose. We use a statically sized array for better performance (if we used a List
, internally the List...