| 51 | } |
| 52 | |
| 53 | static void pollControllerState() |
| 54 | { |
| 55 | std::memset(input.gamepad.bButtons, 0, sizeof(input.gamepad.bButtons)); |
| 56 | std::memset(input.gamepad.bHat, 0, sizeof(input.gamepad.bHat)); |
| 57 | input.gamepad.lAxisX = 0; |
| 58 | input.gamepad.lAxisY = 0; |
| 59 | input.gamepad.lAxisZ = 0; |
| 60 | input.gamepad.lAxisRz = 0; |
| 61 | |
| 62 | if (!g_controller) |
| 63 | return; |
| 64 | |
| 65 | input.gamepad.bButtons[GPB_A] = |
| 66 | SDL_GameControllerGetButton(g_controller, SDL_CONTROLLER_BUTTON_A) != 0; |
| 67 | input.gamepad.bButtons[GPB_B] = |
| 68 | SDL_GameControllerGetButton(g_controller, SDL_CONTROLLER_BUTTON_B) != 0; |
| 69 | input.gamepad.bButtons[GPB_X] = |
| 70 | SDL_GameControllerGetButton(g_controller, SDL_CONTROLLER_BUTTON_X) != 0; |
| 71 | input.gamepad.bButtons[GPB_Y] = |
| 72 | SDL_GameControllerGetButton(g_controller, SDL_CONTROLLER_BUTTON_Y) != 0; |
| 73 | input.gamepad.bButtons[GPB_LB] = SDL_GameControllerGetButton( |
| 74 | g_controller, |
| 75 | SDL_CONTROLLER_BUTTON_LEFTSHOULDER) != 0; |
| 76 | input.gamepad.bButtons[GPB_RB] = SDL_GameControllerGetButton( |
| 77 | g_controller, |
| 78 | SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) != 0; |
| 79 | input.gamepad.bButtons[GPB_SL] = SDL_GameControllerGetButton( |
| 80 | g_controller, SDL_CONTROLLER_BUTTON_BACK) != 0; |
| 81 | input.gamepad.bButtons[GPB_ST] = SDL_GameControllerGetButton( |
| 82 | g_controller, SDL_CONTROLLER_BUTTON_START) != 0; |
| 83 | input.gamepad.bButtons[GPB_LS] = SDL_GameControllerGetButton( |
| 84 | g_controller, SDL_CONTROLLER_BUTTON_LEFTSTICK) != 0; |
| 85 | input.gamepad.bButtons[GPB_RS] = SDL_GameControllerGetButton( |
| 86 | g_controller, SDL_CONTROLLER_BUTTON_RIGHTSTICK) != 0; |
| 87 | |
| 88 | const bool dpadUp = |
| 89 | SDL_GameControllerGetButton(g_controller, SDL_CONTROLLER_BUTTON_DPAD_UP) != 0; |
| 90 | const bool dpadDown = SDL_GameControllerGetButton( |
| 91 | g_controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN) != 0; |
| 92 | const bool dpadLeft = SDL_GameControllerGetButton( |
| 93 | g_controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT) != 0; |
| 94 | const bool dpadRight = SDL_GameControllerGetButton( |
| 95 | g_controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT) != 0; |
| 96 | |
| 97 | input.gamepad.bHat[GPH_UP] = dpadUp; |
| 98 | input.gamepad.bHat[GPH_DOWN] = dpadDown; |
| 99 | input.gamepad.bHat[GPH_LEFT] = dpadLeft; |
| 100 | input.gamepad.bHat[GPH_RIGHT] = dpadRight; |
| 101 | input.gamepad.bHat[GPH_LEFTUP] = dpadLeft && dpadUp; |
| 102 | input.gamepad.bHat[GPH_RIGHTUP] = dpadRight && dpadUp; |
| 103 | input.gamepad.bHat[GPH_LEFTDOWN] = dpadLeft && dpadDown; |
| 104 | input.gamepad.bHat[GPH_RIGHTDOWN] = dpadRight && dpadDown; |
| 105 | |
| 106 | input.gamepad.lAxisX = |
| 107 | SDL_GameControllerGetAxis(g_controller, SDL_CONTROLLER_AXIS_LEFTX); |
| 108 | input.gamepad.lAxisY = |
| 109 | -SDL_GameControllerGetAxis(g_controller, SDL_CONTROLLER_AXIS_LEFTY); |
| 110 | input.gamepad.lAxisZ = |