diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 2f0fe8fe2..e5ffb4d06 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -91,6 +91,29 @@ lookangle getincanglebam(binangle a, binangle na) return bamlook(newa-cura); } +//--------------------------------------------------------------------------- +// +// Functions for determining whether its turbo turn time (turn key held for a number of tics). +// +//--------------------------------------------------------------------------- + +static double turnheldtime; + +void updateTurnHeldAmt(double const scaleAdjust) +{ + turnheldtime += scaleAdjust * (120. / GameTicRate); +} + +bool const isTurboTurnTime() +{ + return turnheldtime >= 590. / GameTicRate; +} + +void resetTurnHeldAmt() +{ + turnheldtime = 0; +} + //--------------------------------------------------------------------------- // // Player's movement function, called from game's ticker or from gi->GetInput() as required. @@ -170,9 +193,6 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn } else { - static double turnheldtime; - int const turnheldamt = 120 / GameTicRate; - double const turboturntime = 590. / GameTicRate; double turnamount = hidspeed * turnscale; double preambleturn = turnamount * (750. / 2776.); @@ -184,17 +204,17 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !allowstrafe)) { - turnheldtime += scaleAdjust * turnheldamt; - currInput->avel -= scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn); + updateTurnHeldAmt(scaleAdjust); + currInput->avel -= scaleAdjust * (isTurboTurnTime() ? turnamount : preambleturn); } else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !allowstrafe)) { - turnheldtime += scaleAdjust * turnheldamt; - currInput->avel += scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn); + updateTurnHeldAmt(scaleAdjust); + currInput->avel += scaleAdjust * (isTurboTurnTime() ? turnamount : preambleturn); } else { - turnheldtime = 0; + resetTurnHeldAmt(); } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index fa6ff6390..357febc07 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -269,6 +269,10 @@ class FSerializer; FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def); FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, PlayerHorizon* def); + +void updateTurnHeldAmt(double const scaleAdjust); +bool const isTurboTurnTime(); +void resetTurnHeldAmt(); void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1); void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust = 1); void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust = 1);