Hi again. Thanks for all the help thus far!
I'm going back over my clientside prediction code and trying to remove some jerky snapping artifacts on corrections. I'm getting in a situation where it looks like I need to introduce multiple layers of smoothing and I'm wondering how to proceed.
So, in the naive "show whatever the server sends us" model with a dejitter buffer, my approach looks like this:
I store all states (which I receive every two ticks from the server) in a buffer, and try to stay around 2-3 states behind the newest received in order to allow time for states to arrive out of order and be properly arranged. I call the most recent state out of the dejitter range the "latest" state, with an immediate prior state. When displaying this information on screen, I smoothly interpolate between the prior state and the latest state to produce a position from some t based on the current FPS delta time. (I can extrapolate too but it's basically the same process with t > 1.)
When doing prediction, the process uses the same data, like this:
Every tick on the client I apply the most recent received authoritative state (which normally would be waiting for dejitter) and produce one predicted state for every unacknowledged input message sent to the server. When displaying this information on screen, I interpolate as above, only this time I use the last two predicted states as my endpoints.
My question then comes up when I receive the next authoritative state from the server while predicting:
Here we get the authoritative state for tick 56, which disagrees with our previously predicted state for tick 56. Right now I just trash 56', apply 56, and resimulate, but this creates a noticeable snap because of the following situation:
I'd like to smooth over this, but I'm struggling with how to implement it because of two reasons:
1) I'm already smoothing on display between the latest and prior states.
2) This may happen every two ticks (or whatever the server send rate is), meaning I could be constantly trying to smoothly integrate corrections. I know I need to somehow set aside 56' and roll it into the correction, but I don't know what to do when I'm smoothing over a 56-56' correction and then 58 arrives.
Assuming I have the power to call lerp(t) on any two states, any ideas how I can implement this second, continuous layer of smoothing? Have you dealt with something like this before?
Thanks!
EDIT: Just to clarify, I'm asking because I'd like to smooth the corrections over several ticks, possibly more than the send rate. So I could be correcting 56-56' while 58 comes in, and could in theory have their corrections overlap.