So how does the drawing continue to look smooth? Continuum cheats. The way I did it in Discretion, and the way I think it's done in Continuum, is that it adjusts each player's velocity so that their ship will work it's way to the correct position over time, rather that instantly resetting the position to the best prediction (which would make it jump on your screen). Want proof? Fly next to a player in Continuum that's drifting through space. Match his speed. If you look at him he'll be drifting
Anyways the code to do it in Discretion is below. There's two settings you can adjust, which are
Quote
;;; The amount of time in milliseconds we must "tweak" the velocity before the player's position is
;;; exactly what we predict it should be
;;; too low = bad because suffers from latency jerkiness
;;; too high = bad because we may never catch up to their real position (and have to reset more)
Prediction Velocity Adjust Time = 300
;;; The distance, in pixels, the player's drawn position is allowed to stray from what we predict the real position is
;;; note that it never stays this far for more than a few fractions of a second because the velocity adjustment corrects it
;;; too low = bad because we reset often which causes jerkiness
;;; too high = bad because the player's position may not be drawn accurately
Prediction Reset Distance = 40
During my tests it actually looks better in Discretion than in Continuum, but I'm not 100% this is always the case since when I run both side by side the fps on the non-selected one drops to ~10fps. I'll need to get another computer to test it if still looks good at high fps. I suspect that by modifying the settings it can look reasonable.
s->vel.x = xvel; s->vel.y = yvel; s->display = true; s->rot = sm->frameToRot(frame, s); // look at the timestamp and compute the predicted "correct" position for the player int millDif = 10 * (((net->getServerMilliseconds()/10) & 0x0FFFF) - pi->getValue("timestamp")); // millDif is positive, how much later it is than when the event occured // predicted correct positions int newx = xpos * 10000 + (xvel * millDif); int newy = ypos * 10000 + (yvel * millDif); // these are how much we are "off" by int dx = (newx - s->loc.x)/10000; int dy = (newy - s->loc.y)/10000; // resetDist is in pixels u32 maxDistSq = resetDist * resetDist; u32 distSq = dx * dx + dy * dy; // if we're drawing too far away from the predicted position, jump the player to the correct spot if (distSq > maxDistSq) { s->loc.x = xpos * 10000; s->loc.y = ypos * 10000; } else { // otherwise cheat with the velocities to fix the player position smoothly // s->vel = pixels/10sec, velAdTime = ms, newx/s->loc.x = 10000*pixels if (s->loc.x / 10000 != newx / 10000) s->vel.x += ((newx - s->loc.x)) / (velAdjustTime); if (s->loc.y / 10000 != newy / 10000) s->vel.y += ((newy - s->loc.y)) / (velAdjustTime); }