diff options
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index a9f7e5103..6024ed97a 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -1068,7 +1068,6 @@ public: | |||
| 1068 | 1068 | ||
| 1069 | void Start(const std::string& device_id) override { | 1069 | void Start(const std::string& device_id) override { |
| 1070 | SDLPoller::Start(device_id); | 1070 | SDLPoller::Start(device_id); |
| 1071 | // Load the game controller | ||
| 1072 | // Reset stored axes | 1071 | // Reset stored axes |
| 1073 | analog_x_axis = -1; | 1072 | analog_x_axis = -1; |
| 1074 | analog_y_axis = -1; | 1073 | analog_y_axis = -1; |
| @@ -1081,40 +1080,21 @@ public: | |||
| 1081 | if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) { | 1080 | if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) { |
| 1082 | continue; | 1081 | continue; |
| 1083 | } | 1082 | } |
| 1084 | // Simplify controller config by testing if game controller support is enabled. | ||
| 1085 | if (event.type == SDL_JOYAXISMOTION) { | 1083 | if (event.type == SDL_JOYAXISMOTION) { |
| 1086 | const auto axis = event.jaxis.axis; | 1084 | const auto axis = event.jaxis.axis; |
| 1087 | if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 1085 | // In order to return a complete analog param, we need inputs for both axes. |
| 1088 | auto* const controller = joystick->GetSDLGameController()) { | 1086 | // First we take the x-axis (horizontal) input, then the y-axis (vertical) input. |
| 1089 | const auto axis_left_x = | 1087 | if (analog_x_axis == -1) { |
| 1090 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX) | 1088 | analog_x_axis = axis; |
| 1091 | .value.axis; | 1089 | } else if (analog_y_axis == -1 && analog_x_axis != axis) { |
| 1092 | const auto axis_left_y = | 1090 | analog_y_axis = axis; |
| 1093 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY) | 1091 | } |
| 1094 | .value.axis; | 1092 | } else { |
| 1095 | const auto axis_right_x = | 1093 | // If the press wasn't accepted as a joy axis, check for a button press |
| 1096 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX) | 1094 | auto button_press = button_poller.FromEvent(event); |
| 1097 | .value.axis; | 1095 | if (button_press) { |
| 1098 | const auto axis_right_y = | 1096 | return *button_press; |
| 1099 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY) | ||
| 1100 | .value.axis; | ||
| 1101 | |||
| 1102 | if (axis == axis_left_x || axis == axis_left_y) { | ||
| 1103 | analog_x_axis = axis_left_x; | ||
| 1104 | analog_y_axis = axis_left_y; | ||
| 1105 | break; | ||
| 1106 | } else if (axis == axis_right_x || axis == axis_right_y) { | ||
| 1107 | analog_x_axis = axis_right_x; | ||
| 1108 | analog_y_axis = axis_right_y; | ||
| 1109 | break; | ||
| 1110 | } | ||
| 1111 | } | 1097 | } |
| 1112 | } | ||
| 1113 | |||
| 1114 | // If the press wasn't accepted as a joy axis, check for a button press | ||
| 1115 | auto button_press = button_poller.FromEvent(event); | ||
| 1116 | if (button_press) { | ||
| 1117 | return *button_press; | ||
| 1118 | } | 1098 | } |
| 1119 | } | 1099 | } |
| 1120 | 1100 | ||
| @@ -1127,6 +1107,7 @@ public: | |||
| 1127 | return params; | 1107 | return params; |
| 1128 | } | 1108 | } |
| 1129 | } | 1109 | } |
| 1110 | |||
| 1130 | return {}; | 1111 | return {}; |
| 1131 | } | 1112 | } |
| 1132 | 1113 | ||