From e0e459216d8467628549d82c45096830fb77cb54 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 25 Sep 2023 19:51:53 +1000 Subject: [PATCH] - Reduce `GameInput::processVehicle()` interface by changing three bools to a bitfield. --- source/core/gameinput.cpp | 8 ++++---- source/core/gameinput.h | 11 +++++++++-- source/games/duke/src/input.cpp | 9 +++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 67191431ca..eb87a21f30 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -185,7 +185,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale // //--------------------------------------------------------------------------- -void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate) +void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const unsigned flags) { // open up input packet for this session. InputPacket thisInput{}; @@ -194,7 +194,7 @@ void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleA inputBuffer.actions &= ~(SB_WEAPONMASK_BITS | SB_TURNAROUND | SB_CENTERVIEW | SB_HOLSTER | SB_JUMP | SB_CROUCH | SB_RUN | SB_AIM_UP | SB_AIM_DOWN | SB_AIMMODE | SB_LOOK_UP | SB_LOOK_DOWN | SB_LOOK_LEFT | SB_LOOK_RIGHT); - if (canMove) + if (flags & VEH_CANMOVE) { const auto kbdForwards = buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe); const auto kbdBackward = buttonMap.ButtonDown(gamefunc_Move_Backward); @@ -205,7 +205,7 @@ void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleA if (buttonMap.ButtonDown(gamefunc_Run)) inputBuffer.actions |= SB_CROUCH; } - if (canTurn) + if (flags & VEH_CANTURN) { // Keyboard turning. const auto kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); @@ -217,7 +217,7 @@ void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleA const auto hidRight = mouseInput.X > 0 || joyAxes[JOYAXIS_Yaw] < 0; // Velocity setup. - const auto turnVel = (!attenuate && (isTurboTurnTime() || hidLeft || hidRight)) ? (baseVel) : (baseVel * velScale); + const auto turnVel = (!(flags & VEH_SCALETURN) && (isTurboTurnTime() || hidLeft || hidRight)) ? (baseVel) : (baseVel * velScale); const auto mouseVel = abs(turnVel * mouseInput.X * m_yaw) * (45.f / 2048.f) / scaleAdjust; const auto maxVel = abs(turnVel * 1.5f); diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 0dbb161beb..e340e12296 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -9,6 +9,13 @@ enum : unsigned CS_DISABLETOGGLE = 2, }; +enum : unsigned +{ + VEH_CANMOVE = 1, + VEH_CANTURN = 2, + VEH_SCALETURN = 4, +}; + inline double getTicrateScale(const double value) { return value / GameTicRate; @@ -75,7 +82,7 @@ class GameInput // Prototypes for large member functions. void processMovement(PlayerAngles* const plrAngles, const float scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const float turnscale = 1.f); - void processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); + void processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const unsigned flags); void getInput(const double scaleAdjust, InputPacket* packet = nullptr); void resetCrouchToggle(); }; @@ -93,7 +100,7 @@ struct PlayerAngles friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); friend void GameInput::processMovement(PlayerAngles* const plrAngles, const float scaleAdjust, const int drink_amt, const bool allowstrafe, const float turnscale); - friend void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); + friend void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const unsigned flags); // Prototypes. void doPitchInput(InputPacket* const input); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 2a86a36e70..1bee4d6f93 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -529,11 +529,12 @@ void GameInterface::doPlayerMovement(const float scaleAdjust) baseVel = VEHICLETURN * velScale; } - const auto canMove = p->OnBoat || !p->moto_underwater; - const auto canTurn = p->OnMotorcycle || p->MotoSpeed || p->moto_drink; - const auto attenuate = p->OnMotorcycle && p->MotoSpeed <= 0; + unsigned vehFlags = 0; + vehFlags |= VEH_CANMOVE * (p->OnBoat || !p->moto_underwater); + vehFlags |= VEH_CANTURN * (p->OnMotorcycle || p->MotoSpeed || p->moto_drink); + vehFlags |= VEH_SCALETURN * (p->OnMotorcycle && p->MotoSpeed <= 0); - gameInput.processVehicle(&p->Angles, scaleAdjust, baseVel, velScale, canMove, canTurn, attenuate); + gameInput.processVehicle(&p->Angles, scaleAdjust, baseVel, velScale, vehFlags); } else {