Просмотр исходного кода

fix: set correct default axes for gamepads that are not connected (inside rcore_desktop_glfw.c) (#5444)

* fix: set correct default axes for gamepads that are not connected

`glfwGetGamepadState` will set all gamepad state variables to 0.0 if required gamepad is not connected, but `RecordAutomationEvent()` inside rcore.c expects trigger axes to be -1.0f when gamepad is not connected. Since SDL and RGFW return -1.0f in such case, this change is aligning it with them

* updated comment in rcore_desktop_glfw.c
pull/5438/head
Dino 3 дней назад
committed by GitHub
Родитель
Сommit
aee6734cff
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: B5690EEEBB952194
1 измененных файлов: 8 добавлений и 2 удалений
  1. +8
    -2
      src/platforms/rcore_desktop_glfw.c

+ 8
- 2
src/platforms/rcore_desktop_glfw.c Просмотреть файл

@ -1266,8 +1266,14 @@ void PollInputEvents(void)
// Get current gamepad state
// NOTE: There is no callback available, so we get it manually
GLFWgamepadstate state = { 0 };
glfwGetGamepadState(i, &state); // This remapps all gamepads so they have their buttons mapped like an xbox controller
int isGamepadConnected = glfwGetGamepadState(i, &state); // This remapps all gamepads so they have their buttons mapped like an xbox controller
if (!isGamepadConnected)
{
// setting axes to expected resting value instead of GLFW's 0.0f default when gamepad isnt connected
state.axes[GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
state.axes[GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
}
const unsigned char *buttons = state.buttons;
for (int k = 0; (buttons != NULL) && (k < MAX_GAMEPAD_BUTTONS); k++)

Загрузка…
Отмена
Сохранить