From 290e6158079cbfe9fcfe2219f544549d7cc237dd Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 4 Sep 2020 17:53:36 +1000 Subject: [PATCH] - Move Duke's input scaling for unsynchronised input to backend as `InputScale()`. --- source/core/inputstate.cpp | 17 +++++++++++++++++ source/core/inputstate.h | 3 ++- source/games/duke/src/input.cpp | 10 +--------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 1e6e6638e..a1f4baf25 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -47,6 +47,8 @@ ESyncBits ActionsToSend = 0; static int dpad_lock = 0; bool sendPause; +static double lastCheck; + //========================================================================== // // @@ -402,3 +404,18 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput) } +double InputScale() +{ + if (!cl_syncinput) + { + double now = I_msTimeF(); + double elapsedInputTicks = lastCheck > 0 ? min(now - lastCheck, 1000.0 / GameTicRate) : 1; + lastCheck = now; + return elapsedInputTicks * GameTicRate / 1000.0; + } + else + { + return 1; + } +} + diff --git a/source/core/inputstate.h b/source/core/inputstate.h index e42dbc227..18d5ef9e4 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -97,4 +97,5 @@ enum GameFunction_t void SetupGameButtons(); void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput); -extern ESyncBits ActionsToSend; \ No newline at end of file +extern ESyncBits ActionsToSend; +double InputScale(); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 8544ca420..588e73d6a 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -1001,16 +1001,8 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput) { - double elapsedInputTicks; auto const p = &ps[myconnectindex]; - auto now = I_msTimeF(); - // do not let this become too large - it would create overflows resulting in undefined behavior. The very first tic must not use the timer difference at all because the timer has not been set yet. - // This really needs to have the timer fixed to be robust, doing it ad-hoc here is not really safe. - if (lastCheck > 0) elapsedInputTicks = min(now - lastCheck, 1000.0 / REALGAMETICSPERSEC); - else elapsedInputTicks = 1; - lastCheck = now; - if (paused) { loc = {}; @@ -1022,7 +1014,7 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput) setlocalplayerinput(p); } - double scaleAdjust = !cl_syncinput ? elapsedInputTicks * REALGAMETICSPERSEC / 1000.0 : 1; + double const scaleAdjust = InputScale(); InputPacket input{}; if (isRRRA() && (p->OnMotorcycle || p->OnBoat))