From eed9716d86d66f6aedbeca6f989784b7cd1068db Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 17 Mar 2023 20:42:19 +1100 Subject: [PATCH] - Move `joyaxes[]` array from `getHidInput()` directly into `ControlInfo`. --- source/core/gameinput.cpp | 12 ++++----- source/core/inputstate.cpp | 44 ++++++++------------------------- source/core/inputstate.h | 14 +++++------ source/games/duke/src/input.cpp | 42 +++++++++++++++---------------- 4 files changed, 44 insertions(+), 68 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index da97d5b05..9f38183b6 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -119,27 +119,27 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe // determine player input. 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->dforward * scaleAdjustf; - const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dside * scaleAdjustf; + const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->joyaxes[JOYAXIS_Forward] * scaleAdjustf; + const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->joyaxes[JOYAXIS_Side] * scaleAdjustf; // 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)); - currInput->avel += hidInput->mouseturnx - (hidInput->dyaw * hidspeed - turndir * turnspeed) * scaleAdjustf; + currInput->avel += hidInput->mouseturnx - (hidInput->joyaxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf; if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt(); } else { - currInput->svel += hidInput->mousemovex - (hidInput->dyaw - turning) * keymove * scaleAdjustf; + currInput->svel += hidInput->mousemovex - (hidInput->joyaxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf; } // process player pitch input. if (!(inputBuffer->actions & SB_AIMMODE)) - currInput->horz += hidInput->mouseturny - hidInput->dpitch * hidspeed * scaleAdjustf; + currInput->horz += hidInput->mouseturny - hidInput->joyaxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf; else - currInput->fvel -= hidInput->mousemovey - hidInput->dpitch * keymove * scaleAdjustf; + currInput->fvel -= hidInput->mousemovey - hidInput->joyaxes[JOYAXIS_Pitch] * keymove * scaleAdjustf; // process movement input. currInput->fvel += moving * keymove; diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 5da4b3edd..01bd661b5 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -195,30 +195,6 @@ int32_t handleevents(void) return 0; } -//========================================================================== -// -// -// -//========================================================================== - -void getHidInput(HIDInput* const hidInput) -{ - inputState.GetMouseDelta(hidInput); - - if (use_joystick) - { - // Handle joysticks/game controllers. - float joyaxes[NUM_JOYAXIS]; - - I_GetAxes(joyaxes); - - hidInput->dyaw += joyaxes[JOYAXIS_Yaw]; - hidInput->dpitch += joyaxes[JOYAXIS_Pitch]; - hidInput->dforward += joyaxes[JOYAXIS_Forward] * .5f; - hidInput->dside += joyaxes[JOYAXIS_Side] * .5f; - } -} - //--------------------------------------------------------------------------- // // @@ -401,33 +377,33 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const croucha if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select)) { // These buttons should not autorepeat. The game handlers are not really equipped for that. - if (hidInput->dforward > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } + if (hidInput->joyaxes[JOYAXIS_Forward] > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); } else dpad_lock &= ~1; - if (hidInput->dforward < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } + if (hidInput->joyaxes[JOYAXIS_Forward] < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); } else dpad_lock &= ~2; - if ((hidInput->dside < 0 || hidInput->dyaw > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } + if ((hidInput->joyaxes[JOYAXIS_Side] < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; } else dpad_lock &= ~4; - if ((hidInput->dside > 0 || hidInput->dyaw < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } + if ((hidInput->joyaxes[JOYAXIS_Side] > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; } else dpad_lock &= ~8; // This eats the controller input for regular use - hidInput->dside = 0; - hidInput->dforward = 0; - hidInput->dyaw = 0; + hidInput->joyaxes[JOYAXIS_Side] = 0; + hidInput->joyaxes[JOYAXIS_Forward] = 0; + hidInput->joyaxes[JOYAXIS_Yaw] = 0; } else dpad_lock = 0; input.actions |= ActionsToSend; ActionsToSend = 0; - if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward > 0)) + if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] > 0)) input.actions |= SB_AIM_UP; - if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward < 0))) + if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] < 0))) input.actions |= SB_AIM_DOWN; if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) - hidInput->dforward = 0; + hidInput->joyaxes[JOYAXIS_Forward] = 0; if (buttonMap.ButtonDown(gamefunc_Jump)) input.actions |= SB_JUMP; diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 52a0740a3..bc766c7fd 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -16,12 +16,7 @@ struct HIDInput { - float dside; - float dup; - float dforward; - float dyaw; - float dpitch; - float droll; + float joyaxes[NUM_JOYAXIS]; float mouseturnx; float mouseturny; float mousemovex; @@ -63,7 +58,6 @@ public: extern InputState inputState; -void getHidInput(HIDInput* const hidInput); int32_t handleevents(void); enum GameFunction_t @@ -116,6 +110,12 @@ inline float backendinputscale() return (1.f / 16.f); } +inline void getHidInput(HIDInput* const hidInput) +{ + inputState.GetMouseDelta(hidInput); + if (use_joystick) I_GetAxes(hidInput->joyaxes); +} + //--------------------------------------------------------------------------- // // Inline functions to help with edge cases where synchronised input is needed. diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 97589d589..1e8edefee 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -564,13 +564,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons { resetTurnHeldAmt(); - if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) + if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) { p->TiltStatus -= (float)factor; if (p->TiltStatus < -10) p->TiltStatus = -10; } - else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) + else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) { p->TiltStatus += (float)factor; if (p->TiltStatus > 10) @@ -579,12 +579,12 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons } else { - if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) + if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) { constexpr float velScale = (3.f / 10.f); - const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dforward < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) { p->TiltStatus -= (float)factor; @@ -597,13 +597,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx < 0) turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw > 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) { p->TiltStatus += (float)factor; @@ -616,8 +616,8 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx > 0) turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw < 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } @@ -652,12 +652,12 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (p->MotoSpeed) { - if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw) + if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) { const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); const float baseVel = VEHICLETURN * velScale; - if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0) + if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) { if (!p->NotOnWater) { @@ -672,13 +672,13 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx < 0) turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw > 0) - turnvel += baseVel * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } - if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0) + if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) { if (!p->NotOnWater) { @@ -693,8 +693,8 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons if (hidInput->mouseturnx > 0) turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - if (hidInput->dyaw < 0) - turnvel += baseVel * hidInput->dyaw; + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; updateTurnHeldAmt(factor); } @@ -739,13 +739,13 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu // Cancel out micro-movement if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) hidInput->mouseturnx = 0; - p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0; - p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0; + p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0; + p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0; if (p->OnBoat || !p->moto_underwater) { - p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->dforward, 1.f); - p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->dforward, 1.f); + p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->joyaxes[JOYAXIS_Forward], 1.f); + p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->joyaxes[JOYAXIS_Forward], 1.f); p->vehBraking = buttonMap.ButtonDown(gamefunc_Run); }