diff options
| author | 2021-05-14 21:17:08 -0500 | |
|---|---|---|
| committer | 2021-05-14 21:17:08 -0500 | |
| commit | 85eeae7aad96fd5272f77ce0e24608417ad5c68e (patch) | |
| tree | 81f0537f4141b5d43b802c76037a0af7f119e2a7 /src/input_common/sdl/sdl_impl.cpp | |
| parent | Merge pull request #6300 from Morph1984/mbedtls (diff) | |
| download | yuzu-85eeae7aad96fd5272f77ce0e24608417ad5c68e.tar.gz yuzu-85eeae7aad96fd5272f77ce0e24608417ad5c68e.tar.xz yuzu-85eeae7aad96fd5272f77ce0e24608417ad5c68e.zip | |
input_common: Rewrite sdl analog mapping
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index f682a6db4..c918a333d 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -1168,51 +1168,51 @@ public: | |||
| 1168 | void Start(const std::string& device_id) override { | 1168 | void Start(const std::string& device_id) override { |
| 1169 | SDLPoller::Start(device_id); | 1169 | SDLPoller::Start(device_id); |
| 1170 | // Reset stored axes | 1170 | // Reset stored axes |
| 1171 | analog_x_axis = -1; | 1171 | first_axis = -1; |
| 1172 | analog_y_axis = -1; | ||
| 1173 | } | 1172 | } |
| 1174 | 1173 | ||
| 1175 | Common::ParamPackage GetNextInput() override { | 1174 | Common::ParamPackage GetNextInput() override { |
| 1176 | SDL_Event event; | 1175 | SDL_Event event; |
| 1177 | while (state.event_queue.Pop(event)) { | 1176 | while (state.event_queue.Pop(event)) { |
| 1178 | // Filter out axis events that are below a threshold | 1177 | if (event.type != SDL_JOYAXISMOTION) { |
| 1179 | if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) { | 1178 | // Check for a button press |
| 1180 | continue; | ||
| 1181 | } | ||
| 1182 | if (event.type == SDL_JOYAXISMOTION) { | ||
| 1183 | const auto axis = event.jaxis.axis; | ||
| 1184 | // In order to return a complete analog param, we need inputs for both axes. | ||
| 1185 | // First we take the x-axis (horizontal) input, then the y-axis (vertical) input. | ||
| 1186 | if (analog_x_axis == -1) { | ||
| 1187 | analog_x_axis = axis; | ||
| 1188 | } else if (analog_y_axis == -1 && analog_x_axis != axis) { | ||
| 1189 | analog_y_axis = axis; | ||
| 1190 | } | ||
| 1191 | } else { | ||
| 1192 | // If the press wasn't accepted as a joy axis, check for a button press | ||
| 1193 | auto button_press = button_poller.FromEvent(event); | 1179 | auto button_press = button_poller.FromEvent(event); |
| 1194 | if (button_press) { | 1180 | if (button_press) { |
| 1195 | return *button_press; | 1181 | return *button_press; |
| 1196 | } | 1182 | } |
| 1183 | continue; | ||
| 1184 | } | ||
| 1185 | const auto axis = event.jaxis.axis; | ||
| 1186 | |||
| 1187 | // Filter out axis events that are below a threshold | ||
| 1188 | if (std::abs(event.jaxis.value / 32767.0) < 0.5) { | ||
| 1189 | continue; | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | // Filter out axis events that are the same | ||
| 1193 | if (first_axis == axis) { | ||
| 1194 | continue; | ||
| 1195 | } | ||
| 1196 | |||
| 1197 | // In order to return a complete analog param, we need inputs for both axes. | ||
| 1198 | // If the first axis isn't set we set the value then wait till next event | ||
| 1199 | if (first_axis == -1) { | ||
| 1200 | first_axis = axis; | ||
| 1201 | continue; | ||
| 1197 | } | 1202 | } |
| 1198 | } | ||
| 1199 | 1203 | ||
| 1200 | if (analog_x_axis != -1 && analog_y_axis != -1) { | ||
| 1201 | if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which)) { | 1204 | if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which)) { |
| 1202 | auto params = BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(), | 1205 | auto params = BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(), |
| 1203 | analog_x_axis, analog_y_axis); | 1206 | first_axis, axis); |
| 1204 | analog_x_axis = -1; | 1207 | first_axis = -1; |
| 1205 | analog_y_axis = -1; | ||
| 1206 | return params; | 1208 | return params; |
| 1207 | } | 1209 | } |
| 1208 | } | 1210 | } |
| 1209 | |||
| 1210 | return {}; | 1211 | return {}; |
| 1211 | } | 1212 | } |
| 1212 | 1213 | ||
| 1213 | private: | 1214 | private: |
| 1214 | int analog_x_axis = -1; | 1215 | int first_axis = -1; |
| 1215 | int analog_y_axis = -1; | ||
| 1216 | SDLButtonPoller button_poller; | 1216 | SDLButtonPoller button_poller; |
| 1217 | }; | 1217 | }; |
| 1218 | } // namespace Polling | 1218 | } // namespace Polling |