From ea4e8506748881924ccb69b1ca4d948498b9675f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 31 Mar 2023 00:31:59 +1100 Subject: [PATCH] - Move remaining mouse CVARs from `inputstate.cpp` to `gameinput.cpp`. --- source/core/gameinput.cpp | 13 ++++++++++++- source/core/inputstate.cpp | 22 ---------------------- source/core/inputstate.h | 11 +++++------ 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 5f96211a7..038cd9ce6 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -37,6 +37,8 @@ CVAR(Float, m_pitch, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) CVAR(Float, m_yaw, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) CVAR(Float, m_forward, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) CVAR(Float, m_side, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) +CVARD(Bool, invertmousex, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert horizontal mouse movement") +CVARD(Bool, invertmouse, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert vertical mouse movement") //--------------------------------------------------------------------------- @@ -58,6 +60,7 @@ static int dpad_lock = 0; ESyncBits ActionsToSend = 0; bool crouch_toggle = false; +static constexpr float backendmousescale = 1.f / 16.f; static constexpr double YAW_TURNSPEEDS[3] = { 41.1987304, 156.555175, 272.24121 }; static constexpr double YAW_PREAMBLESCALE = YAW_TURNSPEEDS[0] / YAW_TURNSPEEDS[1]; static constexpr double YAW_LOOKINGSPEED = 801.5625; @@ -191,7 +194,7 @@ void processVehicleInput(HIDInput* const hidInput, InputPacket* const currInput, SB_AIM_UP | SB_AIM_DOWN | SB_AIMMODE | SB_LOOK_UP | SB_LOOK_DOWN | SB_LOOK_LEFT | SB_LOOK_RIGHT); // Cancel out micro-movement - if (fabs(hidInput->mouse.X) < (m_sensitivity_x * backendinputscale() * 2.f)) + if (fabs(hidInput->mouse.X) < (m_sensitivity_x * backendmousescale * 2.f)) hidInput->mouse.X = 0; // Yes, we need all these bools... @@ -254,6 +257,14 @@ static void ApplyGlobalInput(HIDInput* const hidInput) inputState.GetMouseDelta(hidInput->mouse); if (use_joystick) I_GetAxes(hidInput->joyaxes); + hidInput->mouse *= backendmousescale; + + if (invertmousex) + hidInput->mouse.X = -hidInput->mouse.X; + + if (invertmouse) + hidInput->mouse.Y = -hidInput->mouse.Y; + if (WeaponToSend != 0) inputBuffer.setNewWeapon(WeaponToSend); WeaponToSend = 0; if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select)) diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index ede340aed..0dd5e7646 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -44,28 +44,6 @@ #include "gamestate.h" #include "gameinput.h" -// Mouse speeds -CVARD(Bool, invertmousex, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert horizontal mouse movement") -CVARD(Bool, invertmouse, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "invert vertical mouse movement") - -//========================================================================== -// -// -// -//========================================================================== - -void InputState::GetMouseDelta(FVector2& hidInput) -{ - hidInput = g_mousePos * backendinputscale(); - g_mousePos.Zero(); - - if (invertmousex) - hidInput.X = -hidInput.X; - - if (invertmouse) - hidInput.Y = -hidInput.Y; -} - //========================================================================== // // diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 302661fc1..f4d094d10 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -34,7 +34,11 @@ public: g_mousePos.Y += y; } - void GetMouseDelta(FVector2& hidInput); + void GetMouseDelta(FVector2& gameinput) + { + gameinput = g_mousePos; + g_mousePos.Zero(); + } void ClearAllInput(); bool CheckAllInput() @@ -85,8 +89,3 @@ enum GameFunction_t }; void SetupGameButtons(); - -inline float backendinputscale() -{ - return (1.f / 16.f); -}