summaryrefslogtreecommitdiff
path: root/src/input_common/sdl/sdl_impl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp671
1 files changed, 671 insertions, 0 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
new file mode 100644
index 000000000..5949ecbae
--- /dev/null
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -0,0 +1,671 @@
1// Copyright 2018 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <atomic>
7#include <cmath>
8#include <functional>
9#include <iterator>
10#include <mutex>
11#include <string>
12#include <thread>
13#include <tuple>
14#include <unordered_map>
15#include <utility>
16#include <vector>
17#include <SDL.h>
18#include "common/assert.h"
19#include "common/logging/log.h"
20#include "common/math_util.h"
21#include "common/param_package.h"
22#include "common/threadsafe_queue.h"
23#include "core/frontend/input.h"
24#include "input_common/sdl/sdl_impl.h"
25
26namespace InputCommon {
27
28namespace SDL {
29
30static std::string GetGUID(SDL_Joystick* joystick) {
31 SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
32 char guid_str[33];
33 SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
34 return guid_str;
35}
36
37/// Creates a ParamPackage from an SDL_Event that can directly be used to create a ButtonDevice
38static Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Event& event);
39
40static int SDLEventWatcher(void* userdata, SDL_Event* event) {
41 SDLState* sdl_state = reinterpret_cast<SDLState*>(userdata);
42 // Don't handle the event if we are configuring
43 if (sdl_state->polling) {
44 sdl_state->event_queue.Push(*event);
45 } else {
46 sdl_state->HandleGameControllerEvent(*event);
47 }
48 return 0;
49}
50
51class SDLJoystick {
52public:
53 SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick,
54 decltype(&SDL_JoystickClose) deleter = &SDL_JoystickClose)
55 : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, deleter} {}
56
57 void SetButton(int button, bool value) {
58 std::lock_guard lock{mutex};
59 state.buttons[button] = value;
60 }
61
62 bool GetButton(int button) const {
63 std::lock_guard lock{mutex};
64 return state.buttons.at(button);
65 }
66
67 void SetAxis(int axis, Sint16 value) {
68 std::lock_guard lock{mutex};
69 state.axes[axis] = value;
70 }
71
72 float GetAxis(int axis) const {
73 std::lock_guard lock{mutex};
74 return state.axes.at(axis) / 32767.0f;
75 }
76
77 std::tuple<float, float> GetAnalog(int axis_x, int axis_y) const {
78 float x = GetAxis(axis_x);
79 float y = GetAxis(axis_y);
80 y = -y; // 3DS uses an y-axis inverse from SDL
81
82 // Make sure the coordinates are in the unit circle,
83 // otherwise normalize it.
84 float r = x * x + y * y;
85 if (r > 1.0f) {
86 r = std::sqrt(r);
87 x /= r;
88 y /= r;
89 }
90
91 return std::make_tuple(x, y);
92 }
93
94 void SetHat(int hat, Uint8 direction) {
95 std::lock_guard lock{mutex};
96 state.hats[hat] = direction;
97 }
98
99 bool GetHatDirection(int hat, Uint8 direction) const {
100 std::lock_guard lock{mutex};
101 return (state.hats.at(hat) & direction) != 0;
102 }
103 /**
104 * The guid of the joystick
105 */
106 const std::string& GetGUID() const {
107 return guid;
108 }
109
110 /**
111 * The number of joystick from the same type that were connected before this joystick
112 */
113 int GetPort() const {
114 return port;
115 }
116
117 SDL_Joystick* GetSDLJoystick() const {
118 return sdl_joystick.get();
119 }
120
121 void SetSDLJoystick(SDL_Joystick* joystick,
122 decltype(&SDL_JoystickClose) deleter = &SDL_JoystickClose) {
123 sdl_joystick =
124 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)>(joystick, deleter);
125 }
126
127private:
128 struct State {
129 std::unordered_map<int, bool> buttons;
130 std::unordered_map<int, Sint16> axes;
131 std::unordered_map<int, Uint8> hats;
132 } state;
133 std::string guid;
134 int port;
135 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
136 mutable std::mutex mutex;
137};
138
139/**
140 * Get the nth joystick with the corresponding GUID
141 */
142std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickByGUID(const std::string& guid, int port) {
143 std::lock_guard lock{joystick_map_mutex};
144 const auto it = joystick_map.find(guid);
145 if (it != joystick_map.end()) {
146 while (it->second.size() <= port) {
147 auto joystick = std::make_shared<SDLJoystick>(guid, it->second.size(), nullptr,
148 [](SDL_Joystick*) {});
149 it->second.emplace_back(std::move(joystick));
150 }
151 return it->second[port];
152 }
153 auto joystick = std::make_shared<SDLJoystick>(guid, 0, nullptr, [](SDL_Joystick*) {});
154 return joystick_map[guid].emplace_back(std::move(joystick));
155}
156
157/**
158 * Check how many identical joysticks (by guid) were connected before the one with sdl_id and so tie
159 * it to a SDLJoystick with the same guid and that port
160 */
161std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
162 auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
163 const std::string guid = GetGUID(sdl_joystick);
164
165 std::lock_guard lock{joystick_map_mutex};
166 auto map_it = joystick_map.find(guid);
167 if (map_it != joystick_map.end()) {
168 auto vec_it = std::find_if(map_it->second.begin(), map_it->second.end(),
169 [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) {
170 return sdl_joystick == joystick->GetSDLJoystick();
171 });
172 if (vec_it != map_it->second.end()) {
173 // This is the common case: There is already an existing SDL_Joystick maped to a
174 // SDLJoystick. return the SDLJoystick
175 return *vec_it;
176 }
177 // Search for a SDLJoystick without a mapped SDL_Joystick...
178 auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(),
179 [](const std::shared_ptr<SDLJoystick>& joystick) {
180 return !joystick->GetSDLJoystick();
181 });
182 if (nullptr_it != map_it->second.end()) {
183 // ... and map it
184 (*nullptr_it)->SetSDLJoystick(sdl_joystick);
185 return *nullptr_it;
186 }
187 // There is no SDLJoystick without a mapped SDL_Joystick
188 // Create a new SDLJoystick
189 auto joystick = std::make_shared<SDLJoystick>(guid, map_it->second.size(), sdl_joystick);
190 return map_it->second.emplace_back(std::move(joystick));
191 }
192 auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick);
193 return joystick_map[guid].emplace_back(std::move(joystick));
194}
195
196void SDLState::InitJoystick(int joystick_index) {
197 SDL_Joystick* sdl_joystick = SDL_JoystickOpen(joystick_index);
198 if (!sdl_joystick) {
199 LOG_ERROR(Input, "failed to open joystick {}", joystick_index);
200 return;
201 }
202 const std::string guid = GetGUID(sdl_joystick);
203
204 std::lock_guard lock{joystick_map_mutex};
205 if (joystick_map.find(guid) == joystick_map.end()) {
206 auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick);
207 joystick_map[guid].emplace_back(std::move(joystick));
208 return;
209 }
210 auto& joystick_guid_list = joystick_map[guid];
211 const auto it = std::find_if(
212 joystick_guid_list.begin(), joystick_guid_list.end(),
213 [](const std::shared_ptr<SDLJoystick>& joystick) { return !joystick->GetSDLJoystick(); });
214 if (it != joystick_guid_list.end()) {
215 (*it)->SetSDLJoystick(sdl_joystick);
216 return;
217 }
218 auto joystick = std::make_shared<SDLJoystick>(guid, joystick_guid_list.size(), sdl_joystick);
219 joystick_guid_list.emplace_back(std::move(joystick));
220}
221
222void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
223 std::string guid = GetGUID(sdl_joystick);
224 std::shared_ptr<SDLJoystick> joystick;
225 {
226 std::lock_guard lock{joystick_map_mutex};
227 // This call to guid is safe since the joystick is guaranteed to be in the map
228 auto& joystick_guid_list = joystick_map[guid];
229 const auto joystick_it =
230 std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(),
231 [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) {
232 return joystick->GetSDLJoystick() == sdl_joystick;
233 });
234 joystick = *joystick_it;
235 }
236 // Destruct SDL_Joystick outside the lock guard because SDL can internally call event calback
237 // which locks the mutex again
238 joystick->SetSDLJoystick(nullptr, [](SDL_Joystick*) {});
239}
240
241void SDLState::HandleGameControllerEvent(const SDL_Event& event) {
242 switch (event.type) {
243 case SDL_JOYBUTTONUP: {
244 if (auto joystick = GetSDLJoystickBySDLID(event.jbutton.which)) {
245 joystick->SetButton(event.jbutton.button, false);
246 }
247 break;
248 }
249 case SDL_JOYBUTTONDOWN: {
250 if (auto joystick = GetSDLJoystickBySDLID(event.jbutton.which)) {
251 joystick->SetButton(event.jbutton.button, true);
252 }
253 break;
254 }
255 case SDL_JOYHATMOTION: {
256 if (auto joystick = GetSDLJoystickBySDLID(event.jhat.which)) {
257 joystick->SetHat(event.jhat.hat, event.jhat.value);
258 }
259 break;
260 }
261 case SDL_JOYAXISMOTION: {
262 if (auto joystick = GetSDLJoystickBySDLID(event.jaxis.which)) {
263 joystick->SetAxis(event.jaxis.axis, event.jaxis.value);
264 }
265 break;
266 }
267 case SDL_JOYDEVICEREMOVED:
268 LOG_DEBUG(Input, "Controller removed with Instance_ID {}", event.jdevice.which);
269 CloseJoystick(SDL_JoystickFromInstanceID(event.jdevice.which));
270 break;
271 case SDL_JOYDEVICEADDED:
272 LOG_DEBUG(Input, "Controller connected with device index {}", event.jdevice.which);
273 InitJoystick(event.jdevice.which);
274 break;
275 }
276}
277
278void SDLState::CloseJoysticks() {
279 std::lock_guard lock{joystick_map_mutex};
280 joystick_map.clear();
281}
282
283class SDLButton final : public Input::ButtonDevice {
284public:
285 explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_)
286 : joystick(std::move(joystick_)), button(button_) {}
287
288 bool GetStatus() const override {
289 return joystick->GetButton(button);
290 }
291
292private:
293 std::shared_ptr<SDLJoystick> joystick;
294 int button;
295};
296
297class SDLDirectionButton final : public Input::ButtonDevice {
298public:
299 explicit SDLDirectionButton(std::shared_ptr<SDLJoystick> joystick_, int hat_, Uint8 direction_)
300 : joystick(std::move(joystick_)), hat(hat_), direction(direction_) {}
301
302 bool GetStatus() const override {
303 return joystick->GetHatDirection(hat, direction);
304 }
305
306private:
307 std::shared_ptr<SDLJoystick> joystick;
308 int hat;
309 Uint8 direction;
310};
311
312class SDLAxisButton final : public Input::ButtonDevice {
313public:
314 explicit SDLAxisButton(std::shared_ptr<SDLJoystick> joystick_, int axis_, float threshold_,
315 bool trigger_if_greater_)
316 : joystick(std::move(joystick_)), axis(axis_), threshold(threshold_),
317 trigger_if_greater(trigger_if_greater_) {}
318
319 bool GetStatus() const override {
320 float axis_value = joystick->GetAxis(axis);
321 if (trigger_if_greater)
322 return axis_value > threshold;
323 return axis_value < threshold;
324 }
325
326private:
327 std::shared_ptr<SDLJoystick> joystick;
328 int axis;
329 float threshold;
330 bool trigger_if_greater;
331};
332
333class SDLAnalog final : public Input::AnalogDevice {
334public:
335 SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, float deadzone_)
336 : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {}
337
338 std::tuple<float, float> GetStatus() const override {
339 const auto [x, y] = joystick->GetAnalog(axis_x, axis_y);
340 const float r = std::sqrt((x * x) + (y * y));
341 if (r > deadzone) {
342 return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone),
343 y / r * (r - deadzone) / (1 - deadzone));
344 }
345 return std::make_tuple<float, float>(0.0f, 0.0f);
346 }
347
348private:
349 std::shared_ptr<SDLJoystick> joystick;
350 const int axis_x;
351 const int axis_y;
352 const float deadzone;
353};
354
355/// A button device factory that creates button devices from SDL joystick
356class SDLButtonFactory final : public Input::Factory<Input::ButtonDevice> {
357public:
358 explicit SDLButtonFactory(SDLState& state_) : state(state_) {}
359
360 /**
361 * Creates a button device from a joystick button
362 * @param params contains parameters for creating the device:
363 * - "guid": the guid of the joystick to bind
364 * - "port": the nth joystick of the same type to bind
365 * - "button"(optional): the index of the button to bind
366 * - "hat"(optional): the index of the hat to bind as direction buttons
367 * - "axis"(optional): the index of the axis to bind
368 * - "direction"(only used for hat): the direction name of the hat to bind. Can be "up",
369 * "down", "left" or "right"
370 * - "threshold"(only used for axis): a float value in (-1.0, 1.0) which the button is
371 * triggered if the axis value crosses
372 * - "direction"(only used for axis): "+" means the button is triggered when the axis
373 * value is greater than the threshold; "-" means the button is triggered when the axis
374 * value is smaller than the threshold
375 */
376 std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override {
377 const std::string guid = params.Get("guid", "0");
378 const int port = params.Get("port", 0);
379
380 auto joystick = state.GetSDLJoystickByGUID(guid, port);
381
382 if (params.Has("hat")) {
383 const int hat = params.Get("hat", 0);
384 const std::string direction_name = params.Get("direction", "");
385 Uint8 direction;
386 if (direction_name == "up") {
387 direction = SDL_HAT_UP;
388 } else if (direction_name == "down") {
389 direction = SDL_HAT_DOWN;
390 } else if (direction_name == "left") {
391 direction = SDL_HAT_LEFT;
392 } else if (direction_name == "right") {
393 direction = SDL_HAT_RIGHT;
394 } else {
395 direction = 0;
396 }
397 // This is necessary so accessing GetHat with hat won't crash
398 joystick->SetHat(hat, SDL_HAT_CENTERED);
399 return std::make_unique<SDLDirectionButton>(joystick, hat, direction);
400 }
401
402 if (params.Has("axis")) {
403 const int axis = params.Get("axis", 0);
404 const float threshold = params.Get("threshold", 0.5f);
405 const std::string direction_name = params.Get("direction", "");
406 bool trigger_if_greater;
407 if (direction_name == "+") {
408 trigger_if_greater = true;
409 } else if (direction_name == "-") {
410 trigger_if_greater = false;
411 } else {
412 trigger_if_greater = true;
413 LOG_ERROR(Input, "Unknown direction {}", direction_name);
414 }
415 // This is necessary so accessing GetAxis with axis won't crash
416 joystick->SetAxis(axis, 0);
417 return std::make_unique<SDLAxisButton>(joystick, axis, threshold, trigger_if_greater);
418 }
419
420 const int button = params.Get("button", 0);
421 // This is necessary so accessing GetButton with button won't crash
422 joystick->SetButton(button, false);
423 return std::make_unique<SDLButton>(joystick, button);
424 }
425
426private:
427 SDLState& state;
428};
429
430/// An analog device factory that creates analog devices from SDL joystick
431class SDLAnalogFactory final : public Input::Factory<Input::AnalogDevice> {
432public:
433 explicit SDLAnalogFactory(SDLState& state_) : state(state_) {}
434 /**
435 * Creates analog device from joystick axes
436 * @param params contains parameters for creating the device:
437 * - "guid": the guid of the joystick to bind
438 * - "port": the nth joystick of the same type
439 * - "axis_x": the index of the axis to be bind as x-axis
440 * - "axis_y": the index of the axis to be bind as y-axis
441 */
442 std::unique_ptr<Input::AnalogDevice> Create(const Common::ParamPackage& params) override {
443 const std::string guid = params.Get("guid", "0");
444 const int port = params.Get("port", 0);
445 const int axis_x = params.Get("axis_x", 0);
446 const int axis_y = params.Get("axis_y", 1);
447 float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f);
448
449 auto joystick = state.GetSDLJoystickByGUID(guid, port);
450
451 // This is necessary so accessing GetAxis with axis_x and axis_y won't crash
452 joystick->SetAxis(axis_x, 0);
453 joystick->SetAxis(axis_y, 0);
454 return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, deadzone);
455 }
456
457private:
458 SDLState& state;
459};
460
461SDLState::SDLState() {
462 using namespace Input;
463 RegisterFactory<ButtonDevice>("sdl", std::make_shared<SDLButtonFactory>(*this));
464 RegisterFactory<AnalogDevice>("sdl", std::make_shared<SDLAnalogFactory>(*this));
465
466 // If the frontend is going to manage the event loop, then we dont start one here
467 start_thread = !SDL_WasInit(SDL_INIT_JOYSTICK);
468 if (start_thread && SDL_Init(SDL_INIT_JOYSTICK) < 0) {
469 LOG_CRITICAL(Input, "SDL_Init(SDL_INIT_JOYSTICK) failed with: {}", SDL_GetError());
470 return;
471 }
472 if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) {
473 LOG_ERROR(Input, "Failed to set Hint for background events", SDL_GetError());
474 }
475
476 SDL_AddEventWatch(&SDLEventWatcher, this);
477
478 initialized = true;
479 if (start_thread) {
480 poll_thread = std::thread([this] {
481 using namespace std::chrono_literals;
482 while (initialized) {
483 SDL_PumpEvents();
484 std::this_thread::sleep_for(10ms);
485 }
486 });
487 }
488 // Because the events for joystick connection happens before we have our event watcher added, we
489 // can just open all the joysticks right here
490 for (int i = 0; i < SDL_NumJoysticks(); ++i) {
491 InitJoystick(i);
492 }
493}
494
495SDLState::~SDLState() {
496 using namespace Input;
497 UnregisterFactory<ButtonDevice>("sdl");
498 UnregisterFactory<AnalogDevice>("sdl");
499
500 CloseJoysticks();
501 SDL_DelEventWatch(&SDLEventWatcher, this);
502
503 initialized = false;
504 if (start_thread) {
505 poll_thread.join();
506 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
507 }
508}
509
510Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Event& event) {
511 Common::ParamPackage params({{"engine", "sdl"}});
512
513 switch (event.type) {
514 case SDL_JOYAXISMOTION: {
515 auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which);
516 params.Set("port", joystick->GetPort());
517 params.Set("guid", joystick->GetGUID());
518 params.Set("axis", event.jaxis.axis);
519 if (event.jaxis.value > 0) {
520 params.Set("direction", "+");
521 params.Set("threshold", "0.5");
522 } else {
523 params.Set("direction", "-");
524 params.Set("threshold", "-0.5");
525 }
526 break;
527 }
528 case SDL_JOYBUTTONUP: {
529 auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which);
530 params.Set("port", joystick->GetPort());
531 params.Set("guid", joystick->GetGUID());
532 params.Set("button", event.jbutton.button);
533 break;
534 }
535 case SDL_JOYHATMOTION: {
536 auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which);
537 params.Set("port", joystick->GetPort());
538 params.Set("guid", joystick->GetGUID());
539 params.Set("hat", event.jhat.hat);
540 switch (event.jhat.value) {
541 case SDL_HAT_UP:
542 params.Set("direction", "up");
543 break;
544 case SDL_HAT_DOWN:
545 params.Set("direction", "down");
546 break;
547 case SDL_HAT_LEFT:
548 params.Set("direction", "left");
549 break;
550 case SDL_HAT_RIGHT:
551 params.Set("direction", "right");
552 break;
553 default:
554 return {};
555 }
556 break;
557 }
558 }
559 return params;
560}
561
562namespace Polling {
563
564class SDLPoller : public InputCommon::Polling::DevicePoller {
565public:
566 explicit SDLPoller(SDLState& state_) : state(state_) {}
567
568 void Start() override {
569 state.event_queue.Clear();
570 state.polling = true;
571 }
572
573 void Stop() override {
574 state.polling = false;
575 }
576
577protected:
578 SDLState& state;
579};
580
581class SDLButtonPoller final : public SDLPoller {
582public:
583 explicit SDLButtonPoller(SDLState& state_) : SDLPoller(state_) {}
584
585 Common::ParamPackage GetNextInput() override {
586 SDL_Event event;
587 while (state.event_queue.Pop(event)) {
588 switch (event.type) {
589 case SDL_JOYAXISMOTION:
590 if (std::abs(event.jaxis.value / 32767.0) < 0.5) {
591 break;
592 }
593 case SDL_JOYBUTTONUP:
594 case SDL_JOYHATMOTION:
595 return SDLEventToButtonParamPackage(state, event);
596 }
597 }
598 return {};
599 }
600};
601
602class SDLAnalogPoller final : public SDLPoller {
603public:
604 explicit SDLAnalogPoller(SDLState& state_) : SDLPoller(state_) {}
605
606 void Start() override {
607 SDLPoller::Start();
608
609 // Reset stored axes
610 analog_xaxis = -1;
611 analog_yaxis = -1;
612 analog_axes_joystick = -1;
613 }
614
615 Common::ParamPackage GetNextInput() override {
616 SDL_Event event;
617 while (state.event_queue.Pop(event)) {
618 if (event.type != SDL_JOYAXISMOTION || std::abs(event.jaxis.value / 32767.0) < 0.5) {
619 continue;
620 }
621 // An analog device needs two axes, so we need to store the axis for later and wait for
622 // a second SDL event. The axes also must be from the same joystick.
623 int axis = event.jaxis.axis;
624 if (analog_xaxis == -1) {
625 analog_xaxis = axis;
626 analog_axes_joystick = event.jaxis.which;
627 } else if (analog_yaxis == -1 && analog_xaxis != axis &&
628 analog_axes_joystick == event.jaxis.which) {
629 analog_yaxis = axis;
630 }
631 }
632 Common::ParamPackage params;
633 if (analog_xaxis != -1 && analog_yaxis != -1) {
634 auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which);
635 params.Set("engine", "sdl");
636 params.Set("port", joystick->GetPort());
637 params.Set("guid", joystick->GetGUID());
638 params.Set("axis_x", analog_xaxis);
639 params.Set("axis_y", analog_yaxis);
640 analog_xaxis = -1;
641 analog_yaxis = -1;
642 analog_axes_joystick = -1;
643 return params;
644 }
645 return params;
646 }
647
648private:
649 int analog_xaxis = -1;
650 int analog_yaxis = -1;
651 SDL_JoystickID analog_axes_joystick = -1;
652};
653} // namespace Polling
654
655SDLState::Pollers SDLState::GetPollers(InputCommon::Polling::DeviceType type) {
656 Pollers pollers;
657
658 switch (type) {
659 case InputCommon::Polling::DeviceType::Analog:
660 pollers.emplace_back(std::make_unique<Polling::SDLAnalogPoller>(*this));
661 break;
662 case InputCommon::Polling::DeviceType::Button:
663 pollers.emplace_back(std::make_unique<Polling::SDLButtonPoller>(*this));
664 break;
665 }
666
667 return pollers;
668}
669
670} // namespace SDL
671} // namespace InputCommon