From 8c12037ef422fb49e31775963e844def7f5332ca Mon Sep 17 00:00:00 2001 From: Marcus Minhorst Date: Mon, 7 Jul 2025 21:38:47 -0400 Subject: [PATCH] Unified gamepad settings --- src/common/engine/m_joy.cpp | 17 +++++++++++ src/common/engine/m_joy.h | 12 ++++++++ .../platform/posix/cocoa/i_joystick.cpp | 18 ++++------- src/common/platform/posix/sdl/i_joystick.cpp | 30 +++++++++---------- src/common/platform/win32/i_dijoy.cpp | 13 ++++---- src/common/platform/win32/i_rawps2.cpp | 19 ++++++------ src/common/platform/win32/i_xinput.cpp | 18 +++++------ 7 files changed, 72 insertions(+), 55 deletions(-) diff --git a/src/common/engine/m_joy.cpp b/src/common/engine/m_joy.cpp index 9f1c3cae5..4ea016879 100644 --- a/src/common/engine/m_joy.cpp +++ b/src/common/engine/m_joy.cpp @@ -58,6 +58,23 @@ EXTERN_CVAR(Bool, joy_ps2raw) EXTERN_CVAR(Bool, joy_dinput) EXTERN_CVAR(Bool, joy_xinput) +extern const float JOYDEADZONE_DEFAULT = 0.1; // reduced from 0.25 + +extern const float JOYSENSITIVITY_DEFAULT = 1.0; + +extern const float JOYTHRESH_DEFAULT = 0.05; +extern const float JOYTHRESH_TRIGGER = 0.05; +extern const float JOYTHRESH_STICK_X = 0.65; +extern const float JOYTHRESH_STICK_Y = 0.35; + +extern const CubicBezier JOYCURVE[NUM_JOYCURVE] = { + {{0.3, 0.0, 0.7, 0.4}}, // DEFAULT -> QUADRATIC + + {{0.0, 0.0, 1.0, 1.0}}, // LINEAR + {{0.3, 0.0, 0.7, 0.4}}, // QUADRATIC + {{0.5, 0.0, 0.7, 0.2}}, // CUBIC +}; + // PUBLIC DATA DEFINITIONS ------------------------------------------------- CUSTOM_CVARD(Bool, use_joystick, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL, "enables input from the joystick if it is present") diff --git a/src/common/engine/m_joy.h b/src/common/engine/m_joy.h index 60321785a..87dca60a3 100644 --- a/src/common/engine/m_joy.h +++ b/src/common/engine/m_joy.h @@ -38,6 +38,18 @@ enum EJoyAxis NUM_JOYAXIS, }; +extern const float JOYDEADZONE_DEFAULT; + +extern const float JOYSENSITIVITY_DEFAULT; + +extern const float JOYTHRESH_DEFAULT; + +extern const float JOYTHRESH_TRIGGER; +extern const float JOYTHRESH_STICK_X; +extern const float JOYTHRESH_STICK_Y; + +extern const CubicBezier JOYCURVE[NUM_JOYCURVE]; + // Generic configuration interface for a controller. struct IJoystickConfig { diff --git a/src/common/platform/posix/cocoa/i_joystick.cpp b/src/common/platform/posix/cocoa/i_joystick.cpp index e338ad8dd..6eeb2eb56 100644 --- a/src/common/platform/posix/cocoa/i_joystick.cpp +++ b/src/common/platform/posix/cocoa/i_joystick.cpp @@ -185,10 +185,6 @@ private: io_object_t m_notification; - - static const float DEFAULT_DEADZONE; - static const float DEFAULT_SENSITIVITY; - void ProcessAxes(); bool ProcessAxis (const IOHIDEventStruct& event); bool ProcessButton(const IOHIDEventStruct& event); @@ -208,10 +204,6 @@ private: }; -const float IOKitJoystick::DEFAULT_DEADZONE = 0.25f; -const float IOKitJoystick::DEFAULT_SENSITIVITY = 1.0f; - - IOHIDDeviceInterface** CreateDeviceInterface(const io_object_t device) { IOCFPlugInInterface** plugInInterface = NULL; @@ -294,7 +286,7 @@ IOHIDQueueInterface** CreateDeviceQueue(IOHIDDeviceInterface** const interface) IOKitJoystick::IOKitJoystick(const io_object_t device) : m_interface(CreateDeviceInterface(device)) , m_queue(CreateDeviceQueue(m_interface)) -, m_sensitivity(DEFAULT_SENSITIVITY) +, m_sensitivity(JOYSENSITIVITY_DEFAULT) , m_enabled(true) , m_useAxesPolling(true) , m_notification(0) @@ -449,7 +441,7 @@ void IOKitJoystick::SetAxisResponseCurvePoint(int axis, int point, float value) bool IOKitJoystick::IsSensitivityDefault() { - return DEFAULT_SENSITIVITY == m_sensitivity; + return JOYSENSITIVITY_DEFAULT == m_sensitivity; } bool IOKitJoystick::IsAxisDeadZoneDefault(int axis) @@ -498,14 +490,14 @@ void IOKitJoystick::SetEnabled(bool enabled) void IOKitJoystick::SetDefaultConfig() { - m_sensitivity = DEFAULT_SENSITIVITY; + m_sensitivity = JOYSENSITIVITY_DEFAULT; const size_t axisCount = m_axes.Size(); for (size_t i = 0; i < axisCount; ++i) { - m_axes[i].deadZone = DEFAULT_DEADZONE; - m_axes[i].sensitivity = DEFAULT_SENSITIVITY; + m_axes[i].deadZone = JOYDEADZONE_DEFAULT; + m_axes[i].sensitivity = JOYSENSITIVITY_DEFAULT; m_axes[i].gameAxis = JOYAXIS_None; } diff --git a/src/common/platform/posix/sdl/i_joystick.cpp b/src/common/platform/posix/sdl/i_joystick.cpp index 6654bcae3..000562e30 100644 --- a/src/common/platform/posix/sdl/i_joystick.cpp +++ b/src/common/platform/posix/sdl/i_joystick.cpp @@ -40,15 +40,13 @@ #include "m_joy.h" #include "keydef.h" -#define DEFAULT_DEADZONE 0.25f; - -// Very small deadzone so that floating point magic doesn't happen -#define MIN_DEADZONE 0.000001f - class SDLInputJoystick: public IJoystickConfig { public: - SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f) , Enabled(true) + SDLInputJoystick(int DeviceIndex) : + DeviceIndex(DeviceIndex), + Multiplier(JOYSENSITIVITY_DEFAULT) , + Enabled(true) { if (SDL_IsGameController(DeviceIndex)) { @@ -143,7 +141,7 @@ public: void SetAxisDeadZone(int axis, float zone) { - Axes[axis].DeadZone = clamp(zone, MIN_DEADZONE, 1.f); + Axes[axis].DeadZone = clamp(zone, 0.f, 1.f); } void SetAxisMap(int axis, EJoyAxis gameaxis) { @@ -166,11 +164,11 @@ public: // Used by the saver to not save properties that are at their defaults. bool IsSensitivityDefault() { - return Multiplier == 1.0f; + return Multiplier == JOYSENSITIVITY_DEFAULT; } bool IsAxisDeadZoneDefault(int axis) { - return Axes[axis].DeadZone <= MIN_DEADZONE; + return Axes[axis].DeadZone <= JOYDEADZONE_DEFAULT; } bool IsAxisMapDefault(int axis) { @@ -180,7 +178,7 @@ public: } bool IsAxisScaleDefault(int axis) { - return Axes[axis].Multiplier == 1.0f; + return Axes[axis].Multiplier == JOYSENSITIVITY_DEFAULT; } bool IsAxisDigitalThresholdDefault(int axis) { @@ -214,8 +212,8 @@ public: info.Name.Format("Hat %d (%c)", (i-NumAxes)/2 + 1, (i-NumAxes)%2 == 0 ? 'x' : 'y'); } - info.DeadZone = DEFAULT_DEADZONE; - info.Multiplier = 1.0f; + info.DeadZone = JOYDEADZONE_DEFAULT; + info.Multiplier = JOYSENSITIVITY_DEFAULT; info.Value = 0.0; info.ButtonValue = 0; @@ -398,8 +396,8 @@ void SDLInputJoystick::ProcessInput() { { // GameController API available - auto lastTriggerL = Axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT].Value > MIN_DEADZONE; - auto lastTriggerR = Axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT].Value > MIN_DEADZONE; + auto lastTriggerL = Axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT].Value > JOYTHRESH_DEFAULT; + auto lastTriggerR = Axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT].Value > JOYTHRESH_DEFAULT; for (auto i = 0; i < SDL_CONTROLLER_AXIS_MAX && i < NumAxes; ++i) { @@ -409,8 +407,8 @@ void SDLInputJoystick::ProcessInput() { Axes[i].Value = Joy_RemoveDeadZone(Axes[i].Value, Axes[i].DeadZone, &buttonstate); } - auto currTriggerL = Axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT].Value > MIN_DEADZONE; - auto currTriggerR = Axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT].Value > MIN_DEADZONE; + auto currTriggerL = Axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT].Value > JOYTHRESH_DEFAULT; + auto currTriggerR = Axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT].Value > JOYTHRESH_DEFAULT; if (lastTriggerL != currTriggerL) PostKeyEvent(currTriggerL, KEY_PAD_LTRIGGER); if (lastTriggerR != currTriggerR) PostKeyEvent(currTriggerR, KEY_PAD_RTRIGGER); diff --git a/src/common/platform/win32/i_dijoy.cpp b/src/common/platform/win32/i_dijoy.cpp index d3ada1e22..f87456606 100644 --- a/src/common/platform/win32/i_dijoy.cpp +++ b/src/common/platform/win32/i_dijoy.cpp @@ -146,8 +146,6 @@ public: // MACROS ------------------------------------------------------------------ -#define DEFAULT_DEADZONE 0.25f - // TYPES ------------------------------------------------------------------- class FDInputJoystick : public FInputDevice, IJoystickConfig @@ -769,11 +767,11 @@ void FDInputJoystick::SetDefaultConfig() { unsigned i; - Multiplier = 1; + Multiplier = JOYSENSITIVITY_DEFAULT; for (i = 0; i < Axes.Size(); ++i) { - Axes[i].DeadZone = DEFAULT_DEADZONE; - Axes[i].Multiplier = 1; + Axes[i].DeadZone = JOYDEADZONE_DEFAULT; + Axes[i].Multiplier = JOYSENSITIVITY_DEFAULT; Axes[i].GameAxis = JOYAXIS_None; } // Triggers on a 360 controller have a much smaller deadzone. @@ -796,7 +794,8 @@ void FDInputJoystick::SetDefaultConfig() // Four axes? First two are movement, last two are looking around. if (Axes.Size() >= 4) { - Axes[3].GameAxis = JOYAXIS_Pitch; Axes[3].Multiplier = 0.75f; + Axes[3].GameAxis = JOYAXIS_Pitch; + // Axes[3].Multiplier = 0.75f; // Five axes? Use the fifth one for moving up and down. if (Axes.Size() >= 5) { @@ -857,7 +856,7 @@ void FDInputJoystick::SetSensitivity(float scale) bool FDInputJoystick::IsSensitivityDefault() { - return Multiplier == 1; + return Multiplier == JOYSENSITIVITY_DEFAULT; } //=========================================================================== diff --git a/src/common/platform/win32/i_rawps2.cpp b/src/common/platform/win32/i_rawps2.cpp index 69eea017a..a76e02f45 100644 --- a/src/common/platform/win32/i_rawps2.cpp +++ b/src/common/platform/win32/i_rawps2.cpp @@ -48,7 +48,6 @@ // MACROS ------------------------------------------------------------------ -#define DEFAULT_DEADZONE 0.25f #define STATUS_SWITCH_TIME 3 #define VID_PLAY_COM 0x0b43 @@ -114,13 +113,13 @@ public: void SetAxisDigitalThreshold(int axis, float threshold); void SetAxisResponseCurve(int axis, EJoyCurve preset); void SetAxisResponseCurvePoint(int axis, int point, float value); - bool IsAxisDigitalThresholdDefault(int axis); - bool IsAxisResponseCurveDefault(int axis); bool IsSensitivityDefault(); bool IsAxisDeadZoneDefault(int axis); bool IsAxisMapDefault(int axis); bool IsAxisScaleDefault(int axis); + bool IsAxisDigitalThresholdDefault(int axis); + bool IsAxisResponseCurveDefault(int axis); bool GetEnabled(); void SetEnabled(bool enabled); @@ -366,10 +365,10 @@ static const char *AxisNames[] = FRawPS2Controller::DefaultAxisConfig FRawPS2Controller::DefaultAxes[NUM_AXES] = { // Game axis, multiplier - { JOYAXIS_Side, 1 }, // ThumbLX - { JOYAXIS_Forward, 1 }, // ThumbLY - { JOYAXIS_Yaw, 1 }, // ThumbRX - { JOYAXIS_Pitch, 0.75 }, // ThumbRY + { JOYAXIS_Side, JOYSENSITIVITY_DEFAULT }, // ThumbLX + { JOYAXIS_Forward, JOYSENSITIVITY_DEFAULT }, // ThumbLY + { JOYAXIS_Yaw, JOYSENSITIVITY_DEFAULT }, // ThumbRX + { JOYAXIS_Pitch, JOYSENSITIVITY_DEFAULT }, // ThumbRY }; // CODE -------------------------------------------------------------------- @@ -652,10 +651,10 @@ void FRawPS2Controller::AddAxes(float axes[NUM_JOYAXIS]) void FRawPS2Controller::SetDefaultConfig() { - Multiplier = 1; + Multiplier = JOYSENSITIVITY_DEFAULT; for (int i = 0; i < NUM_AXES; ++i) { - Axes[i].DeadZone = DEFAULT_DEADZONE; + Axes[i].DeadZone = JOYDEADZONE_DEFAULT; Axes[i].GameAxis = DefaultAxes[i].GameAxis; Axes[i].Multiplier = DefaultAxes[i].Multiplier; } @@ -720,7 +719,7 @@ void FRawPS2Controller::SetSensitivity(float scale) bool FRawPS2Controller::IsSensitivityDefault() { - return Multiplier == 1; + return Multiplier == JOYSENSITIVITY_DEFAULT; } //========================================================================== diff --git a/src/common/platform/win32/i_xinput.cpp b/src/common/platform/win32/i_xinput.cpp index f9cdbe2e5..031aebc37 100644 --- a/src/common/platform/win32/i_xinput.cpp +++ b/src/common/platform/win32/i_xinput.cpp @@ -220,12 +220,12 @@ static const char *AxisNames[] = FXInputController::DefaultAxisConfig FXInputController::DefaultAxes[NUM_AXES] = { // Dead zone, game axis, multiplier - { XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32768.f, JOYAXIS_Side, 1 }, // ThumbLX - { XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32768.f, JOYAXIS_Forward, 1 }, // ThumbLY - { XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE / 32768.f, JOYAXIS_Yaw, 1 }, // ThumbRX - { XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE / 32768.f, JOYAXIS_Pitch, 0.75 }, // ThumbRY - { XINPUT_GAMEPAD_TRIGGER_THRESHOLD / 256.f, JOYAXIS_None, 0 }, // LeftTrigger - { XINPUT_GAMEPAD_TRIGGER_THRESHOLD / 256.f, JOYAXIS_None, 0 } // RightTrigger + { XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32768.f, JOYAXIS_Side, JOYSENSITIVITY_DEFAULT }, // ThumbLX + { XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32768.f, JOYAXIS_Forward, JOYSENSITIVITY_DEFAULT }, // ThumbLY + { XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE / 32768.f, JOYAXIS_Yaw, JOYSENSITIVITY_DEFAULT }, // ThumbRX + { XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE / 32768.f, JOYAXIS_Pitch, JOYSENSITIVITY_DEFAULT }, // ThumbRY + { XINPUT_GAMEPAD_TRIGGER_THRESHOLD / 256.f, JOYAXIS_None, JOYSENSITIVITY_DEFAULT }, // LeftTrigger + { XINPUT_GAMEPAD_TRIGGER_THRESHOLD / 256.f, JOYAXIS_None, JOYSENSITIVITY_DEFAULT } // RightTrigger }; // CODE -------------------------------------------------------------------- @@ -439,7 +439,7 @@ void FXInputController::AddAxes(float axes[NUM_JOYAXIS]) void FXInputController::SetDefaultConfig() { - Multiplier = 1; + Multiplier = JOYSENSITIVITY_DEFAULT; for (int i = 0; i < NUM_AXES; ++i) { Axes[i].DeadZone = DefaultAxes[i].DeadZone; @@ -502,7 +502,7 @@ void FXInputController::SetSensitivity(float scale) bool FXInputController::IsSensitivityDefault() { - return Multiplier == 1; + return Multiplier == JOYSENSITIVITY_DEFAULT; } //========================================================================== @@ -573,7 +573,7 @@ float FXInputController::GetAxisScale(int axis) { return Axes[axis].Multiplier; } - return 0; + return JOYSENSITIVITY_DEFAULT; } //==========================================================================