summaryrefslogtreecommitdiff
path: root/src/input_common/input_poller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/input_poller.cpp')
-rw-r--r--src/input_common/input_poller.cpp89
1 files changed, 47 insertions, 42 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 2b3b77938..01c435802 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -18,7 +18,7 @@ public:
18 18
19class InputFromButton final : public Common::Input::InputDevice { 19class InputFromButton final : public Common::Input::InputDevice {
20public: 20public:
21 explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, 21 explicit InputFromButton(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_,
22 InputEngine* input_engine_) 22 InputEngine* input_engine_)
23 : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), 23 : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_),
24 input_engine(input_engine_) { 24 input_engine(input_engine_) {
@@ -69,7 +69,7 @@ public:
69 69
70private: 70private:
71 const PadIdentifier identifier; 71 const PadIdentifier identifier;
72 const u32 button; 72 const int button;
73 const bool toggle; 73 const bool toggle;
74 const bool inverted; 74 const bool inverted;
75 int callback_key; 75 int callback_key;
@@ -79,7 +79,7 @@ private:
79 79
80class InputFromHatButton final : public Common::Input::InputDevice { 80class InputFromHatButton final : public Common::Input::InputDevice {
81public: 81public:
82 explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, 82 explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool toggle_,
83 bool inverted_, InputEngine* input_engine_) 83 bool inverted_, InputEngine* input_engine_)
84 : identifier(identifier_), button(button_), direction(direction_), toggle(toggle_), 84 : identifier(identifier_), button(button_), direction(direction_), toggle(toggle_),
85 inverted(inverted_), input_engine(input_engine_) { 85 inverted(inverted_), input_engine(input_engine_) {
@@ -130,7 +130,7 @@ public:
130 130
131private: 131private:
132 const PadIdentifier identifier; 132 const PadIdentifier identifier;
133 const u32 button; 133 const int button;
134 const u8 direction; 134 const u8 direction;
135 const bool toggle; 135 const bool toggle;
136 const bool inverted; 136 const bool inverted;
@@ -141,7 +141,7 @@ private:
141 141
142class InputFromStick final : public Common::Input::InputDevice { 142class InputFromStick final : public Common::Input::InputDevice {
143public: 143public:
144 explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, 144 explicit InputFromStick(PadIdentifier identifier_, int axis_x_, int axis_y_,
145 Common::Input::AnalogProperties properties_x_, 145 Common::Input::AnalogProperties properties_x_,
146 Common::Input::AnalogProperties properties_y_, 146 Common::Input::AnalogProperties properties_y_,
147 InputEngine* input_engine_) 147 InputEngine* input_engine_)
@@ -211,8 +211,8 @@ public:
211 211
212private: 212private:
213 const PadIdentifier identifier; 213 const PadIdentifier identifier;
214 const u32 axis_x; 214 const int axis_x;
215 const u32 axis_y; 215 const int axis_y;
216 const Common::Input::AnalogProperties properties_x; 216 const Common::Input::AnalogProperties properties_x;
217 const Common::Input::AnalogProperties properties_y; 217 const Common::Input::AnalogProperties properties_y;
218 int callback_key_x; 218 int callback_key_x;
@@ -224,8 +224,8 @@ private:
224 224
225class InputFromTouch final : public Common::Input::InputDevice { 225class InputFromTouch final : public Common::Input::InputDevice {
226public: 226public:
227 explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, 227 explicit InputFromTouch(PadIdentifier identifier_, int touch_id_, int button_, bool toggle_,
228 bool inverted_, u32 axis_x_, u32 axis_y_, 228 bool inverted_, int axis_x_, int axis_y_,
229 Common::Input::AnalogProperties properties_x_, 229 Common::Input::AnalogProperties properties_x_,
230 Common::Input::AnalogProperties properties_y_, 230 Common::Input::AnalogProperties properties_y_,
231 InputEngine* input_engine_) 231 InputEngine* input_engine_)
@@ -302,12 +302,12 @@ public:
302 302
303private: 303private:
304 const PadIdentifier identifier; 304 const PadIdentifier identifier;
305 const u32 touch_id; 305 const int touch_id;
306 const u32 button; 306 const int button;
307 const bool toggle; 307 const bool toggle;
308 const bool inverted; 308 const bool inverted;
309 const u32 axis_x; 309 const int axis_x;
310 const u32 axis_y; 310 const int axis_y;
311 const Common::Input::AnalogProperties properties_x; 311 const Common::Input::AnalogProperties properties_x;
312 const Common::Input::AnalogProperties properties_y; 312 const Common::Input::AnalogProperties properties_y;
313 int callback_key_button; 313 int callback_key_button;
@@ -321,8 +321,8 @@ private:
321 321
322class InputFromTrigger final : public Common::Input::InputDevice { 322class InputFromTrigger final : public Common::Input::InputDevice {
323public: 323public:
324 explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, 324 explicit InputFromTrigger(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_,
325 u32 axis_, Common::Input::AnalogProperties properties_, 325 int axis_, Common::Input::AnalogProperties properties_,
326 InputEngine* input_engine_) 326 InputEngine* input_engine_)
327 : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), 327 : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_),
328 axis(axis_), properties(properties_), input_engine(input_engine_) { 328 axis(axis_), properties(properties_), input_engine(input_engine_) {
@@ -355,9 +355,14 @@ public:
355 .raw_value = input_engine->GetAxis(identifier, axis), 355 .raw_value = input_engine->GetAxis(identifier, axis),
356 .properties = properties, 356 .properties = properties,
357 }; 357 };
358 const Common::Input::ButtonStatus button_status{
359 .value = input_engine->GetButton(identifier, button),
360 .inverted = inverted,
361 .toggle = toggle,
362 };
358 return { 363 return {
359 .analog = analog_status, 364 .analog = analog_status,
360 .pressed = input_engine->GetButton(identifier, button), 365 .pressed = button_status,
361 }; 366 };
362 } 367 }
363 368
@@ -368,19 +373,19 @@ public:
368 }; 373 };
369 374
370 if (status.trigger_status.analog.raw_value != last_axis_value || 375 if (status.trigger_status.analog.raw_value != last_axis_value ||
371 status.trigger_status.pressed != last_button_value) { 376 status.trigger_status.pressed.value != last_button_value) {
372 last_axis_value = status.trigger_status.analog.raw_value; 377 last_axis_value = status.trigger_status.analog.raw_value;
373 last_button_value = status.trigger_status.pressed; 378 last_button_value = status.trigger_status.pressed.value;
374 TriggerOnChange(status); 379 TriggerOnChange(status);
375 } 380 }
376 } 381 }
377 382
378private: 383private:
379 const PadIdentifier identifier; 384 const PadIdentifier identifier;
380 const u32 button; 385 const int button;
381 const bool toggle; 386 const bool toggle;
382 const bool inverted; 387 const bool inverted;
383 const u32 axis; 388 const int axis;
384 const Common::Input::AnalogProperties properties; 389 const Common::Input::AnalogProperties properties;
385 int callback_key_button; 390 int callback_key_button;
386 int axis_callback_key; 391 int axis_callback_key;
@@ -391,7 +396,7 @@ private:
391 396
392class InputFromAnalog final : public Common::Input::InputDevice { 397class InputFromAnalog final : public Common::Input::InputDevice {
393public: 398public:
394 explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, 399 explicit InputFromAnalog(PadIdentifier identifier_, int axis_,
395 Common::Input::AnalogProperties properties_, 400 Common::Input::AnalogProperties properties_,
396 InputEngine* input_engine_) 401 InputEngine* input_engine_)
397 : identifier(identifier_), axis(axis_), properties(properties_), 402 : identifier(identifier_), axis(axis_), properties(properties_),
@@ -432,7 +437,7 @@ public:
432 437
433private: 438private:
434 const PadIdentifier identifier; 439 const PadIdentifier identifier;
435 const u32 axis; 440 const int axis;
436 const Common::Input::AnalogProperties properties; 441 const Common::Input::AnalogProperties properties;
437 int callback_key; 442 int callback_key;
438 float last_axis_value; 443 float last_axis_value;
@@ -493,7 +498,7 @@ private:
493 498
494class InputFromMotion final : public Common::Input::InputDevice { 499class InputFromMotion final : public Common::Input::InputDevice {
495public: 500public:
496 explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, 501 explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_,
497 InputEngine* input_engine_) 502 InputEngine* input_engine_)
498 : identifier(identifier_), motion_sensor(motion_sensor_), input_engine(input_engine_) { 503 : identifier(identifier_), motion_sensor(motion_sensor_), input_engine(input_engine_) {
499 UpdateCallback engine_callback{[this]() { OnChange(); }}; 504 UpdateCallback engine_callback{[this]() { OnChange(); }};
@@ -539,14 +544,14 @@ public:
539 544
540private: 545private:
541 const PadIdentifier identifier; 546 const PadIdentifier identifier;
542 const u32 motion_sensor; 547 const int motion_sensor;
543 int callback_key; 548 int callback_key;
544 InputEngine* input_engine; 549 InputEngine* input_engine;
545}; 550};
546 551
547class InputFromAxisMotion final : public Common::Input::InputDevice { 552class InputFromAxisMotion final : public Common::Input::InputDevice {
548public: 553public:
549 explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, 554 explicit InputFromAxisMotion(PadIdentifier identifier_, int axis_x_, int axis_y_, int axis_z_,
550 Common::Input::AnalogProperties properties_x_, 555 Common::Input::AnalogProperties properties_x_,
551 Common::Input::AnalogProperties properties_y_, 556 Common::Input::AnalogProperties properties_y_,
552 Common::Input::AnalogProperties properties_z_, 557 Common::Input::AnalogProperties properties_z_,
@@ -634,9 +639,9 @@ public:
634 639
635private: 640private:
636 const PadIdentifier identifier; 641 const PadIdentifier identifier;
637 const u32 axis_x; 642 const int axis_x;
638 const u32 axis_y; 643 const int axis_y;
639 const u32 axis_z; 644 const int axis_z;
640 const Common::Input::AnalogProperties properties_x; 645 const Common::Input::AnalogProperties properties_x;
641 const Common::Input::AnalogProperties properties_y; 646 const Common::Input::AnalogProperties properties_y;
642 const Common::Input::AnalogProperties properties_z; 647 const Common::Input::AnalogProperties properties_z;
@@ -680,8 +685,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice(
680 .pad = static_cast<std::size_t>(params.Get("pad", 0)), 685 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
681 }; 686 };
682 687
683 const auto button_id = static_cast<u32>(params.Get("button", 0)); 688 const auto button_id = params.Get("button", 0);
684 const auto keyboard_key = static_cast<u32>(params.Get("code", 0)); 689 const auto keyboard_key = params.Get("code", 0);
685 const auto toggle = params.Get("toggle", false); 690 const auto toggle = params.Get("toggle", false);
686 const auto inverted = params.Get("inverted", false); 691 const auto inverted = params.Get("inverted", false);
687 input_engine->PreSetController(identifier); 692 input_engine->PreSetController(identifier);
@@ -703,7 +708,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice(
703 .pad = static_cast<std::size_t>(params.Get("pad", 0)), 708 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
704 }; 709 };
705 710
706 const auto button_id = static_cast<u32>(params.Get("hat", 0)); 711 const auto button_id = params.Get("hat", 0);
707 const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); 712 const auto direction = input_engine->GetHatButtonId(params.Get("direction", ""));
708 const auto toggle = params.Get("toggle", false); 713 const auto toggle = params.Get("toggle", false);
709 const auto inverted = params.Get("inverted", false); 714 const auto inverted = params.Get("inverted", false);
@@ -725,7 +730,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice(
725 .pad = static_cast<std::size_t>(params.Get("pad", 0)), 730 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
726 }; 731 };
727 732
728 const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); 733 const auto axis_x = params.Get("axis_x", 0);
729 const Common::Input::AnalogProperties properties_x = { 734 const Common::Input::AnalogProperties properties_x = {
730 .deadzone = deadzone, 735 .deadzone = deadzone,
731 .range = range, 736 .range = range,
@@ -734,7 +739,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice(
734 .inverted = params.Get("invert_x", "+") == "-", 739 .inverted = params.Get("invert_x", "+") == "-",
735 }; 740 };
736 741
737 const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); 742 const auto axis_y = params.Get("axis_y", 1);
738 const Common::Input::AnalogProperties properties_y = { 743 const Common::Input::AnalogProperties properties_y = {
739 .deadzone = deadzone, 744 .deadzone = deadzone,
740 .range = range, 745 .range = range,
@@ -757,7 +762,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice(
757 .pad = static_cast<std::size_t>(params.Get("pad", 0)), 762 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
758 }; 763 };
759 764
760 const auto axis = static_cast<u32>(params.Get("axis", 0)); 765 const auto axis = params.Get("axis", 0);
761 const Common::Input::AnalogProperties properties = { 766 const Common::Input::AnalogProperties properties = {
762 .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), 767 .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f),
763 .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), 768 .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f),
@@ -778,11 +783,11 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTriggerDevice(
778 .pad = static_cast<std::size_t>(params.Get("pad", 0)), 783 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
779 }; 784 };
780 785
781 const auto button = static_cast<u32>(params.Get("button", 0)); 786 const auto button = params.Get("button", 0);
782 const auto toggle = params.Get("toggle", false); 787 const auto toggle = params.Get("toggle", false);
783 const auto inverted = params.Get("inverted", false); 788 const auto inverted = params.Get("inverted", false);
784 789
785 const auto axis = static_cast<u32>(params.Get("axis", 0)); 790 const auto axis = params.Get("axis", 0);
786 const Common::Input::AnalogProperties properties = { 791 const Common::Input::AnalogProperties properties = {
787 .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), 792 .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f),
788 .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), 793 .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f),
@@ -809,11 +814,11 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice(
809 .pad = static_cast<std::size_t>(params.Get("pad", 0)), 814 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
810 }; 815 };
811 816
812 const auto button = static_cast<u32>(params.Get("button", 0)); 817 const auto button = params.Get("button", 0);
813 const auto toggle = params.Get("toggle", false); 818 const auto toggle = params.Get("toggle", false);
814 const auto inverted = params.Get("inverted", false); 819 const auto inverted = params.Get("inverted", false);
815 820
816 const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); 821 const auto axis_x = params.Get("axis_x", 0);
817 const Common::Input::AnalogProperties properties_x = { 822 const Common::Input::AnalogProperties properties_x = {
818 .deadzone = deadzone, 823 .deadzone = deadzone,
819 .range = range, 824 .range = range,
@@ -822,7 +827,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice(
822 .inverted = params.Get("invert_x", "+") == "-", 827 .inverted = params.Get("invert_x", "+") == "-",
823 }; 828 };
824 829
825 const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); 830 const auto axis_y = params.Get("axis_y", 1);
826 const Common::Input::AnalogProperties properties_y = { 831 const Common::Input::AnalogProperties properties_y = {
827 .deadzone = deadzone, 832 .deadzone = deadzone,
828 .range = range, 833 .range = range,
@@ -869,7 +874,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
869 const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); 874 const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f);
870 const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); 875 const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f);
871 876
872 const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); 877 const auto axis_x = params.Get("axis_x", 0);
873 const Common::Input::AnalogProperties properties_x = { 878 const Common::Input::AnalogProperties properties_x = {
874 .deadzone = deadzone, 879 .deadzone = deadzone,
875 .range = range, 880 .range = range,
@@ -878,7 +883,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
878 .inverted = params.Get("invert_x", "+") == "-", 883 .inverted = params.Get("invert_x", "+") == "-",
879 }; 884 };
880 885
881 const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); 886 const auto axis_y = params.Get("axis_y", 1);
882 const Common::Input::AnalogProperties properties_y = { 887 const Common::Input::AnalogProperties properties_y = {
883 .deadzone = deadzone, 888 .deadzone = deadzone,
884 .range = range, 889 .range = range,
@@ -887,7 +892,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
887 .inverted = params.Get("invert_y", "+") != "+", 892 .inverted = params.Get("invert_y", "+") != "+",
888 }; 893 };
889 894
890 const auto axis_z = static_cast<u32>(params.Get("axis_z", 1)); 895 const auto axis_z = params.Get("axis_z", 1);
891 const Common::Input::AnalogProperties properties_z = { 896 const Common::Input::AnalogProperties properties_z = {
892 .deadzone = deadzone, 897 .deadzone = deadzone,
893 .range = range, 898 .range = range,