From 3ef431a428c7834c63eebdc9030a785babadf10f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 3 Apr 2023 19:37:51 +1000 Subject: [PATCH] - Make `scaleAdjust` a float since it's what's needed anyway. --- source/core/gamecontrol.cpp | 2 +- source/core/gameinput.cpp | 29 +++++++++++++---------------- source/core/gameinput.h | 10 +++++----- source/core/gamestruct.h | 2 +- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/input.cpp | 2 +- source/games/sw/src/game.h | 2 +- 7 files changed, 23 insertions(+), 26 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index a085b69e0..0cb25e8d0 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1415,7 +1415,7 @@ void GameInterface::FreeLevelData() // //--------------------------------------------------------------------------- -void GameInterface::doPlayerMovement(const double scaleAdjust) +void GameInterface::doPlayerMovement(const float scaleAdjust) { gameInput.processMovement(scaleAdjust); } diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 4c842b7d0..33a615294 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -106,42 +106,39 @@ void processCrouchToggle(bool& toggle, ESyncBits& actions, const bool crouchable // //--------------------------------------------------------------------------- -void GameInput::processMovement(const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) +void GameInput::processMovement(const float scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // open up input packet for this session. InputPacket thisInput{}; // set up variables. - const int keymove = 1 << int(!!(inputBuffer.actions & SB_RUN)); - const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); - const float scaleAdjustf = float(scaleAdjust); - - // determine player input. + const auto keymove = 1 << int(!!(inputBuffer.actions & SB_RUN)); + const auto hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); - const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + joyAxes[JOYAXIS_Forward] * scaleAdjustf; - const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - joyAxes[JOYAXIS_Side] * scaleAdjustf; + const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + joyAxes[JOYAXIS_Forward] * scaleAdjust; + const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - joyAxes[JOYAXIS_Side] * scaleAdjust; // process player angle input. if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) { const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); - thisInput.avel += mouseInput.X * m_yaw - (joyAxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf; + thisInput.avel += mouseInput.X * m_yaw - (joyAxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjust; if (turndir) updateTurnHeldAmt(scaleAdjust); else turnheldtime = 0; } else { - thisInput.svel += mouseInput.X * m_side - (joyAxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf; + thisInput.svel += mouseInput.X * m_side - (joyAxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjust; } // process player pitch input. if (!(inputBuffer.actions & SB_AIMMODE)) { - thisInput.horz -= mouseInput.Y * m_pitch + joyAxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf; + thisInput.horz -= mouseInput.Y * m_pitch + joyAxes[JOYAXIS_Pitch] * hidspeed * scaleAdjust; } else { - thisInput.fvel += mouseInput.Y * m_forward + joyAxes[JOYAXIS_Pitch] * keymove * scaleAdjustf; + thisInput.fvel += mouseInput.Y * m_forward + joyAxes[JOYAXIS_Pitch] * keymove * scaleAdjust; } // process movement input. @@ -174,7 +171,7 @@ void GameInput::processMovement(const double scaleAdjust, const int drink_amt, c // //--------------------------------------------------------------------------- -void GameInput::processVehicle(const double scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate) +void GameInput::processVehicle(const float scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate) { // open up input packet for this session. InputPacket thisInput{}; @@ -204,8 +201,8 @@ void GameInput::processVehicle(const double scaleAdjust, const float baseVel, co const auto turnVel = (!attenuate && (isTurboTurnTime() || hidLeft || hidRight)) ? (baseVel) : (baseVel * velScale); thisInput.avel += turnVel * -joyAxes[JOYAXIS_Yaw] + turnVel * kbdDir; - thisInput.avel += sqrtf(abs(turnVel * mouseInput.X * m_yaw / (float)scaleAdjust) * (7.f / 20.f)) * Sgn(turnVel) * Sgn(mouseInput.X); - thisInput.avel *= (float)scaleAdjust; + thisInput.avel += sqrtf(abs(turnVel * mouseInput.X * m_yaw / scaleAdjust) * (7.f / 20.f)) * Sgn(turnVel) * Sgn(mouseInput.X); + thisInput.avel *= scaleAdjust; if (kbdDir) updateTurnHeldAmt(scaleAdjust); else turnheldtime = 0; } else @@ -357,7 +354,7 @@ void GameInput::getInput(const double scaleAdjust, InputPacket* packet) prepareHidInput(); processInputBits(); - gi->doPlayerMovement(!SyncInput() ? scaleAdjust : 1.); + gi->doPlayerMovement(!SyncInput() ? (float)scaleAdjust : 1.f); resetHidInput(); if (packet) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 05e83b3c0..bc6491547 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -32,7 +32,7 @@ class GameInput ESyncBits ActionsToSend; // Turn speed doubling after x amount of tics. - void updateTurnHeldAmt(const double scaleAdjust) + void updateTurnHeldAmt(const float scaleAdjust) { turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust; } @@ -75,8 +75,8 @@ public: } // Prototypes for large member functions. - void processMovement(const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); - void processVehicle(const double scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); + void processMovement(const float scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); + void processVehicle(const float scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); void getInput(const double scaleAdjust, InputPacket* packet = nullptr); }; @@ -89,8 +89,8 @@ struct PlayerAngles DAngle YawSpin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); - friend void GameInput::processMovement(const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale); - friend void GameInput::processVehicle(const double scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); + friend void GameInput::processMovement(const float scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale); + friend void GameInput::processVehicle(const float scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); // Prototypes. void doPitchKeys(InputPacket* const input); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index b02a59fb1..84283a036 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -119,7 +119,7 @@ struct GameInterface virtual bool WantEscape() { return false; } virtual void StartSoundEngine() = 0; virtual void reapplyInputBits(InputPacket* const input) = 0; - virtual void doPlayerMovement(const double scaleAdjust); + virtual void doPlayerMovement(const float scaleAdjust); virtual FString statFPS() { diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 347dc1b2b..eacb17dce 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -40,7 +40,7 @@ struct GameInterface : public ::GameInterface void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; void reapplyInputBits(InputPacket* const input) override { input->actions |= ps[myconnectindex].sync.actions & SB_CENTERVIEW; } - void doPlayerMovement(const double scaleAdjust) override; + void doPlayerMovement(const float scaleAdjust) override; void UpdateSounds() override; void Startup() override; void DrawBackground() override; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 217500788..477748a30 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -501,7 +501,7 @@ void hud_input(int plnum) // //--------------------------------------------------------------------------- -void GameInterface::doPlayerMovement(const double scaleAdjust) +void GameInterface::doPlayerMovement(const float scaleAdjust) { auto const p = &ps[myconnectindex]; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 59941ceda..1c15b1cc2 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1889,7 +1889,7 @@ struct GameInterface : public ::GameInterface int GetCurrentSkill() override; void StartSoundEngine() override; void reapplyInputBits(InputPacket* const input) override { input->actions |= Player[myconnectindex].input.actions & SB_CENTERVIEW; } - void doPlayerMovement(const double scaleAdjust) override + void doPlayerMovement(const float scaleAdjust) override { gameInput.processMovement(scaleAdjust, 0, !Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); }