- int numaxes;
- int numbuttons;
- numaxes = SDL_JoystickNumAxes(joy);
- for (j = 0;j < numaxes;j++)
- joystate->axis[j] = SDL_JoystickGetAxis(joy, j) * (1.0f / 32767.0f);
- numbuttons = SDL_JoystickNumButtons(joy);
- for (j = 0;j < numbuttons;j++)
- joystate->button[j] = SDL_JoystickGetButton(joy, j);
+
+ if (vid_sdlgamecontroller)
+ {
+ for (j = 0; j <= SDL_CONTROLLER_AXIS_MAX; ++j)
+ {
+ joystate->axis[j] = SDL_GameControllerGetAxis(vid_sdlgamecontroller, j) * (1.0f / 32767.0f);
+ }
+ for (j = 0; j < SDL_CONTROLLER_BUTTON_MAX; ++j)
+ joystate->button[j] = SDL_GameControllerGetButton(vid_sdlgamecontroller, j);
+ // emulate joy buttons for trigger "axes"
+ joystate->button[SDL_CONTROLLER_BUTTON_MAX] = VID_JoyState_GetAxis(joystate, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 1, joy_sdl2_trigger_deadzone.value) > 0.0f;
+ joystate->button[SDL_CONTROLLER_BUTTON_MAX+1] = VID_JoyState_GetAxis(joystate, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 1, joy_sdl2_trigger_deadzone.value) > 0.0f;
+ }
+ else
+
+ {
+ int numaxes;
+ int numbuttons;
+ numaxes = SDL_JoystickNumAxes(joy);
+ for (j = 0;j < numaxes;j++)
+ joystate->axis[j] = SDL_JoystickGetAxis(joy, j) * (1.0f / 32767.0f);
+ numbuttons = SDL_JoystickNumButtons(joy);
+ for (j = 0;j < numbuttons;j++)
+ joystate->button[j] = SDL_JoystickGetButton(joy, j);
+ }