From 5171f90e35ad7136802ed58408b56453e757deb6 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 17 Apr 2019 16:07:32 +0200 Subject: [PATCH] - add r_ticstability for a smoother experience playing mods with high think times --- src/d_net.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/d_net.cpp b/src/d_net.cpp index ec0a90deb4..072988b1c1 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -1802,7 +1802,46 @@ void D_QuitNetGame (void) fclose (debugfile); } +// Forces playsim processing time to be consistent across frames. +// This improves interpolation for frames in between tics. +// +// With this cvar off the mods with a high playsim processing time will appear +// less smooth as the measured time used for interpolation will vary. +CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + +static uint64_t stabilityticduration = 0; +static uint64_t stabilitystarttime = 0; + +static void TicStabilityWait() +{ + using namespace std::chrono; + using namespace std::this_thread; + + if (!r_ticstability) + return; + + uint64_t start = duration_cast(steady_clock::now().time_since_epoch()).count(); + while (true) + { + uint64_t cur = duration_cast(steady_clock::now().time_since_epoch()).count(); + if (cur - start > stabilityticduration) + break; + } +} + +static void TicStabilityBegin() +{ + using namespace std::chrono; + stabilitystarttime = duration_cast(steady_clock::now().time_since_epoch()).count(); +} + +static void TicStabilityEnd() +{ + using namespace std::chrono; + uint64_t stabilityendtime = duration_cast(steady_clock::now().time_since_epoch()).count(); + stabilityticduration = std::min(stabilityendtime - stabilitystarttime, (uint64_t)1'000'000); +} // // TryRunTics @@ -1872,6 +1911,8 @@ void TryRunTics (void) // Uncapped framerate needs seprate checks if (counts == 0 && !doWait) { + TicStabilityWait(); + // Check possible stall conditions Net_CheckLastReceived(counts); if (realtics >= 1) @@ -1939,6 +1980,7 @@ void TryRunTics (void) P_UnPredictPlayer(); while (counts--) { + TicStabilityBegin(); if (gametic > lowtic) { I_Error ("gametic>lowtic"); @@ -1954,10 +1996,15 @@ void TryRunTics (void) gametic++; NetUpdate (); // check for new console commands + TicStabilityEnd(); } P_PredictPlayer(&players[consoleplayer]); S_UpdateSounds (players[consoleplayer].camera); // move positional sounds } + else + { + TicStabilityWait(); + } } void Net_CheckLastReceived (int counts)