diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 0dc32701a..133ce4c40 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -21,11 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- -#include "gamecontrol.h" #include "gameinput.h" -#include "gamestruct.h" -#include "serializer.h" -#include "gamefuncs.h" //--------------------------------------------------------------------------- // @@ -73,7 +69,7 @@ static inline DAngle getscaledangle(const DAngle angle, const double scale, cons static inline bool scaletozero(DAngle& angle, const double scale, const DAngle push = DAngle::fromDeg(32. / 465.)) { - auto sgn = angle.Sgn(); + const auto sgn = angle.Sgn(); if (!sgn || sgn != (angle -= getscaledangle(angle, scale, push * sgn)).Sgn()) { @@ -92,7 +88,7 @@ static inline bool scaletozero(DAngle& angle, const double scale, const DAngle p static double turnheldtime; -void updateTurnHeldAmt(double const scaleAdjust) +void updateTurnHeldAmt(const double scaleAdjust) { turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust; } @@ -114,23 +110,23 @@ void resetTurnHeldAmt() // //--------------------------------------------------------------------------- -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt, bool const allowstrafe, double const turnscale) +void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. - int const keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); - float const hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); - float const scaleAdjustf = float(scaleAdjust); + 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. - auto const turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); - auto const moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dz * scaleAdjustf; - auto const strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf; + 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) + hidInput->dz * scaleAdjustf; + const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf; // process player angle input. if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) { - float const turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); - float const turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); + const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); + const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE)); currInput->avel += hidInput->mouseturnx + (hidInput->dyaw * hidspeed + turndir * turnspeed) * scaleAdjustf; if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt(); } @@ -207,22 +203,22 @@ void PlayerAngles::doPitchKeys(InputPacket* const input) // //--------------------------------------------------------------------------- -void PlayerAngles::doYawKeys(ESyncBits* actions) +void PlayerAngles::doYawKeys(InputPacket* const input) { - if (*actions & SB_TURNAROUND) + if (input->actions & SB_TURNAROUND) { if (YawSpin == nullAngle) { // currently not spinning, so start a spin YawSpin = -DAngle180; } - *actions &= ~SB_TURNAROUND; + input->actions &= ~SB_TURNAROUND; } if (YawSpin < nullAngle) { // return spin to 0 - DAngle add = DAngle::fromDeg(getTicrateScale(!(*actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH)); + DAngle add = DAngle::fromDeg(getTicrateScale(!(input->actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH)); YawSpin += add; if (YawSpin > nullAngle) { @@ -296,17 +292,17 @@ void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing) // //--------------------------------------------------------------------------- -void PlayerAngles::doViewYaw(const ESyncBits actions) +void PlayerAngles::doViewYaw(InputPacket* const input) { // Process angle return to zeros. scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN); scaletozero(ViewAngles.Roll, YAW_LOOKRETURN); // Process keyboard input. - if (auto looking = !!(actions & SB_LOOK_RIGHT) - !!(actions & SB_LOOK_LEFT)) + if (const auto looking = !!(input->actions & SB_LOOK_RIGHT) - !!(input->actions & SB_LOOK_LEFT)) { - ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED)) * looking; - ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED)) * looking; + ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED) * looking); + ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED) * looking); } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index c8951476b..edc26c054 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -1,10 +1,7 @@ #pragma once -#include "m_fixed.h" -#include "gamecvars.h" -#include "gamestruct.h" +#include "serializer.h" #include "gamefuncs.h" -#include "packet.h" struct PlayerAngles { @@ -21,9 +18,9 @@ struct PlayerAngles // Prototypes. void doPitchKeys(InputPacket* const input); - void doYawKeys(ESyncBits* actions); + void doYawKeys(InputPacket* const input); void doViewPitch(const bool canslopetilt, const bool climbing = false); - void doViewYaw(const ESyncBits actions); + void doViewYaw(InputPacket* const input); // General methods. void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle) @@ -83,7 +80,7 @@ class FSerializer; FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); -void updateTurnHeldAmt(double const scaleAdjust); +void updateTurnHeldAmt(const double scaleAdjust); bool isTurboTurnTime(); void resetTurnHeldAmt(); -void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1); +void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 829d565d0..6ff6d4b75 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1569,14 +1569,14 @@ void ProcessInput(PLAYER* pPlayer) actor->vel.XY() += DVector2(pInput->fvel * fvAccel, pInput->svel * svAccel).Rotated(actor->spr.Angles.Yaw) * speed; } - pPlayer->Angles.doViewYaw(pInput->actions); + pPlayer->Angles.doViewYaw(pInput); if (SyncInput()) { pPlayer->actor->spr.Angles.Yaw += DAngle::fromDeg(pInput->avel); } - pPlayer->Angles.doYawKeys(&pInput->actions); + pPlayer->Angles.doYawKeys(pInput); if (!(pInput->actions & SB_JUMP)) pPlayer->cantJump = 0; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 67b6b7fe3..335e0e750 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2756,7 +2756,7 @@ void processinput_d(int snum) p->psectlotag = psectlotag; //Do the quick lefts and rights - p->Angles.doViewYaw(actions); + p->Angles.doViewYaw(&p->sync); if (movementBlocked(p)) { @@ -2773,7 +2773,7 @@ void processinput_d(int snum) p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum)); } - p->Angles.doYawKeys(&actions); + p->Angles.doYawKeys(&p->sync); purplelavacheck(p); if (p->spritebridge == 0 && pact->insector()) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index a2664a379..59a0da549 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3442,7 +3442,7 @@ void processinput_r(int snum) p->psectlotag = psectlotag; //Do the quick lefts and rights - p->Angles.doViewYaw(actions); + p->Angles.doViewYaw(&p->sync); if (movementBlocked(p)) { @@ -3459,7 +3459,7 @@ void processinput_r(int snum) p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum)); } - p->Angles.doYawKeys(&actions); + p->Angles.doYawKeys(&p->sync); purplelavacheck(p); if (p->spritebridge == 0 && pact->insector()) diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index ce0cd3b32..56ef4ef50 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -976,7 +976,7 @@ void AIPlayer::Tick(RunListEvent* ev) } } - PlayerList[nPlayer].Angles.doViewYaw(sPlayerInput[nLocalPlayer].actions); + PlayerList[nPlayer].Angles.doViewYaw(&PlayerList[nLocalPlayer].input); // loc_1A494: if (SyncInput()) @@ -984,7 +984,7 @@ void AIPlayer::Tick(RunListEvent* ev) PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(PlayerList[nPlayer].input.avel); } - PlayerList[nPlayer].Angles.doYawKeys(&sPlayerInput[nLocalPlayer].actions); + PlayerList[nPlayer].Angles.doYawKeys(&PlayerList[nLocalPlayer].input); UpdatePlayerSpriteAngle(&PlayerList[nPlayer]); // player.zvel is modified within Gravity() diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 8d7a23779..42b47e65d 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -2024,7 +2024,7 @@ void DoPlayerMove(PLAYER* pp) SlipSlope(pp); - pp->Angles.doViewYaw(pp->input.actions); + pp->Angles.doViewYaw(&pp->input); if (!SyncInput()) { @@ -2035,7 +2035,7 @@ void DoPlayerMove(PLAYER* pp) pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel); } - pp->Angles.doYawKeys(&pp->input.actions); + pp->Angles.doYawKeys(&pp->input); UpdatePlayerSpriteAngle(pp); pp->lastcursector = pp->cursector;