Merge branch 'interp-clag-stutter' into 'master'

Fix intermittent stutters with frame interpolation

See merge request KartKrew/Kart!522
This commit is contained in:
Sal 2022-01-18 07:34:57 +00:00
commit 311c22592b
6 changed files with 33 additions and 13 deletions

View file

@ -5235,8 +5235,10 @@ static void SV_Maketic(void)
maketic++; maketic++;
} }
void TryRunTics(tic_t realtics) boolean TryRunTics(tic_t realtics)
{ {
boolean ticking;
// the machine has lagged but it is not so bad // the machine has lagged but it is not so bad
if (realtics > TICRATE/7) // FIXME: consistency failure!! if (realtics > TICRATE/7) // FIXME: consistency failure!!
{ {
@ -5280,7 +5282,9 @@ void TryRunTics(tic_t realtics)
} }
#endif #endif
if (neededtic > gametic) ticking = neededtic > gametic;
if (ticking)
{ {
if (realtics) if (realtics)
hu_stopped = false; hu_stopped = false;
@ -5290,10 +5294,10 @@ void TryRunTics(tic_t realtics)
{ {
if (realtics) if (realtics)
hu_stopped = true; hu_stopped = true;
return; return false;
} }
if (neededtic > gametic) if (ticking)
{ {
if (advancedemo) if (advancedemo)
{ {
@ -5330,6 +5334,8 @@ void TryRunTics(tic_t realtics)
if (realtics) if (realtics)
hu_stopped = true; hu_stopped = true;
} }
return ticking;
} }

View file

@ -488,7 +488,7 @@ boolean Playing(void);
void D_QuitNetGame(void); void D_QuitNetGame(void);
//? How many ticks to run? //? How many ticks to run?
void TryRunTics(tic_t realtic); boolean TryRunTics(tic_t realtic);
// extra data for lmps // extra data for lmps
// these functions scare me. they contain magic. // these functions scare me. they contain magic.

View file

@ -685,6 +685,7 @@ tic_t rendergametic;
void D_SRB2Loop(void) void D_SRB2Loop(void)
{ {
tic_t oldentertics = 0, entertic = 0, realtics = 0, rendertimeout = INFTICS; tic_t oldentertics = 0, entertic = 0, realtics = 0, rendertimeout = INFTICS;
boolean ticked;
if (dedicated) if (dedicated)
server = true; server = true;
@ -772,11 +773,23 @@ void D_SRB2Loop(void)
realtics = 1; realtics = 1;
// process tics (but maybe not if realtic == 0) // process tics (but maybe not if realtic == 0)
TryRunTics(realtics); ticked = TryRunTics(realtics);
if (cv_frameinterpolation.value == 1 && !(paused || P_AutoPause() || hu_stopped)) if (cv_frameinterpolation.value == 1 && !(paused || P_AutoPause()))
{ {
fixed_t entertimefrac = I_GetTimeFrac(); static float tictime;
float entertime = I_GetTimeFrac();
fixed_t entertimefrac;
if (ticked)
tictime = entertime;
if (aproxfps < 35.0)
entertimefrac = FRACUNIT;
else
entertimefrac = FLOAT_TO_FIXED(entertime - tictime);
// renderdeltatics is a bit awkard to evaluate, since the system time interface is whole tic-based // renderdeltatics is a bit awkard to evaluate, since the system time interface is whole tic-based
renderdeltatics = realtics * FRACUNIT; renderdeltatics = realtics * FRACUNIT;
if (entertimefrac > rendertimefrac) if (entertimefrac > rendertimefrac)

View file

@ -46,9 +46,9 @@ UINT32 I_GetFreeMem(UINT32 *total);
*/ */
tic_t I_GetTime(void); tic_t I_GetTime(void);
/** \brief Get the current time as a fraction of a tic since the last tic. /** \brief Get the current time in tics including fractions.
*/ */
fixed_t I_GetTimeFrac(void); float I_GetTimeFrac(void);
/** \brief Returns precise time value for performance measurement. /** \brief Returns precise time value for performance measurement.
*/ */

View file

@ -84,8 +84,10 @@ void R_InterpolateView(fixed_t frac)
{ {
if (frac < 0) if (frac < 0)
frac = 0; frac = 0;
#if 0
if (frac > FRACUNIT) if (frac > FRACUNIT)
frac = FRACUNIT; frac = FRACUNIT;
#endif
viewx = oldview->x + R_LerpFixed(oldview->x, newview->x, frac); viewx = oldview->x + R_LerpFixed(oldview->x, newview->x, frac);
viewy = oldview->y + R_LerpFixed(oldview->y, newview->y, frac); viewy = oldview->y + R_LerpFixed(oldview->y, newview->y, frac);

View file

@ -1658,11 +1658,10 @@ tic_t I_GetTime(void)
return (tic_t)f; return (tic_t)f;
} }
fixed_t I_GetTimeFrac(void) float I_GetTimeFrac(void)
{ {
UpdateElapsedTics(); UpdateElapsedTics();
return elapsed_tics;
return FLOAT_TO_FIXED((float) (elapsed_tics - floor(elapsed_tics)));
} }
precise_t I_GetPreciseTime(void) precise_t I_GetPreciseTime(void)