diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 8de886aad..a085b69e0 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1415,9 +1415,9 @@ void GameInterface::FreeLevelData() // //--------------------------------------------------------------------------- -void GameInterface::GetInput(InputPacket* const currInput, const double scaleAdjust) +void GameInterface::doPlayerMovement(const double scaleAdjust) { - gameInput.processMovement(currInput, scaleAdjust); + gameInput.processMovement(scaleAdjust); } //--------------------------------------------------------------------------- diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 7951de103..4c842b7d0 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -102,12 +102,15 @@ void processCrouchToggle(bool& toggle, ESyncBits& actions, const bool crouchable //--------------------------------------------------------------------------- // -// Player's movement function, called from game's ticker or from gi->GetInput() as required. +// Player's movement function, called from game's ticker or from gi->doPlayerMovement() as required. // //--------------------------------------------------------------------------- -void GameInput::processMovement(InputPacket* const currInput, 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) { + // 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); @@ -123,33 +126,45 @@ void GameInput::processMovement(InputPacket* const currInput, const double scale { 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 += mouseInput.X * m_yaw - (joyAxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf; + thisInput.avel += mouseInput.X * m_yaw - (joyAxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf; if (turndir) updateTurnHeldAmt(scaleAdjust); else turnheldtime = 0; } else { - currInput->svel += mouseInput.X * m_side - (joyAxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf; + thisInput.svel += mouseInput.X * m_side - (joyAxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf; } // process player pitch input. if (!(inputBuffer.actions & SB_AIMMODE)) - currInput->horz -= mouseInput.Y * m_pitch + joyAxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf; + { + thisInput.horz -= mouseInput.Y * m_pitch + joyAxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf; + } else - currInput->fvel += mouseInput.Y * m_forward + joyAxes[JOYAXIS_Pitch] * keymove * scaleAdjustf; + { + thisInput.fvel += mouseInput.Y * m_forward + joyAxes[JOYAXIS_Pitch] * keymove * scaleAdjustf; + } // process movement input. - currInput->fvel += moving * keymove; - currInput->svel += strafing * keymove * allowstrafe; + thisInput.fvel += moving * keymove; + thisInput.svel += strafing * keymove * allowstrafe; // process RR's drunk state. if (isRR() && drink_amt >= 66 && drink_amt <= 87) - currInput->svel += drink_amt & 1 ? -currInput->fvel : currInput->fvel; + thisInput.svel += drink_amt & 1 ? -thisInput.fvel : thisInput.fvel; // add collected input to game's local input accumulation packet. - inputBuffer.fvel = clamp(inputBuffer.fvel + currInput->fvel, -(float)keymove, (float)keymove); - inputBuffer.svel = clamp(inputBuffer.svel + currInput->svel, -(float)keymove, (float)keymove); - inputBuffer.avel = clamp(inputBuffer.avel + currInput->avel, -179.f, 179.f); - inputBuffer.horz = clamp(inputBuffer.horz + currInput->horz, -179.f, 179.f); + inputBuffer.fvel = clamp(inputBuffer.fvel + thisInput.fvel, -(float)keymove, (float)keymove); + inputBuffer.svel = clamp(inputBuffer.svel + thisInput.svel, -(float)keymove, (float)keymove); + inputBuffer.avel = clamp(inputBuffer.avel + thisInput.avel, -179.f, 179.f); + inputBuffer.horz = clamp(inputBuffer.horz + thisInput.horz, -179.f, 179.f); + + // directly update player angles if we can. + if (scaleAdjust < 1) + { + const auto plrAngles = gi->getConsoleAngles(); + plrAngles->CameraAngles.Yaw += DAngle::fromDeg(thisInput.avel); + plrAngles->CameraAngles.Pitch += DAngle::fromDeg(thisInput.horz); + } } @@ -159,8 +174,11 @@ void GameInput::processMovement(InputPacket* const currInput, const double scale // //--------------------------------------------------------------------------- -void GameInput::processVehicle(InputPacket* const currInput, const double scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate) +void GameInput::processVehicle(const double 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{}; + // mask out all actions not compatible with vehicles. 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); @@ -169,7 +187,7 @@ void GameInput::processVehicle(InputPacket* const currInput, const double scaleA { const auto kbdForwards = buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe); const auto kbdBackward = buttonMap.ButtonDown(gamefunc_Move_Backward); - currInput->fvel = kbdForwards - kbdBackward + joyAxes[JOYAXIS_Forward]; + thisInput.fvel = kbdForwards - kbdBackward + joyAxes[JOYAXIS_Forward]; if (buttonMap.ButtonDown(gamefunc_Run)) inputBuffer.actions |= SB_CROUCH; } @@ -185,9 +203,9 @@ void GameInput::processVehicle(InputPacket* const currInput, const double scaleA const auto kbdDir = kbdRight - kbdLeft; const auto turnVel = (!attenuate && (isTurboTurnTime() || hidLeft || hidRight)) ? (baseVel) : (baseVel * velScale); - currInput->avel += turnVel * -joyAxes[JOYAXIS_Yaw] + turnVel * kbdDir; - currInput->avel += sqrtf(abs(turnVel * mouseInput.X * m_yaw / (float)scaleAdjust) * (7.f / 20.f)) * Sgn(turnVel) * Sgn(mouseInput.X); - currInput->avel *= (float)scaleAdjust; + 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; if (kbdDir) updateTurnHeldAmt(scaleAdjust); else turnheldtime = 0; } else @@ -195,8 +213,16 @@ void GameInput::processVehicle(InputPacket* const currInput, const double scaleA turnheldtime = 0; } - inputBuffer.fvel = clamp(inputBuffer.fvel + currInput->fvel, -1.00f, 1.00f); - inputBuffer.avel = clamp(inputBuffer.avel + currInput->avel, -179.f, 179.f); + inputBuffer.fvel = clamp(inputBuffer.fvel + thisInput.fvel, -1.00f, 1.00f); + inputBuffer.avel = clamp(inputBuffer.avel + thisInput.avel, -179.f, 179.f); + + // directly update player angles if we can. + if (scaleAdjust < 1) + { + const auto plrAngles = gi->getConsoleAngles(); + plrAngles->CameraAngles.Yaw += DAngle::fromDeg(thisInput.avel); + plrAngles->CameraAngles.Pitch += DAngle::fromDeg(thisInput.horz); + } } @@ -321,37 +347,24 @@ void GameInput::processInputBits() // //--------------------------------------------------------------------------- -void GameInput::getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet) +void GameInput::getInput(const double scaleAdjust, InputPacket* packet) { - if (M_Active() || gamestate != GS_LEVEL || !plrAngles || !plrAngles->pActor) + if (M_Active() || gamestate != GS_LEVEL) { inputBuffer = {}; return; } - InputPacket input{}; prepareHidInput(); processInputBits(); - - // Directly update the camera angles if we're unsynchronised. - if (!SyncInput()) - { - gi->GetInput(&input, scaleAdjust); - plrAngles->CameraAngles.Yaw += DAngle::fromDeg(input.avel); - plrAngles->CameraAngles.Pitch += DAngle::fromDeg(input.horz); - } - else - { - gi->GetInput(&input, 1); - } + gi->doPlayerMovement(!SyncInput() ? scaleAdjust : 1.); + resetHidInput(); if (packet) { *packet = inputBuffer; inputBuffer = {}; } - - resetHidInput(); } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 00dcb6d07..05e83b3c0 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -75,9 +75,9 @@ public: } // Prototypes for large member functions. - void processMovement(InputPacket* const currInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); - void processVehicle(InputPacket* const currInput, const double scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); - void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet = nullptr); + 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 getInput(const double scaleAdjust, InputPacket* packet = nullptr); }; struct PlayerAngles @@ -89,7 +89,8 @@ struct PlayerAngles DAngle YawSpin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); - friend void GameInput::getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet); + 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); // Prototypes. void doPitchKeys(InputPacket* const input); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 033b20135..b02a59fb1 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 GetInput(InputPacket* const currInput, const double scaleAdjust); + virtual void doPlayerMovement(const double scaleAdjust); virtual FString statFPS() { diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 2777c238a..6302cbb87 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -137,7 +137,7 @@ void G_BuildTiccmd(ticcmd_t* cmd) } cmd->ucmd = {}; I_GetEvent(); - gameInput.getInput(inputScale, gi->getConsoleAngles(), &cmd->ucmd); + gameInput.getInput(inputScale, &cmd->ucmd); cmd->consistency = consistency[myconnectindex][(maketic / ticdup) % BACKUPTICS]; } @@ -606,7 +606,7 @@ void TryRunTics (void) if (!SyncInput()) { I_GetEvent(); - gameInput.getInput(inputScale, gi->getConsoleAngles()); + gameInput.getInput(inputScale); } return; } diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index a454f69dd..347dc1b2b 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 GetInput(InputPacket* const currInput, const double scaleAdjust) override; + void doPlayerMovement(const double 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 6b17c64a1..217500788 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::GetInput(InputPacket* const currInput, const double scaleAdjust) +void GameInterface::doPlayerMovement(const double scaleAdjust) { auto const p = &ps[myconnectindex]; @@ -525,11 +525,11 @@ void GameInterface::GetInput(InputPacket* const currInput, const double scaleAdj const auto canTurn = p->OnMotorcycle || p->MotoSpeed || p->moto_drink; const auto attenuate = p->OnMotorcycle && p->MotoSpeed <= 0; - gameInput.processVehicle(currInput, scaleAdjust, baseVel, velScale, canMove, canTurn, attenuate); + gameInput.processVehicle(scaleAdjust, baseVel, velScale, canMove, canTurn, attenuate); } else { - gameInput.processMovement(currInput, scaleAdjust, p->drink_amt); + gameInput.processMovement(scaleAdjust, p->drink_amt); } } diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 37c1b6cd1..59941ceda 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1889,9 +1889,9 @@ 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 GetInput(InputPacket* const currInput, const double scaleAdjust) override + void doPlayerMovement(const double scaleAdjust) override { - gameInput.processMovement(currInput, scaleAdjust, 0, !Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); + gameInput.processMovement(scaleAdjust, 0, !Player[myconnectindex].sop, Player[myconnectindex].sop_control ? 3. / 1.40625 : 1.); }