Fix #4405 at runtime

This commit is contained in:
asdqwe 2024-10-22 10:52:57 -03:00
parent 4cd243f0a3
commit 85b90d8816
2 changed files with 10 additions and 1 deletions

View File

@ -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 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 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 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 // Input-related functions: mouse
RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once RLAPI bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once

View File

@ -349,6 +349,7 @@ typedef struct CoreData {
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous 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 axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
float globalDeadzone; // Global gamepad axis deadzone
} Gamepad; } Gamepad;
} Input; } 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.scale = (Vector2){ 1.0f, 1.0f };
CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW; CORE.Input.Mouse.cursor = MOUSE_CURSOR_ARROW;
CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN; CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN;
CORE.Input.Gamepad.globalDeadzone = 0.1f;
// Initialize platform // 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]); 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 // 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; return value;
} }
// Set gamepad global deadzone
void SetGamepadDeadzone(float deadzone)
{
CORE.Input.Gamepad.globalDeadzone = deadzone;
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Definition: Input Handling: Mouse // Module Functions Definition: Input Handling: Mouse
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------