Skip to content

Commit 9e39788

Browse files
authored
[rcore] fix gamepad axis movement and its automation event recording (#4184)
* [rcore] fix gamepad axis movement and its automation event recording This commit fixes 2 issues: - Automation events aren't recorded for negative axis movements on gamepads (e.g. stick going left/up) - 'GetGamepadAxisMovement' drift check isn't working correctly for triggers. Axis values between [-0.1, 0.1] are clamped to 0.0 Behaviour change: - 'GetGamepadAxisMovement' returns default value for each axis, even if gamepad isn't attached. * [rcore] inline body of 'GetGamepadAxisMovementDefault' and remove it
1 parent e5a1fc4 commit 9e39788

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/rcore.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,10 +2952,14 @@ int GetGamepadAxisCount(int gamepad)
29522952
// Get axis movement vector for a gamepad
29532953
float GetGamepadAxisMovement(int gamepad, int axis)
29542954
{
2955-
float value = 0;
2955+
float value = (axis == GAMEPAD_AXIS_LEFT_TRIGGER || axis == GAMEPAD_AXIS_RIGHT_TRIGGER)? -1.0f : 0.0f;
29562956

2957-
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS) &&
2958-
(fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]) > 0.1f)) value = CORE.Input.Gamepad.axisState[gamepad][axis]; // 0.1f = GAMEPAD_AXIS_MINIMUM_DRIFT/DELTA
2957+
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS)) {
2958+
float movement = value < 0.0f ? CORE.Input.Gamepad.axisState[gamepad][axis] : fabs(CORE.Input.Gamepad.axisState[gamepad][axis]);
2959+
2960+
// 0.1f = GAMEPAD_AXIS_MINIMUM_DRIFT/DELTA
2961+
if (movement > value + 0.1f) value = CORE.Input.Gamepad.axisState[gamepad][axis];
2962+
}
29592963

29602964
return value;
29612965
}
@@ -3599,7 +3603,8 @@ static void RecordAutomationEvent(void)
35993603
for (int axis = 0; axis < MAX_GAMEPAD_AXIS; axis++)
36003604
{
36013605
// Event type: INPUT_GAMEPAD_AXIS_MOTION
3602-
if (CORE.Input.Gamepad.axisState[gamepad][axis] > 0.1f)
3606+
float defaultMovement = (axis == GAMEPAD_AXIS_LEFT_TRIGGER || axis == GAMEPAD_AXIS_RIGHT_TRIGGER)? -1.0f : 0.0f;
3607+
if (GetGamepadAxisMovement(gamepad, axis) != defaultMovement)
36033608
{
36043609
currentEventList->events[currentEventList->count].frame = CORE.Time.frameCounter;
36053610
currentEventList->events[currentEventList->count].type = INPUT_GAMEPAD_AXIS_MOTION;

0 commit comments

Comments
 (0)