I've setup a basic entity interpolation for a multiplayer game and everything works ok. Currently I'm trying to improve it for bad connections with packet loss.
The game uses TCP so in case of packet loss on client it looks like the delivery is stopped for ~300ms and then everything is received at once.
I observe the same behavior on a wireless internet connection and on a good connection with packet loss simulator ("clumsy").
I suppose for many realtime multiplayer games this delay is too much and nothing can be done, but movement in my game is somewhat predictable
and extrapolating last movement even for longer periods of time (with possible smooth corrections after) will look better than just freezing movement.
So my goal is to interpolate when everything is ok and extrapolate in case of packet loss but still let client be behind in time.
My current scheme involves "startPos", "curPos", "endPos" and "startTime" variables. Every time position is received, I set startPos = curPos,
endPos = received pos, startTime = now, and every frame interpolate from startPos to endPos with t ranging from 0.0 when now == startTime
to 1.0 when now >= startTime + 100 (an arbitrary constant larger than expected send rate).
To introduce extrapolation my initial solution was to stop clamping t to 1.0, but it failed because after extrapolating for some time, old data is received
and movement looks like entity jerks backwards. To fix this I started sending server time in form of "server now - first send time"
so client now has two times: server time and client time in form of "client now - first receive time".
But this is where my thought process stops and I don't know what to do next.
All schemes I come to will work in case of packet loss (which can be treated as temp latency increase)
but will be ruined by a permanent latency increase (network route change? idk if this is a good example) and client will either extrapolate too forward and suffer
from corrections or interpolate too behind and have extra latency.
So how should I utilize these times to achieve desired results?