From bdf566b34848235445097969e4fa308fd2dccb81 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 4 Oct 2023 16:05:00 +1100 Subject: [PATCH] - Remove `GameInput` friendships inside `PlayerAngles` in lieu of a local inline function. --- source/core/gameinput.cpp | 27 ++++++++++++++++++++++----- source/core/gameinput.h | 7 +++---- source/core/gamestruct.h | 5 +---- source/games/blood/src/blood.h | 1 - source/games/duke/src/input.cpp | 4 ++-- source/games/exhumed/src/exhumed.h | 1 - source/games/sw/src/game.h | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 036c2f368..99658e570 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -60,10 +60,15 @@ bool crouch_toggle = false; //--------------------------------------------------------------------------- // -// Input scale helper functions. +// Input helper functions. // //--------------------------------------------------------------------------- +inline void addCameraAngles(const DRotator& input) +{ + PlayerArray[myconnectindex]->Angles.CameraAngles += input; +} + static inline DAngle getscaledangle(const DAngle angle, const double scale, const double push) { return (angle.Normalized180() * getTicrateScale(scale)) + DAngle::fromDeg(push); @@ -94,13 +99,25 @@ void GameInput::resetCrouchToggle() } +//--------------------------------------------------------------------------- +// +// Default player movement function for the games. Can be overridden. +// +//--------------------------------------------------------------------------- + +void GameInterface::doPlayerMovement(const double scaleAdjust) +{ + gameInput.processMovement(scaleAdjust); +} + + //--------------------------------------------------------------------------- // // Player's movement function, called from game's ticker or from gi->doPlayerMovement() as required. // //--------------------------------------------------------------------------- -void GameInput::processMovement(PlayerAngles* const plrAngles, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) +void GameInput::processMovement(const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. InputPacket thisInput{}; @@ -173,7 +190,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const double scal // directly update player angles if we can. if (scaleAdjust < 1) { - plrAngles->CameraAngles += thisInput.ang; + addCameraAngles(thisInput.ang); } } @@ -184,7 +201,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const double scal // //--------------------------------------------------------------------------- -void GameInput::processVehicle(PlayerAngles* const plrAngles, const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags) +void GameInput::processVehicle(const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags) { // open up input packet for this session. InputPacket thisInput{}; @@ -237,7 +254,7 @@ void GameInput::processVehicle(PlayerAngles* const plrAngles, const double scale // directly update player angles if we can. if (scaleAdjust < 1) { - plrAngles->CameraAngles += thisInput.ang; + addCameraAngles(thisInput.ang); } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 3386b6072..8eced2bc2 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -84,8 +84,8 @@ public: } // Prototypes for large member functions. - void processMovement(PlayerAngles* const plrAngles, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); - void processVehicle(PlayerAngles* const plrAngles, const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags); + void processMovement(const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); + void processVehicle(const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags); void getInput(const double scaleAdjust, InputPacket* packet = nullptr); void resetCrouchToggle(); }; @@ -102,8 +102,7 @@ struct PlayerAngles DAngle YawSpin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); - friend void GameInput::processMovement(PlayerAngles* const plrAngles, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale); - friend void GameInput::processVehicle(PlayerAngles* const plrAngles, const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags); + friend void addCameraAngles(const DRotator& input); // Prototypes. void doPitchInput(InputPacket* const input); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 76c4a94d8..2b21e69f6 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -6,7 +6,6 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m #include "vectors.h" #include "engineerrors.h" #include "stats.h" -#include "packet.h" #include "serializer.h" #include "inputstate.h" #include "maptypes.h" @@ -15,9 +14,7 @@ class FSerializer; struct FRenderViewpoint; struct sectortype; struct tspritetype; -class DCoreActor; struct MapRecord; -struct PlayerAngles; struct GameStats { @@ -115,7 +112,7 @@ struct GameInterface virtual void RemoveQAVInterpProps(const int res_id) { } virtual bool WantEscape() { return false; } virtual void StartSoundEngine() = 0; - virtual void doPlayerMovement(const double scaleAdjust) = 0; + virtual void doPlayerMovement(const double scaleAdjust); virtual unsigned getCrouchState() = 0; virtual FString statFPS() diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 37c76ef45..4f7dd36c4 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -135,7 +135,6 @@ struct GameInterface : public ::GameInterface void AddQAVInterpProps(const int res_id, const FString& interptype, const bool loopable, const TMap>&& ignoredata) override; void RemoveQAVInterpProps(const int res_id) override; void StartSoundEngine() override; - void doPlayerMovement(const double scaleAdjust) override { gameInput.processMovement(&getPlayer(myconnectindex)->Angles, scaleAdjust); } unsigned getCrouchState() override; }; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 216604927..1039719b2 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -529,11 +529,11 @@ void GameInterface::doPlayerMovement(const double scaleAdjust) baseVel = VEHICLETURN * velScale; } - gameInput.processVehicle(&p->Angles, scaleAdjust, baseVel, velScale, vehFlags); + gameInput.processVehicle(scaleAdjust, baseVel, velScale, vehFlags); } else { - gameInput.processMovement(&p->Angles, scaleAdjust, p->drink_amt, true, (p->psectlotag != ST_2_UNDERWATER) ? 1. : 0.875); + gameInput.processMovement(scaleAdjust, p->drink_amt, true, (p->psectlotag != ST_2_UNDERWATER) ? 1. : 0.875); } } diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 85c990b27..b1e742c98 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -238,7 +238,6 @@ struct GameInterface : public ::GameInterface void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; void StartSoundEngine() override; - void doPlayerMovement(const double scaleAdjust) override { gameInput.processMovement(&getPlayer(nLocalPlayer)->Angles, scaleAdjust); } unsigned getCrouchState() override; }; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 5fbebac78..227f9dda2 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1904,7 +1904,7 @@ struct GameInterface : public ::GameInterface void doPlayerMovement(const double scaleAdjust) override { const auto pp = getPlayer(myconnectindex); - gameInput.processMovement(&pp->Angles, scaleAdjust, 0, !pp->sop, pp->sop_control ? (3. / 1.40625) : 1.); + gameInput.processMovement(scaleAdjust, 0, !pp->sop, pp->sop_control ? (3. / 1.40625) : 1.); } };