From 85b90d8816567ae18b19fbf4ed2ae31effe89f48 Mon Sep 17 00:00:00 2001 From: asdqwe Date: Tue, 22 Oct 2024 10:52:57 -0300 Subject: [PATCH] Fix #4405 at runtime --- src/raylib.h | 1 + src/rcore.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/raylib.h b/src/raylib.h index fc505f787..25a015d57 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1185,6 +1185,7 @@ RLAPI int GetGamepadAxisCount(int gamepad); RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB) RLAPI void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration); // Set gamepad vibration for both motors (duration in seconds) +RLAPI void SetGamepadDeadzone(float deadzone); // Set gamepad global deadzone // Input-related functions: mouse RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once diff --git a/src/rcore.c b/src/rcore.c index a1771d18e..626b7521a 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -349,6 +349,7 @@ typedef struct CoreData { char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state + float globalDeadzone; // Global gamepad axis deadzone } Gamepad; } Input; @@ -642,6 +643,7 @@ void InitWindow(int width, int height, const char *title) CORE.Input.Mouse.scale = (Vector2){ 1.0f, 1.0f }; CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW; CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN; + CORE.Input.Gamepad.globalDeadzone = 0.1f; // Initialize platform //-------------------------------------------------------------- @@ -3296,12 +3298,18 @@ float GetGamepadAxisMovement(int gamepad, int axis) float movement = value < 0.0f ? CORE.Input.Gamepad.axisState[gamepad][axis] : fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]); // 0.1f = GAMEPAD_AXIS_MINIMUM_DRIFT/DELTA - if (movement > value + 0.1f) value = CORE.Input.Gamepad.axisState[gamepad][axis]; + if (movement > value + CORE.Input.Gamepad.globalDeadzone) value = CORE.Input.Gamepad.axisState[gamepad][axis]; } return value; } +// Set gamepad global deadzone +void SetGamepadDeadzone(float deadzone) +{ + CORE.Input.Gamepad.globalDeadzone = deadzone; +} + //---------------------------------------------------------------------------------- // Module Functions Definition: Input Handling: Mouse //----------------------------------------------------------------------------------