diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 780f2721c..305583118 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1040,30 +1040,49 @@ void S_SetSoundPaused(int state) int CalcSmoothRatio(const ClockTicks &totalclk, const ClockTicks &ototalclk, int realgameticspersec) { - double const gametics = 1'000'000'000. / realgameticspersec; - uint64_t currentTime = I_nsTime(); - - if ((lastototalclk == ototalclk) && (lastTime != 0)) - { - elapsedTime += currentTime - lastTime; - } - else - { - lastototalclk = ototalclk; - elapsedTime = 0; - } - lastTime = currentTime; - - double ratioScale = elapsedTime / gametics; - int smoothratio = clamp(xs_CRoundToInt(MaxSmoothRatio * ratioScale), 0, MaxSmoothRatio); + double ratio; + int result; if (cl_debugintrpl) { - Printf("ototalclk: %d\ntotalclk: %d\ngametics: %.3f ms\nelapsedTime: %.3f ms\nratioScale: %f\nsmoothratio: %d\n", - ototalclk, totalclk, (gametics / 1'000'000.), (elapsedTime / 1'000'000.), ratioScale, smoothratio); + Printf("ototalclk: %d\ntotalclk: %d\n", ototalclk, totalclk); } - return smoothratio; + if (!cl_legacyintrpl) + { + double const gametics = 1'000'000'000. / realgameticspersec; + uint64_t currentTime = I_nsTime(); + + if ((lastototalclk == ototalclk) && (lastTime != 0)) + { + elapsedTime += currentTime - lastTime; + } + else + { + lastototalclk = ototalclk; + elapsedTime = 0; + } + lastTime = currentTime; + ratio = elapsedTime / gametics; + + if (cl_debugintrpl) + { + Printf("gametics: %.3f ms\nelapsedTime: %.3f ms\n", (gametics / 1'000'000.), (elapsedTime / 1'000'000.)); + } + } + else + { + ratio = (0.5 + (totalclk - ototalclk)) / (120 / realgameticspersec); + } + + result = clamp(xs_CRoundToInt(ratio * MaxSmoothRatio), 0, MaxSmoothRatio); + + if (cl_debugintrpl) + { + Printf("ratio: %f\nresult: %d\n", ratio, result); + } + + return result; } FString G_GetDemoPath() diff --git a/source/core/gamecvars.cpp b/source/core/gamecvars.cpp index a18bb86ce..fa25b7327 100644 --- a/source/core/gamecvars.cpp +++ b/source/core/gamecvars.cpp @@ -90,7 +90,8 @@ CVARD(Bool, cl_slopetilting, false, CVAR_ARCHIVE, "enable/disable slope tilting" CVARD(Int, cl_showweapon, 1, CVAR_ARCHIVE, "enable/disable show weapons") // only implemented in Blood CVARD(Bool, cl_sointerpolation, true, CVAR_ARCHIVE, "enable/disable sector object interpolation") // only implemented in SW CVARD(Bool, cl_syncinput, false, CVAR_ARCHIVE, "enable/disable synchronized input with game's ticrate") // only implemented in SW -CVARD(Bool, cl_debugintrpl, false, CVAR_NOSAVE, "print information regarding calculated smoothratio for interpolation") // only implemented in SW +CVARD(Bool, cl_debugintrpl, false, CVAR_NOSAVE, "print information regarding calculated smoothratio for interpolation") +CVARD(Bool, cl_legacyintrpl, false, CVAR_ARCHIVE, "perform legacy interpolation calculations") CUSTOM_CVARD(Int, cl_crosshairscale, 50, CVAR_ARCHIVE, "changes the size of the crosshair") { if (self < 1) self = 1; diff --git a/source/core/gamecvars.h b/source/core/gamecvars.h index 716546d75..678ca46b6 100644 --- a/source/core/gamecvars.h +++ b/source/core/gamecvars.h @@ -26,6 +26,7 @@ EXTERN_CVAR(Int, cl_crosshairscale) EXTERN_CVAR(Bool, cl_sointerpolation) EXTERN_CVAR(Bool, cl_syncinput) EXTERN_CVAR(Bool, cl_debugintrpl) +EXTERN_CVAR(Bool, cl_legacyintrpl) EXTERN_CVAR(Bool, demorec_seeds_cvar) EXTERN_CVAR(Bool, demoplay_diffs)