summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/drivers/gc_adapter.cpp6
-rw-r--r--src/input_common/drivers/gc_adapter.h8
-rw-r--r--src/input_common/drivers/keyboard.cpp2
-rw-r--r--src/input_common/drivers/keyboard.h4
-rw-r--r--src/input_common/drivers/mouse.cpp2
-rw-r--r--src/input_common/drivers/mouse.h4
-rw-r--r--src/input_common/drivers/sdl_driver.cpp19
-rw-r--r--src/input_common/drivers/sdl_driver.h14
-rw-r--r--src/input_common/drivers/tas_input.cpp95
-rw-r--r--src/input_common/drivers/tas_input.h65
-rw-r--r--src/input_common/drivers/touch_screen.cpp2
-rw-r--r--src/input_common/drivers/touch_screen.h4
-rw-r--r--src/input_common/drivers/udp_client.cpp2
-rw-r--r--src/input_common/drivers/udp_client.h6
-rw-r--r--src/input_common/helpers/stick_from_buttons.cpp75
-rw-r--r--src/input_common/helpers/touch_from_buttons.cpp11
-rw-r--r--src/input_common/input_engine.cpp86
-rw-r--r--src/input_common/input_engine.h53
-rw-r--r--src/input_common/input_mapping.h28
-rw-r--r--src/input_common/input_poller.cpp39
-rw-r--r--src/input_common/input_poller.h212
21 files changed, 381 insertions, 356 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 8b6574223..7ab4540a8 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -69,7 +69,7 @@ private:
69 libusb_device_handle* handle{}; 69 libusb_device_handle* handle{};
70}; 70};
71 71
72GCAdapter::GCAdapter(const std::string& input_engine_) : InputEngine(input_engine_) { 72GCAdapter::GCAdapter(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
73 if (usb_adapter_handle) { 73 if (usb_adapter_handle) {
74 return; 74 return;
75 } 75 }
@@ -325,8 +325,8 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
325 return true; 325 return true;
326} 326}
327 327
328Common::Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, 328Common::Input::VibrationError GCAdapter::SetRumble(
329 const Common::Input::VibrationStatus vibration) { 329 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) {
330 const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f; 330 const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
331 const auto processed_amplitude = 331 const auto processed_amplitude =
332 static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); 332 static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index 8dc51d2e5..7ce1912a3 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -22,13 +22,13 @@ namespace InputCommon {
22class LibUSBContext; 22class LibUSBContext;
23class LibUSBDeviceHandle; 23class LibUSBDeviceHandle;
24 24
25class GCAdapter : public InputCommon::InputEngine { 25class GCAdapter : public InputEngine {
26public: 26public:
27 explicit GCAdapter(const std::string& input_engine_); 27 explicit GCAdapter(std::string input_engine_);
28 ~GCAdapter(); 28 ~GCAdapter() override;
29 29
30 Common::Input::VibrationError SetRumble( 30 Common::Input::VibrationError SetRumble(
31 const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override; 31 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
32 32
33 /// Used for automapping features 33 /// Used for automapping features
34 std::vector<Common::ParamPackage> GetInputDevices() const override; 34 std::vector<Common::ParamPackage> GetInputDevices() const override;
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp
index 23b0c0ccf..4c1e5bbec 100644
--- a/src/input_common/drivers/keyboard.cpp
+++ b/src/input_common/drivers/keyboard.cpp
@@ -24,7 +24,7 @@ constexpr PadIdentifier keyboard_modifier_identifier = {
24 .pad = 1, 24 .pad = 1,
25}; 25};
26 26
27Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { 27Keyboard::Keyboard(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
28 // Keyboard is broken into 3 diferent sets: 28 // Keyboard is broken into 3 diferent sets:
29 // key: Unfiltered intended for controllers. 29 // key: Unfiltered intended for controllers.
30 // keyboard_key: Allows only Settings::NativeKeyboard::Keys intended for keyboard emulation. 30 // keyboard_key: Allows only Settings::NativeKeyboard::Keys intended for keyboard emulation.
diff --git a/src/input_common/drivers/keyboard.h b/src/input_common/drivers/keyboard.h
index ad123b136..3856c882c 100644
--- a/src/input_common/drivers/keyboard.h
+++ b/src/input_common/drivers/keyboard.h
@@ -12,9 +12,9 @@ namespace InputCommon {
12 * A button device factory representing a keyboard. It receives keyboard events and forward them 12 * A button device factory representing a keyboard. It receives keyboard events and forward them
13 * to all button devices it created. 13 * to all button devices it created.
14 */ 14 */
15class Keyboard final : public InputCommon::InputEngine { 15class Keyboard final : public InputEngine {
16public: 16public:
17 explicit Keyboard(const std::string& input_engine_); 17 explicit Keyboard(std::string input_engine_);
18 18
19 /** 19 /**
20 * Sets the status of all buttons bound with the key to pressed 20 * Sets the status of all buttons bound with the key to pressed
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index 752118e97..aa69216c8 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -24,7 +24,7 @@ constexpr PadIdentifier identifier = {
24 .pad = 0, 24 .pad = 0,
25}; 25};
26 26
27Mouse::Mouse(const std::string& input_engine_) : InputEngine(input_engine_) { 27Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
28 PreSetController(identifier); 28 PreSetController(identifier);
29 PreSetAxis(identifier, mouse_axis_x); 29 PreSetAxis(identifier, mouse_axis_x);
30 PreSetAxis(identifier, mouse_axis_y); 30 PreSetAxis(identifier, mouse_axis_y);
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h
index 4a1fd2fd9..040446178 100644
--- a/src/input_common/drivers/mouse.h
+++ b/src/input_common/drivers/mouse.h
@@ -27,9 +27,9 @@ enum class MouseButton {
27 * A button device factory representing a keyboard. It receives keyboard events and forward them 27 * A button device factory representing a keyboard. It receives keyboard events and forward them
28 * to all button devices it created. 28 * to all button devices it created.
29 */ 29 */
30class Mouse final : public InputCommon::InputEngine { 30class Mouse final : public InputEngine {
31public: 31public:
32 explicit Mouse(const std::string& input_engine_); 32 explicit Mouse(std::string input_engine_);
33 33
34 /** 34 /**
35 * Signals that mouse has moved. 35 * Signals that mouse has moved.
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index 1052ed394..0cda9df62 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -88,7 +88,7 @@ public:
88 return true; 88 return true;
89 } 89 }
90 90
91 BasicMotion GetMotion() { 91 const BasicMotion& GetMotion() const {
92 return motion; 92 return motion;
93 } 93 }
94 94
@@ -367,7 +367,7 @@ void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) {
367 if (joystick->UpdateMotion(event.csensor)) { 367 if (joystick->UpdateMotion(event.csensor)) {
368 const PadIdentifier identifier = joystick->GetPadIdentifier(); 368 const PadIdentifier identifier = joystick->GetPadIdentifier();
369 SetMotion(identifier, 0, joystick->GetMotion()); 369 SetMotion(identifier, 0, joystick->GetMotion());
370 }; 370 }
371 } 371 }
372 break; 372 break;
373 } 373 }
@@ -387,7 +387,7 @@ void SDLDriver::CloseJoysticks() {
387 joystick_map.clear(); 387 joystick_map.clear();
388} 388}
389 389
390SDLDriver::SDLDriver(const std::string& input_engine_) : InputEngine(input_engine_) { 390SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
391 if (!Settings::values.enable_raw_input) { 391 if (!Settings::values.enable_raw_input) {
392 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens 392 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens
393 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); 393 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
@@ -403,10 +403,11 @@ SDLDriver::SDLDriver(const std::string& input_engine_) : InputEngine(input_engin
403 403
404 // Use hidapi driver for joycons. This will allow joycons to be detected as a GameController and 404 // Use hidapi driver for joycons. This will allow joycons to be detected as a GameController and
405 // not a generic one 405 // not a generic one
406 SDL_SetHint("SDL_JOYSTICK_HIDAPI_JOY_CONS", "1"); 406 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
407 407
408 // Turn off Pro controller home led 408 // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native
409 SDL_SetHint("SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED", "0"); 409 // driver on Linux.
410 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_XBOX, "0");
410 411
411 // If the frontend is going to manage the event loop, then we don't start one here 412 // If the frontend is going to manage the event loop, then we don't start one here
412 start_thread = SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0; 413 start_thread = SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0;
@@ -491,8 +492,9 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
491 } 492 }
492 return devices; 493 return devices;
493} 494}
494Common::Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier, 495
495 const Common::Input::VibrationStatus vibration) { 496Common::Input::VibrationError SDLDriver::SetRumble(
497 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) {
496 const auto joystick = 498 const auto joystick =
497 GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); 499 GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port));
498 const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { 500 const auto process_amplitude_exp = [](f32 amplitude, f32 factor) {
@@ -526,6 +528,7 @@ Common::Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifi
526 528
527 return Common::Input::VibrationError::None; 529 return Common::Input::VibrationError::None;
528} 530}
531
529Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid, 532Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
530 s32 axis, float value) const { 533 s32 axis, float value) const {
531 Common::ParamPackage params{}; 534 Common::ParamPackage params{};
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index d03ff4b84..e9a5d2e26 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -19,19 +19,19 @@ using SDL_GameController = struct _SDL_GameController;
19using SDL_Joystick = struct _SDL_Joystick; 19using SDL_Joystick = struct _SDL_Joystick;
20using SDL_JoystickID = s32; 20using SDL_JoystickID = s32;
21 21
22namespace InputCommon {
23
24class SDLJoystick;
25
22using ButtonBindings = 26using ButtonBindings =
23 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>; 27 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 17>;
24using ZButtonBindings = 28using ZButtonBindings =
25 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>; 29 std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>;
26 30
27namespace InputCommon { 31class SDLDriver : public InputEngine {
28
29class SDLJoystick;
30
31class SDLDriver : public InputCommon::InputEngine {
32public: 32public:
33 /// Initializes and registers SDL device factories 33 /// Initializes and registers SDL device factories
34 SDLDriver(const std::string& input_engine_); 34 explicit SDLDriver(std::string input_engine_);
35 35
36 /// Unregisters SDL device factories and shut them down. 36 /// Unregisters SDL device factories and shut them down.
37 ~SDLDriver() override; 37 ~SDLDriver() override;
@@ -59,7 +59,7 @@ public:
59 u8 GetHatButtonId(const std::string& direction_name) const override; 59 u8 GetHatButtonId(const std::string& direction_name) const override;
60 60
61 Common::Input::VibrationError SetRumble( 61 Common::Input::VibrationError SetRumble(
62 const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override; 62 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
63 63
64private: 64private:
65 void InitJoystick(int joystick_index); 65 void InitJoystick(int joystick_index);
diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cpp
index 0e01fb0d9..5bdd5dac3 100644
--- a/src/input_common/drivers/tas_input.cpp
+++ b/src/input_common/drivers/tas_input.cpp
@@ -3,7 +3,6 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cstring> 5#include <cstring>
6#include <regex>
7#include <fmt/format.h> 6#include <fmt/format.h>
8 7
9#include "common/fs/file.h" 8#include "common/fs/file.h"
@@ -15,7 +14,7 @@
15 14
16namespace InputCommon::TasInput { 15namespace InputCommon::TasInput {
17 16
18enum TasAxes : u8 { 17enum class Tas::TasAxis : u8 {
19 StickX, 18 StickX,
20 StickY, 19 StickY,
21 SubstickX, 20 SubstickX,
@@ -47,7 +46,7 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but
47 {"KEY_ZR", TasButton::TRIGGER_ZR}, 46 {"KEY_ZR", TasButton::TRIGGER_ZR},
48}; 47};
49 48
50Tas::Tas(const std::string& input_engine_) : InputCommon::InputEngine(input_engine_) { 49Tas::Tas(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
51 for (size_t player_index = 0; player_index < PLAYER_NUMBER; player_index++) { 50 for (size_t player_index = 0; player_index < PLAYER_NUMBER; player_index++) {
52 PadIdentifier identifier{ 51 PadIdentifier identifier{
53 .guid = Common::UUID{}, 52 .guid = Common::UUID{},
@@ -66,7 +65,7 @@ Tas::Tas(const std::string& input_engine_) : InputCommon::InputEngine(input_engi
66 65
67Tas::~Tas() { 66Tas::~Tas() {
68 Stop(); 67 Stop();
69}; 68}
70 69
71void Tas::LoadTasFiles() { 70void Tas::LoadTasFiles() {
72 script_length = 0; 71 script_length = 0;
@@ -79,43 +78,43 @@ void Tas::LoadTasFiles() {
79} 78}
80 79
81void Tas::LoadTasFile(size_t player_index, size_t file_index) { 80void Tas::LoadTasFile(size_t player_index, size_t file_index) {
82 if (!commands[player_index].empty()) { 81 commands[player_index].clear();
83 commands[player_index].clear(); 82
84 }
85 std::string file = Common::FS::ReadStringFromFile( 83 std::string file = Common::FS::ReadStringFromFile(
86 Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / 84 Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) /
87 fmt::format("script{}-{}.txt", file_index, player_index + 1), 85 fmt::format("script{}-{}.txt", file_index, player_index + 1),
88 Common::FS::FileType::BinaryFile); 86 Common::FS::FileType::BinaryFile);
89 std::stringstream command_line(file); 87 std::istringstream command_line(file);
90 std::string line; 88 std::string line;
91 int frame_no = 0; 89 int frame_no = 0;
92 while (std::getline(command_line, line, '\n')) { 90 while (std::getline(command_line, line, '\n')) {
93 if (line.empty()) { 91 if (line.empty()) {
94 continue; 92 continue;
95 } 93 }
96 std::smatch m;
97 94
98 std::stringstream linestream(line); 95 std::vector<std::string> seg_list;
99 std::string segment; 96 {
100 std::vector<std::string> seglist; 97 std::istringstream line_stream(line);
101 98 std::string segment;
102 while (std::getline(linestream, segment, ' ')) { 99 while (std::getline(line_stream, segment, ' ')) {
103 seglist.push_back(segment); 100 seg_list.push_back(std::move(segment));
101 }
104 } 102 }
105 103
106 if (seglist.size() < 4) { 104 if (seg_list.size() < 4) {
107 continue; 105 continue;
108 } 106 }
109 107
110 while (frame_no < std::stoi(seglist.at(0))) { 108 const auto num_frames = std::stoi(seg_list[0]);
111 commands[player_index].push_back({}); 109 while (frame_no < num_frames) {
110 commands[player_index].emplace_back();
112 frame_no++; 111 frame_no++;
113 } 112 }
114 113
115 TASCommand command = { 114 TASCommand command = {
116 .buttons = ReadCommandButtons(seglist.at(1)), 115 .buttons = ReadCommandButtons(seg_list[1]),
117 .l_axis = ReadCommandAxis(seglist.at(2)), 116 .l_axis = ReadCommandAxis(seg_list[2]),
118 .r_axis = ReadCommandAxis(seglist.at(3)), 117 .r_axis = ReadCommandAxis(seg_list[3]),
119 }; 118 };
120 commands[player_index].push_back(command); 119 commands[player_index].push_back(command);
121 frame_no++; 120 frame_no++;
@@ -123,16 +122,17 @@ void Tas::LoadTasFile(size_t player_index, size_t file_index) {
123 LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); 122 LOG_INFO(Input, "TAS file loaded! {} frames", frame_no);
124} 123}
125 124
126void Tas::WriteTasFile(std::u8string file_name) { 125void Tas::WriteTasFile(std::u8string_view file_name) {
127 std::string output_text; 126 std::string output_text;
128 for (size_t frame = 0; frame < record_commands.size(); frame++) { 127 for (size_t frame = 0; frame < record_commands.size(); frame++) {
129 const TASCommand& line = record_commands[frame]; 128 const TASCommand& line = record_commands[frame];
130 output_text += fmt::format("{} {} {} {}\n", frame, WriteCommandButtons(line.buttons), 129 output_text += fmt::format("{} {} {} {}\n", frame, WriteCommandButtons(line.buttons),
131 WriteCommandAxis(line.l_axis), WriteCommandAxis(line.r_axis)); 130 WriteCommandAxis(line.l_axis), WriteCommandAxis(line.r_axis));
132 } 131 }
133 const auto bytes_written = Common::FS::WriteStringToFile( 132
134 Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name, 133 const auto tas_file_name = Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name;
135 Common::FS::FileType::TextFile, output_text); 134 const auto bytes_written =
135 Common::FS::WriteStringToFile(tas_file_name, Common::FS::FileType::TextFile, output_text);
136 if (bytes_written == output_text.size()) { 136 if (bytes_written == output_text.size()) {
137 LOG_INFO(Input, "TAS file written to file!"); 137 LOG_INFO(Input, "TAS file written to file!");
138 } else { 138 } else {
@@ -205,10 +205,10 @@ void Tas::UpdateThread() {
205 const int button = static_cast<int>(i); 205 const int button = static_cast<int>(i);
206 SetButton(identifier, button, button_status); 206 SetButton(identifier, button, button_status);
207 } 207 }
208 SetAxis(identifier, TasAxes::StickX, command.l_axis.x); 208 SetTasAxis(identifier, TasAxis::StickX, command.l_axis.x);
209 SetAxis(identifier, TasAxes::StickY, command.l_axis.y); 209 SetTasAxis(identifier, TasAxis::StickY, command.l_axis.y);
210 SetAxis(identifier, TasAxes::SubstickX, command.r_axis.x); 210 SetTasAxis(identifier, TasAxis::SubstickX, command.r_axis.x);
211 SetAxis(identifier, TasAxes::SubstickY, command.r_axis.y); 211 SetTasAxis(identifier, TasAxis::SubstickY, command.r_axis.y);
212 } 212 }
213 } else { 213 } else {
214 is_running = Settings::values.tas_loop.GetValue(); 214 is_running = Settings::values.tas_loop.GetValue();
@@ -224,27 +224,28 @@ void Tas::ClearInput() {
224} 224}
225 225
226TasAnalog Tas::ReadCommandAxis(const std::string& line) const { 226TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
227 std::stringstream linestream(line); 227 std::vector<std::string> seg_list;
228 std::string segment; 228 {
229 std::vector<std::string> seglist; 229 std::istringstream line_stream(line);
230 230 std::string segment;
231 while (std::getline(linestream, segment, ';')) { 231 while (std::getline(line_stream, segment, ';')) {
232 seglist.push_back(segment); 232 seg_list.push_back(std::move(segment));
233 }
233 } 234 }
234 235
235 const float x = std::stof(seglist.at(0)) / 32767.0f; 236 const float x = std::stof(seg_list.at(0)) / 32767.0f;
236 const float y = std::stof(seglist.at(1)) / 32767.0f; 237 const float y = std::stof(seg_list.at(1)) / 32767.0f;
237 238
238 return {x, y}; 239 return {x, y};
239} 240}
240 241
241u64 Tas::ReadCommandButtons(const std::string& data) const { 242u64 Tas::ReadCommandButtons(const std::string& line) const {
242 std::stringstream button_text(data); 243 std::istringstream button_text(line);
243 std::string line; 244 std::string button_line;
244 u64 buttons = 0; 245 u64 buttons = 0;
245 while (std::getline(button_text, line, ';')) { 246 while (std::getline(button_text, button_line, ';')) {
246 for (auto [text, tas_button] : text_to_tas_button) { 247 for (const auto& [text, tas_button] : text_to_tas_button) {
247 if (text == line) { 248 if (text == button_line) {
248 buttons |= static_cast<u64>(tas_button); 249 buttons |= static_cast<u64>(tas_button);
249 break; 250 break;
250 } 251 }
@@ -254,8 +255,8 @@ u64 Tas::ReadCommandButtons(const std::string& data) const {
254} 255}
255 256
256std::string Tas::WriteCommandButtons(u64 buttons) const { 257std::string Tas::WriteCommandButtons(u64 buttons) const {
257 std::string returns = ""; 258 std::string returns;
258 for (auto [text_button, tas_button] : text_to_tas_button) { 259 for (const auto& [text_button, tas_button] : text_to_tas_button) {
259 if ((buttons & static_cast<u64>(tas_button)) != 0) { 260 if ((buttons & static_cast<u64>(tas_button)) != 0) {
260 returns += fmt::format("{};", text_button); 261 returns += fmt::format("{};", text_button);
261 } 262 }
@@ -267,6 +268,10 @@ std::string Tas::WriteCommandAxis(TasAnalog analog) const {
267 return fmt::format("{};{}", analog.x * 32767, analog.y * 32767); 268 return fmt::format("{};{}", analog.x * 32767, analog.y * 32767);
268} 269}
269 270
271void Tas::SetTasAxis(const PadIdentifier& identifier, TasAxis axis, f32 value) {
272 SetAxis(identifier, static_cast<int>(axis), value);
273}
274
270void Tas::StartStop() { 275void Tas::StartStop() {
271 if (!Settings::values.tas_enable) { 276 if (!Settings::values.tas_enable) {
272 return; 277 return;
diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.h
index c95a130fc..4b4e6c417 100644
--- a/src/input_common/drivers/tas_input.h
+++ b/src/input_common/drivers/tas_input.h
@@ -5,11 +5,11 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <string>
9#include <vector>
8 10
9#include "common/common_types.h" 11#include "common/common_types.h"
10#include "common/settings_input.h"
11#include "input_common/input_engine.h" 12#include "input_common/input_engine.h"
12#include "input_common/main.h"
13 13
14/* 14/*
15To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below 15To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below
@@ -81,46 +81,46 @@ enum class TasState {
81 Stopped, 81 Stopped,
82}; 82};
83 83
84class Tas final : public InputCommon::InputEngine { 84class Tas final : public InputEngine {
85public: 85public:
86 explicit Tas(const std::string& input_engine_); 86 explicit Tas(std::string input_engine_);
87 ~Tas(); 87 ~Tas() override;
88 88
89 /** 89 /**
90 * Changes the input status that will be stored in each frame 90 * Changes the input status that will be stored in each frame
91 * @param buttons: bitfield with the status of the buttons 91 * @param buttons Bitfield with the status of the buttons
92 * @param left_axis: value of the left axis 92 * @param left_axis Value of the left axis
93 * @param right_axis: value of the right axis 93 * @param right_axis Value of the right axis
94 */ 94 */
95 void RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis); 95 void RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis);
96 96
97 // Main loop that records or executes input 97 // Main loop that records or executes input
98 void UpdateThread(); 98 void UpdateThread();
99 99
100 // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles 100 // Sets the flag to start or stop the TAS command execution and swaps controllers profiles
101 void StartStop(); 101 void StartStop();
102 102
103 // Stop the TAS and reverts any controller profile 103 // Stop the TAS and reverts any controller profile
104 void Stop(); 104 void Stop();
105 105
106 // Sets the flag to reload the file and start from the begining in the next update 106 // Sets the flag to reload the file and start from the beginning in the next update
107 void Reset(); 107 void Reset();
108 108
109 /** 109 /**
110 * Sets the flag to enable or disable recording of inputs 110 * Sets the flag to enable or disable recording of inputs
111 * @return Returns true if the current recording status is enabled 111 * @returns true if the current recording status is enabled
112 */ 112 */
113 bool Record(); 113 bool Record();
114 114
115 /** 115 /**
116 * Saves contents of record_commands on a file 116 * Saves contents of record_commands on a file
117 * @param overwrite_file: Indicates if player 1 should be overwritten 117 * @param overwrite_file Indicates if player 1 should be overwritten
118 */ 118 */
119 void SaveRecording(bool overwrite_file); 119 void SaveRecording(bool overwrite_file);
120 120
121 /** 121 /**
122 * Returns the current status values of TAS playback/recording 122 * Returns the current status values of TAS playback/recording
123 * @return Tuple of 123 * @returns A Tuple of
124 * TasState indicating the current state out of Running ; 124 * TasState indicating the current state out of Running ;
125 * Current playback progress ; 125 * Current playback progress ;
126 * Total length of script file currently loaded or being recorded 126 * Total length of script file currently loaded or being recorded
@@ -128,6 +128,8 @@ public:
128 std::tuple<TasState, size_t, size_t> GetStatus() const; 128 std::tuple<TasState, size_t, size_t> GetStatus() const;
129 129
130private: 130private:
131 enum class TasAxis : u8;
132
131 struct TASCommand { 133 struct TASCommand {
132 u64 buttons{}; 134 u64 buttons{};
133 TasAnalog l_axis{}; 135 TasAnalog l_axis{};
@@ -137,29 +139,31 @@ private:
137 /// Loads TAS files from all players 139 /// Loads TAS files from all players
138 void LoadTasFiles(); 140 void LoadTasFiles();
139 141
140 /** Loads TAS file from the specified player 142 /**
141 * @param player_index: player number to save the script 143 * Loads TAS file from the specified player
142 * @param file_index: script number of the file 144 * @param player_index Player number to save the script
145 * @param file_index Script number of the file
143 */ 146 */
144 void LoadTasFile(size_t player_index, size_t file_index); 147 void LoadTasFile(size_t player_index, size_t file_index);
145 148
146 /** Writes a TAS file from the recorded commands 149 /**
147 * @param file_name: name of the file to be written 150 * Writes a TAS file from the recorded commands
151 * @param file_name Name of the file to be written
148 */ 152 */
149 void WriteTasFile(std::u8string file_name); 153 void WriteTasFile(std::u8string_view file_name);
150 154
151 /** 155 /**
152 * Parses a string containing the axis values. X and Y have a range from -32767 to 32767 156 * Parses a string containing the axis values. X and Y have a range from -32767 to 32767
153 * @param line: string containing axis values with the following format "x;y" 157 * @param line String containing axis values with the following format "x;y"
154 * @return Returns a TAS analog object with axis values with range from -1.0 to 1.0 158 * @returns A TAS analog object with axis values with range from -1.0 to 1.0
155 */ 159 */
156 TasAnalog ReadCommandAxis(const std::string& line) const; 160 TasAnalog ReadCommandAxis(const std::string& line) const;
157 161
158 /** 162 /**
159 * Parses a string containing the button values. Each button is represented by it's text format 163 * Parses a string containing the button values. Each button is represented by it's text format
160 * specified in text_to_tas_button array 164 * specified in text_to_tas_button array
161 * @param line: string containing button name with the following format "a;b;c;d..." 165 * @param line string containing button name with the following format "a;b;c;d..."
162 * @return Returns a u64 with each bit representing the status of a button 166 * @returns A u64 with each bit representing the status of a button
163 */ 167 */
164 u64 ReadCommandButtons(const std::string& line) const; 168 u64 ReadCommandButtons(const std::string& line) const;
165 169
@@ -170,17 +174,20 @@ private:
170 174
171 /** 175 /**
172 * Converts an u64 containing the button status into the text equivalent 176 * Converts an u64 containing the button status into the text equivalent
173 * @param buttons: bitfield with the status of the buttons 177 * @param buttons Bitfield with the status of the buttons
174 * @return Returns a string with the name of the buttons to be written to the file 178 * @returns A string with the name of the buttons to be written to the file
175 */ 179 */
176 std::string WriteCommandButtons(u64 buttons) const; 180 std::string WriteCommandButtons(u64 buttons) const;
177 181
178 /** 182 /**
179 * Converts an TAS analog object containing the axis status into the text equivalent 183 * Converts an TAS analog object containing the axis status into the text equivalent
180 * @param data: value of the axis 184 * @param analog Value of the axis
181 * @return A string with the value of the axis to be written to the file 185 * @returns A string with the value of the axis to be written to the file
182 */ 186 */
183 std::string WriteCommandAxis(TasAnalog data) const; 187 std::string WriteCommandAxis(TasAnalog analog) const;
188
189 /// Sets an axis for a particular pad to the given value.
190 void SetTasAxis(const PadIdentifier& identifier, TasAxis axis, f32 value);
184 191
185 size_t script_length{0}; 192 size_t script_length{0};
186 bool is_recording{false}; 193 bool is_recording{false};
diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cpp
index 45b3086f6..880781825 100644
--- a/src/input_common/drivers/touch_screen.cpp
+++ b/src/input_common/drivers/touch_screen.cpp
@@ -13,7 +13,7 @@ constexpr PadIdentifier identifier = {
13 .pad = 0, 13 .pad = 0,
14}; 14};
15 15
16TouchScreen::TouchScreen(const std::string& input_engine_) : InputEngine(input_engine_) { 16TouchScreen::TouchScreen(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
17 PreSetController(identifier); 17 PreSetController(identifier);
18} 18}
19 19
diff --git a/src/input_common/drivers/touch_screen.h b/src/input_common/drivers/touch_screen.h
index 25c11e8bf..bf395c40b 100644
--- a/src/input_common/drivers/touch_screen.h
+++ b/src/input_common/drivers/touch_screen.h
@@ -12,9 +12,9 @@ namespace InputCommon {
12 * A button device factory representing a keyboard. It receives keyboard events and forward them 12 * A button device factory representing a keyboard. It receives keyboard events and forward them
13 * to all button devices it created. 13 * to all button devices it created.
14 */ 14 */
15class TouchScreen final : public InputCommon::InputEngine { 15class TouchScreen final : public InputEngine {
16public: 16public:
17 explicit TouchScreen(const std::string& input_engine_); 17 explicit TouchScreen(std::string input_engine_);
18 18
19 /** 19 /**
20 * Signals that mouse has moved. 20 * Signals that mouse has moved.
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp
index fdee0f2d5..4ab991a7d 100644
--- a/src/input_common/drivers/udp_client.cpp
+++ b/src/input_common/drivers/udp_client.cpp
@@ -136,7 +136,7 @@ static void SocketLoop(Socket* socket) {
136 socket->Loop(); 136 socket->Loop();
137} 137}
138 138
139UDPClient::UDPClient(const std::string& input_engine_) : InputEngine(input_engine_) { 139UDPClient::UDPClient(std::string input_engine_) : InputEngine(std::move(input_engine_)) {
140 LOG_INFO(Input, "Udp Initialization started"); 140 LOG_INFO(Input, "Udp Initialization started");
141 ReloadSockets(); 141 ReloadSockets();
142} 142}
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h
index 5d483f26b..1adc947c4 100644
--- a/src/input_common/drivers/udp_client.h
+++ b/src/input_common/drivers/udp_client.h
@@ -49,10 +49,10 @@ struct DeviceStatus {
49 * A button device factory representing a keyboard. It receives keyboard events and forward them 49 * A button device factory representing a keyboard. It receives keyboard events and forward them
50 * to all button devices it created. 50 * to all button devices it created.
51 */ 51 */
52class UDPClient final : public InputCommon::InputEngine { 52class UDPClient final : public InputEngine {
53public: 53public:
54 explicit UDPClient(const std::string& input_engine_); 54 explicit UDPClient(std::string input_engine_);
55 ~UDPClient(); 55 ~UDPClient() override;
56 56
57 void ReloadSockets(); 57 void ReloadSockets();
58 58
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index 77fcd655e..e23394f5f 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -19,23 +19,36 @@ public:
19 : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), 19 : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
20 right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), 20 right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
21 modifier_angle(modifier_angle_) { 21 modifier_angle(modifier_angle_) {
22 Common::Input::InputCallback button_up_callback{ 22 up->SetCallback({
23 [this](Common::Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }}; 23 .on_change =
24 Common::Input::InputCallback button_down_callback{ 24 [this](const Common::Input::CallbackStatus& callback_) {
25 [this](Common::Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }}; 25 UpdateUpButtonStatus(callback_);
26 Common::Input::InputCallback button_left_callback{ 26 },
27 [this](Common::Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }}; 27 });
28 Common::Input::InputCallback button_right_callback{ 28 down->SetCallback({
29 [this](Common::Input::CallbackStatus callback_) { 29 .on_change =
30 UpdateRightButtonStatus(callback_); 30 [this](const Common::Input::CallbackStatus& callback_) {
31 }}; 31 UpdateDownButtonStatus(callback_);
32 Common::Input::InputCallback button_modifier_callback{ 32 },
33 [this](Common::Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }}; 33 });
34 up->SetCallback(button_up_callback); 34 left->SetCallback({
35 down->SetCallback(button_down_callback); 35 .on_change =
36 left->SetCallback(button_left_callback); 36 [this](const Common::Input::CallbackStatus& callback_) {
37 right->SetCallback(button_right_callback); 37 UpdateLeftButtonStatus(callback_);
38 modifier->SetCallback(button_modifier_callback); 38 },
39 });
40 right->SetCallback({
41 .on_change =
42 [this](const Common::Input::CallbackStatus& callback_) {
43 UpdateRightButtonStatus(callback_);
44 },
45 });
46 modifier->SetCallback({
47 .on_change =
48 [this](const Common::Input::CallbackStatus& callback_) {
49 UpdateModButtonStatus(callback_);
50 },
51 });
39 last_x_axis_value = 0.0f; 52 last_x_axis_value = 0.0f;
40 last_y_axis_value = 0.0f; 53 last_y_axis_value = 0.0f;
41 } 54 }
@@ -133,27 +146,27 @@ public:
133 } 146 }
134 } 147 }
135 148
136 void UpdateUpButtonStatus(Common::Input::CallbackStatus button_callback) { 149 void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) {
137 up_status = button_callback.button_status.value; 150 up_status = button_callback.button_status.value;
138 UpdateStatus(); 151 UpdateStatus();
139 } 152 }
140 153
141 void UpdateDownButtonStatus(Common::Input::CallbackStatus button_callback) { 154 void UpdateDownButtonStatus(const Common::Input::CallbackStatus& button_callback) {
142 down_status = button_callback.button_status.value; 155 down_status = button_callback.button_status.value;
143 UpdateStatus(); 156 UpdateStatus();
144 } 157 }
145 158
146 void UpdateLeftButtonStatus(Common::Input::CallbackStatus button_callback) { 159 void UpdateLeftButtonStatus(const Common::Input::CallbackStatus& button_callback) {
147 left_status = button_callback.button_status.value; 160 left_status = button_callback.button_status.value;
148 UpdateStatus(); 161 UpdateStatus();
149 } 162 }
150 163
151 void UpdateRightButtonStatus(Common::Input::CallbackStatus button_callback) { 164 void UpdateRightButtonStatus(const Common::Input::CallbackStatus& button_callback) {
152 right_status = button_callback.button_status.value; 165 right_status = button_callback.button_status.value;
153 UpdateStatus(); 166 UpdateStatus();
154 } 167 }
155 168
156 void UpdateModButtonStatus(Common::Input::CallbackStatus button_callback) { 169 void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) {
157 modifier_status = button_callback.button_status.value; 170 modifier_status = button_callback.button_status.value;
158 UpdateStatus(); 171 UpdateStatus();
159 } 172 }
@@ -265,18 +278,18 @@ private:
265 Button left; 278 Button left;
266 Button right; 279 Button right;
267 Button modifier; 280 Button modifier;
268 float modifier_scale; 281 float modifier_scale{};
269 float modifier_angle; 282 float modifier_angle{};
270 float angle{}; 283 float angle{};
271 float goal_angle{}; 284 float goal_angle{};
272 float amplitude{}; 285 float amplitude{};
273 bool up_status; 286 bool up_status{};
274 bool down_status; 287 bool down_status{};
275 bool left_status; 288 bool left_status{};
276 bool right_status; 289 bool right_status{};
277 bool modifier_status; 290 bool modifier_status{};
278 float last_x_axis_value; 291 float last_x_axis_value{};
279 float last_y_axis_value; 292 float last_y_axis_value{};
280 const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; 293 const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
281 std::chrono::time_point<std::chrono::steady_clock> last_update; 294 std::chrono::time_point<std::chrono::steady_clock> last_update;
282}; 295};
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp
index 35d60bc90..ece1e3b32 100644
--- a/src/input_common/helpers/touch_from_buttons.cpp
+++ b/src/input_common/helpers/touch_from_buttons.cpp
@@ -14,10 +14,13 @@ public:
14 using Button = std::unique_ptr<Common::Input::InputDevice>; 14 using Button = std::unique_ptr<Common::Input::InputDevice>;
15 TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_) 15 TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_)
16 : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { 16 : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) {
17 Common::Input::InputCallback button_up_callback{
18 [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }};
19 last_button_value = false; 17 last_button_value = false;
20 button->SetCallback(button_up_callback); 18 button->SetCallback({
19 .on_change =
20 [this](const Common::Input::CallbackStatus& callback_) {
21 UpdateButtonStatus(callback_);
22 },
23 });
21 button->ForceUpdate(); 24 button->ForceUpdate();
22 } 25 }
23 26
@@ -47,7 +50,7 @@ public:
47 return status; 50 return status;
48 } 51 }
49 52
50 void UpdateButtonStatus(Common::Input::CallbackStatus button_callback) { 53 void UpdateButtonStatus(const Common::Input::CallbackStatus& button_callback) {
51 const Common::Input::CallbackStatus status{ 54 const Common::Input::CallbackStatus status{
52 .type = Common::Input::InputType::Touch, 55 .type = Common::Input::InputType::Touch,
53 .touch_status = GetStatus(button_callback.button_status.value), 56 .touch_status = GetStatus(button_callback.button_status.value),
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp
index 2b2105376..9c17ca4f7 100644
--- a/src/input_common/input_engine.cpp
+++ b/src/input_common/input_engine.cpp
@@ -10,41 +10,31 @@ namespace InputCommon {
10 10
11void InputEngine::PreSetController(const PadIdentifier& identifier) { 11void InputEngine::PreSetController(const PadIdentifier& identifier) {
12 std::lock_guard lock{mutex}; 12 std::lock_guard lock{mutex};
13 if (!controller_list.contains(identifier)) { 13 controller_list.try_emplace(identifier);
14 controller_list.insert_or_assign(identifier, ControllerData{});
15 }
16} 14}
17 15
18void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) { 16void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) {
19 std::lock_guard lock{mutex}; 17 std::lock_guard lock{mutex};
20 ControllerData& controller = controller_list.at(identifier); 18 ControllerData& controller = controller_list.at(identifier);
21 if (!controller.buttons.contains(button)) { 19 controller.buttons.try_emplace(button, false);
22 controller.buttons.insert_or_assign(button, false);
23 }
24} 20}
25 21
26void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) { 22void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) {
27 std::lock_guard lock{mutex}; 23 std::lock_guard lock{mutex};
28 ControllerData& controller = controller_list.at(identifier); 24 ControllerData& controller = controller_list.at(identifier);
29 if (!controller.hat_buttons.contains(button)) { 25 controller.hat_buttons.try_emplace(button, u8{0});
30 controller.hat_buttons.insert_or_assign(button, u8{0});
31 }
32} 26}
33 27
34void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) { 28void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) {
35 std::lock_guard lock{mutex}; 29 std::lock_guard lock{mutex};
36 ControllerData& controller = controller_list.at(identifier); 30 ControllerData& controller = controller_list.at(identifier);
37 if (!controller.axes.contains(axis)) { 31 controller.axes.try_emplace(axis, 0.0f);
38 controller.axes.insert_or_assign(axis, 0.0f);
39 }
40} 32}
41 33
42void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) { 34void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) {
43 std::lock_guard lock{mutex}; 35 std::lock_guard lock{mutex};
44 ControllerData& controller = controller_list.at(identifier); 36 ControllerData& controller = controller_list.at(identifier);
45 if (!controller.motions.contains(motion)) { 37 controller.motions.try_emplace(motion);
46 controller.motions.insert_or_assign(motion, BasicMotion{});
47 }
48} 38}
49 39
50void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) { 40void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) {
@@ -91,7 +81,7 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, BatteryLevel value
91 TriggerOnBatteryChange(identifier, value); 81 TriggerOnBatteryChange(identifier, value);
92} 82}
93 83
94void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, BasicMotion value) { 84void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) {
95 { 85 {
96 std::lock_guard lock{mutex}; 86 std::lock_guard lock{mutex};
97 ControllerData& controller = controller_list.at(identifier); 87 ControllerData& controller = controller_list.at(identifier);
@@ -104,85 +94,93 @@ void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, BasicMo
104 94
105bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { 95bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const {
106 std::lock_guard lock{mutex}; 96 std::lock_guard lock{mutex};
107 if (!controller_list.contains(identifier)) { 97 const auto controller_iter = controller_list.find(identifier);
98 if (controller_iter == controller_list.cend()) {
108 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 99 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
109 identifier.pad, identifier.port); 100 identifier.pad, identifier.port);
110 return false; 101 return false;
111 } 102 }
112 ControllerData controller = controller_list.at(identifier); 103 const ControllerData& controller = controller_iter->second;
113 if (!controller.buttons.contains(button)) { 104 const auto button_iter = controller.buttons.find(button);
105 if (button_iter == controller.buttons.cend()) {
114 LOG_ERROR(Input, "Invalid button {}", button); 106 LOG_ERROR(Input, "Invalid button {}", button);
115 return false; 107 return false;
116 } 108 }
117 return controller.buttons.at(button); 109 return button_iter->second;
118} 110}
119 111
120bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const { 112bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const {
121 std::lock_guard lock{mutex}; 113 std::lock_guard lock{mutex};
122 if (!controller_list.contains(identifier)) { 114 const auto controller_iter = controller_list.find(identifier);
115 if (controller_iter == controller_list.cend()) {
123 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 116 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
124 identifier.pad, identifier.port); 117 identifier.pad, identifier.port);
125 return false; 118 return false;
126 } 119 }
127 ControllerData controller = controller_list.at(identifier); 120 const ControllerData& controller = controller_iter->second;
128 if (!controller.hat_buttons.contains(button)) { 121 const auto hat_iter = controller.hat_buttons.find(button);
122 if (hat_iter == controller.hat_buttons.cend()) {
129 LOG_ERROR(Input, "Invalid hat button {}", button); 123 LOG_ERROR(Input, "Invalid hat button {}", button);
130 return false; 124 return false;
131 } 125 }
132 return (controller.hat_buttons.at(button) & direction) != 0; 126 return (hat_iter->second & direction) != 0;
133} 127}
134 128
135f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { 129f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const {
136 std::lock_guard lock{mutex}; 130 std::lock_guard lock{mutex};
137 if (!controller_list.contains(identifier)) { 131 const auto controller_iter = controller_list.find(identifier);
132 if (controller_iter == controller_list.cend()) {
138 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 133 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
139 identifier.pad, identifier.port); 134 identifier.pad, identifier.port);
140 return 0.0f; 135 return 0.0f;
141 } 136 }
142 ControllerData controller = controller_list.at(identifier); 137 const ControllerData& controller = controller_iter->second;
143 if (!controller.axes.contains(axis)) { 138 const auto axis_iter = controller.axes.find(axis);
139 if (axis_iter == controller.axes.cend()) {
144 LOG_ERROR(Input, "Invalid axis {}", axis); 140 LOG_ERROR(Input, "Invalid axis {}", axis);
145 return 0.0f; 141 return 0.0f;
146 } 142 }
147 return controller.axes.at(axis); 143 return axis_iter->second;
148} 144}
149 145
150BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { 146BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const {
151 std::lock_guard lock{mutex}; 147 std::lock_guard lock{mutex};
152 if (!controller_list.contains(identifier)) { 148 const auto controller_iter = controller_list.find(identifier);
149 if (controller_iter == controller_list.cend()) {
153 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 150 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
154 identifier.pad, identifier.port); 151 identifier.pad, identifier.port);
155 return BatteryLevel::Charging; 152 return BatteryLevel::Charging;
156 } 153 }
157 ControllerData controller = controller_list.at(identifier); 154 const ControllerData& controller = controller_iter->second;
158 return controller.battery; 155 return controller.battery;
159} 156}
160 157
161BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { 158BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const {
162 std::lock_guard lock{mutex}; 159 std::lock_guard lock{mutex};
163 if (!controller_list.contains(identifier)) { 160 const auto controller_iter = controller_list.find(identifier);
161 if (controller_iter == controller_list.cend()) {
164 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), 162 LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(),
165 identifier.pad, identifier.port); 163 identifier.pad, identifier.port);
166 return {}; 164 return {};
167 } 165 }
168 ControllerData controller = controller_list.at(identifier); 166 const ControllerData& controller = controller_iter->second;
169 return controller.motions.at(motion); 167 return controller.motions.at(motion);
170} 168}
171 169
172void InputEngine::ResetButtonState() { 170void InputEngine::ResetButtonState() {
173 for (std::pair<PadIdentifier, ControllerData> controller : controller_list) { 171 for (const auto& controller : controller_list) {
174 for (std::pair<int, bool> button : controller.second.buttons) { 172 for (const auto& button : controller.second.buttons) {
175 SetButton(controller.first, button.first, false); 173 SetButton(controller.first, button.first, false);
176 } 174 }
177 for (std::pair<int, bool> button : controller.second.hat_buttons) { 175 for (const auto& button : controller.second.hat_buttons) {
178 SetHatButton(controller.first, button.first, false); 176 SetHatButton(controller.first, button.first, false);
179 } 177 }
180 } 178 }
181} 179}
182 180
183void InputEngine::ResetAnalogState() { 181void InputEngine::ResetAnalogState() {
184 for (std::pair<PadIdentifier, ControllerData> controller : controller_list) { 182 for (const auto& controller : controller_list) {
185 for (std::pair<int, float> axis : controller.second.axes) { 183 for (const auto& axis : controller.second.axes) {
186 SetAxis(controller.first, axis.first, 0.0); 184 SetAxis(controller.first, axis.first, 0.0);
187 } 185 }
188 } 186 }
@@ -190,7 +188,7 @@ void InputEngine::ResetAnalogState() {
190 188
191void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) { 189void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) {
192 std::lock_guard lock{mutex_callback}; 190 std::lock_guard lock{mutex_callback};
193 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 191 for (const auto& poller_pair : callback_list) {
194 const InputIdentifier& poller = poller_pair.second; 192 const InputIdentifier& poller = poller_pair.second;
195 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) { 193 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) {
196 continue; 194 continue;
@@ -218,7 +216,7 @@ void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int but
218 216
219void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) { 217void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) {
220 std::lock_guard lock{mutex_callback}; 218 std::lock_guard lock{mutex_callback};
221 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 219 for (const auto& poller_pair : callback_list) {
222 const InputIdentifier& poller = poller_pair.second; 220 const InputIdentifier& poller = poller_pair.second;
223 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) { 221 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) {
224 continue; 222 continue;
@@ -247,7 +245,7 @@ void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int
247 245
248void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) { 246void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) {
249 std::lock_guard lock{mutex_callback}; 247 std::lock_guard lock{mutex_callback};
250 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 248 for (const auto& poller_pair : callback_list) {
251 const InputIdentifier& poller = poller_pair.second; 249 const InputIdentifier& poller = poller_pair.second;
252 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) { 250 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) {
253 continue; 251 continue;
@@ -274,7 +272,7 @@ void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis,
274void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, 272void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
275 [[maybe_unused]] BatteryLevel value) { 273 [[maybe_unused]] BatteryLevel value) {
276 std::lock_guard lock{mutex_callback}; 274 std::lock_guard lock{mutex_callback};
277 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 275 for (const auto& poller_pair : callback_list) {
278 const InputIdentifier& poller = poller_pair.second; 276 const InputIdentifier& poller = poller_pair.second;
279 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) { 277 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) {
280 continue; 278 continue;
@@ -286,9 +284,9 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
286} 284}
287 285
288void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, 286void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
289 BasicMotion value) { 287 const BasicMotion& value) {
290 std::lock_guard lock{mutex_callback}; 288 std::lock_guard lock{mutex_callback};
291 for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { 289 for (const auto& poller_pair : callback_list) {
292 const InputIdentifier& poller = poller_pair.second; 290 const InputIdentifier& poller = poller_pair.second;
293 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) { 291 if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) {
294 continue; 292 continue;
@@ -342,7 +340,7 @@ const std::string& InputEngine::GetEngineName() const {
342 340
343int InputEngine::SetCallback(InputIdentifier input_identifier) { 341int InputEngine::SetCallback(InputIdentifier input_identifier) {
344 std::lock_guard lock{mutex_callback}; 342 std::lock_guard lock{mutex_callback};
345 callback_list.insert_or_assign(last_callback_key, input_identifier); 343 callback_list.insert_or_assign(last_callback_key, std::move(input_identifier));
346 return last_callback_key++; 344 return last_callback_key++;
347} 345}
348 346
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index 02272b3f8..390581c94 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -23,15 +23,15 @@ struct PadIdentifier {
23 friend constexpr bool operator==(const PadIdentifier&, const PadIdentifier&) = default; 23 friend constexpr bool operator==(const PadIdentifier&, const PadIdentifier&) = default;
24}; 24};
25 25
26// Basic motion data containing data from the sensors and a timestamp in microsecons 26// Basic motion data containing data from the sensors and a timestamp in microseconds
27struct BasicMotion { 27struct BasicMotion {
28 float gyro_x; 28 float gyro_x{};
29 float gyro_y; 29 float gyro_y{};
30 float gyro_z; 30 float gyro_z{};
31 float accel_x; 31 float accel_x{};
32 float accel_y; 32 float accel_y{};
33 float accel_z; 33 float accel_z{};
34 u64 delta_timestamp; 34 u64 delta_timestamp{};
35}; 35};
36 36
37// Stages of a battery charge 37// Stages of a battery charge
@@ -102,9 +102,7 @@ struct InputIdentifier {
102 102
103class InputEngine { 103class InputEngine {
104public: 104public:
105 explicit InputEngine(const std::string& input_engine_) : input_engine(input_engine_) { 105 explicit InputEngine(std::string input_engine_) : input_engine{std::move(input_engine_)} {}
106 callback_list.clear();
107 }
108 106
109 virtual ~InputEngine() = default; 107 virtual ~InputEngine() = default;
110 108
@@ -116,14 +114,12 @@ public:
116 114
117 // Sets a led pattern for a controller 115 // Sets a led pattern for a controller
118 virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier, 116 virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier,
119 [[maybe_unused]] const Common::Input::LedStatus led_status) { 117 [[maybe_unused]] const Common::Input::LedStatus& led_status) {}
120 return;
121 }
122 118
123 // Sets rumble to a controller 119 // Sets rumble to a controller
124 virtual Common::Input::VibrationError SetRumble( 120 virtual Common::Input::VibrationError SetRumble(
125 [[maybe_unused]] const PadIdentifier& identifier, 121 [[maybe_unused]] const PadIdentifier& identifier,
126 [[maybe_unused]] const Common::Input::VibrationStatus vibration) { 122 [[maybe_unused]] const Common::Input::VibrationStatus& vibration) {
127 return Common::Input::VibrationError::NotSupported; 123 return Common::Input::VibrationError::NotSupported;
128 } 124 }
129 125
@@ -140,36 +136,36 @@ public:
140 /// Used for automapping features 136 /// Used for automapping features
141 virtual std::vector<Common::ParamPackage> GetInputDevices() const { 137 virtual std::vector<Common::ParamPackage> GetInputDevices() const {
142 return {}; 138 return {};
143 }; 139 }
144 140
145 /// Retrieves the button mappings for the given device 141 /// Retrieves the button mappings for the given device
146 virtual InputCommon::ButtonMapping GetButtonMappingForDevice( 142 virtual ButtonMapping GetButtonMappingForDevice(
147 [[maybe_unused]] const Common::ParamPackage& params) { 143 [[maybe_unused]] const Common::ParamPackage& params) {
148 return {}; 144 return {};
149 }; 145 }
150 146
151 /// Retrieves the analog mappings for the given device 147 /// Retrieves the analog mappings for the given device
152 virtual InputCommon::AnalogMapping GetAnalogMappingForDevice( 148 virtual AnalogMapping GetAnalogMappingForDevice(
153 [[maybe_unused]] const Common::ParamPackage& params) { 149 [[maybe_unused]] const Common::ParamPackage& params) {
154 return {}; 150 return {};
155 }; 151 }
156 152
157 /// Retrieves the motion mappings for the given device 153 /// Retrieves the motion mappings for the given device
158 virtual InputCommon::MotionMapping GetMotionMappingForDevice( 154 virtual MotionMapping GetMotionMappingForDevice(
159 [[maybe_unused]] const Common::ParamPackage& params) { 155 [[maybe_unused]] const Common::ParamPackage& params) {
160 return {}; 156 return {};
161 }; 157 }
162 158
163 /// Retrieves the name of the given input. 159 /// Retrieves the name of the given input.
164 virtual Common::Input::ButtonNames GetUIName( 160 virtual Common::Input::ButtonNames GetUIName(
165 [[maybe_unused]] const Common::ParamPackage& params) const { 161 [[maybe_unused]] const Common::ParamPackage& params) const {
166 return Common::Input::ButtonNames::Engine; 162 return Common::Input::ButtonNames::Engine;
167 }; 163 }
168 164
169 /// Retrieves the index number of the given hat button direction 165 /// Retrieves the index number of the given hat button direction
170 virtual u8 GetHatButtonId([[maybe_unused]] const std::string& direction_name) const { 166 virtual u8 GetHatButtonId([[maybe_unused]] const std::string& direction_name) const {
171 return 0; 167 return 0;
172 }; 168 }
173 169
174 void PreSetController(const PadIdentifier& identifier); 170 void PreSetController(const PadIdentifier& identifier);
175 void PreSetButton(const PadIdentifier& identifier, int button); 171 void PreSetButton(const PadIdentifier& identifier, int button);
@@ -194,7 +190,7 @@ protected:
194 void SetHatButton(const PadIdentifier& identifier, int button, u8 value); 190 void SetHatButton(const PadIdentifier& identifier, int button, u8 value);
195 void SetAxis(const PadIdentifier& identifier, int axis, f32 value); 191 void SetAxis(const PadIdentifier& identifier, int axis, f32 value);
196 void SetBattery(const PadIdentifier& identifier, BatteryLevel value); 192 void SetBattery(const PadIdentifier& identifier, BatteryLevel value);
197 void SetMotion(const PadIdentifier& identifier, int motion, BasicMotion value); 193 void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value);
198 194
199 virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { 195 virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const {
200 return "Unknown"; 196 return "Unknown";
@@ -206,14 +202,15 @@ private:
206 std::unordered_map<int, u8> hat_buttons; 202 std::unordered_map<int, u8> hat_buttons;
207 std::unordered_map<int, float> axes; 203 std::unordered_map<int, float> axes;
208 std::unordered_map<int, BasicMotion> motions; 204 std::unordered_map<int, BasicMotion> motions;
209 BatteryLevel battery; 205 BatteryLevel battery{};
210 }; 206 };
211 207
212 void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); 208 void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value);
213 void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); 209 void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value);
214 void TriggerOnAxisChange(const PadIdentifier& identifier, int button, f32 value); 210 void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value);
215 void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value); 211 void TriggerOnBatteryChange(const PadIdentifier& identifier, BatteryLevel value);
216 void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, BasicMotion value); 212 void TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
213 const BasicMotion& value);
217 214
218 bool IsInputIdentifierEqual(const InputIdentifier& input_identifier, 215 bool IsInputIdentifierEqual(const InputIdentifier& input_identifier,
219 const PadIdentifier& identifier, EngineInputType type, 216 const PadIdentifier& identifier, EngineInputType type,
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h
index 44eb8ad9a..93564b5f8 100644
--- a/src/input_common/input_mapping.h
+++ b/src/input_common/input_mapping.h
@@ -14,8 +14,8 @@ public:
14 MappingFactory(); 14 MappingFactory();
15 15
16 /** 16 /**
17 * Resets all varables to beggin the mapping process 17 * Resets all variables to begin the mapping process
18 * @param "type": type of input desired to be returned 18 * @param type type of input desired to be returned
19 */ 19 */
20 void BeginMapping(Polling::InputType type); 20 void BeginMapping(Polling::InputType type);
21 21
@@ -24,8 +24,8 @@ public:
24 24
25 /** 25 /**
26 * Registers mapping input data from the driver 26 * Registers mapping input data from the driver
27 * @param "data": An struct containing all the information needed to create a proper 27 * @param data A struct containing all the information needed to create a proper
28 * ParamPackage 28 * ParamPackage
29 */ 29 */
30 void RegisterInput(const MappingData& data); 30 void RegisterInput(const MappingData& data);
31 31
@@ -34,42 +34,42 @@ public:
34 34
35private: 35private:
36 /** 36 /**
37 * If provided data satisfies the requeriments it will push an element to the input_queue 37 * If provided data satisfies the requirements it will push an element to the input_queue
38 * Supported input: 38 * Supported input:
39 * - Button: Creates a basic button ParamPackage 39 * - Button: Creates a basic button ParamPackage
40 * - HatButton: Creates a basic hat button ParamPackage 40 * - HatButton: Creates a basic hat button ParamPackage
41 * - Analog: Creates a basic analog ParamPackage 41 * - Analog: Creates a basic analog ParamPackage
42 * @param "data": An struct containing all the information needed to create a proper 42 * @param data A struct containing all the information needed to create a proper
43 * ParamPackage 43 * ParamPackage
44 */ 44 */
45 void RegisterButton(const MappingData& data); 45 void RegisterButton(const MappingData& data);
46 46
47 /** 47 /**
48 * If provided data satisfies the requeriments it will push an element to the input_queue 48 * If provided data satisfies the requirements it will push an element to the input_queue
49 * Supported input: 49 * Supported input:
50 * - Button, HatButton: Pass the data to RegisterButton 50 * - Button, HatButton: Pass the data to RegisterButton
51 * - Analog: Stores the first axis and on the second axis creates a basic stick ParamPackage 51 * - Analog: Stores the first axis and on the second axis creates a basic stick ParamPackage
52 * @param "data": An struct containing all the information needed to create a proper 52 * @param data A struct containing all the information needed to create a proper
53 * ParamPackage 53 * ParamPackage
54 */ 54 */
55 void RegisterStick(const MappingData& data); 55 void RegisterStick(const MappingData& data);
56 56
57 /** 57 /**
58 * If provided data satisfies the requeriments it will push an element to the input_queue 58 * If provided data satisfies the requirements it will push an element to the input_queue
59 * Supported input: 59 * Supported input:
60 * - Button, HatButton: Pass the data to RegisterButton 60 * - Button, HatButton: Pass the data to RegisterButton
61 * - Analog: Stores the first two axis and on the third axis creates a basic Motion 61 * - Analog: Stores the first two axis and on the third axis creates a basic Motion
62 * ParamPackage 62 * ParamPackage
63 * - Motion: Creates a basic Motion ParamPackage 63 * - Motion: Creates a basic Motion ParamPackage
64 * @param "data": An struct containing all the information needed to create a proper 64 * @param data A struct containing all the information needed to create a proper
65 * ParamPackage 65 * ParamPackage
66 */ 66 */
67 void RegisterMotion(const MappingData& data); 67 void RegisterMotion(const MappingData& data);
68 68
69 /** 69 /**
70 * Returns true if driver can be mapped 70 * Returns true if driver can be mapped
71 * @param "data": An struct containing all the information needed to create a proper 71 * @param data A struct containing all the information needed to create a proper
72 * ParamPackage 72 * ParamPackage
73 */ 73 */
74 bool IsDriverValid(const MappingData& data) const; 74 bool IsDriverValid(const MappingData& data) const;
75 75
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 7e4eafded..7b370335f 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -12,8 +12,7 @@ namespace InputCommon {
12 12
13class DummyInput final : public Common::Input::InputDevice { 13class DummyInput final : public Common::Input::InputDevice {
14public: 14public:
15 explicit DummyInput() {} 15 explicit DummyInput() = default;
16 ~DummyInput() {}
17}; 16};
18 17
19class InputFromButton final : public Common::Input::InputDevice { 18class InputFromButton final : public Common::Input::InputDevice {
@@ -33,7 +32,7 @@ public:
33 callback_key = input_engine->SetCallback(input_identifier); 32 callback_key = input_engine->SetCallback(input_identifier);
34 } 33 }
35 34
36 ~InputFromButton() { 35 ~InputFromButton() override {
37 input_engine->DeleteCallback(callback_key); 36 input_engine->DeleteCallback(callback_key);
38 } 37 }
39 38
@@ -45,7 +44,7 @@ public:
45 }; 44 };
46 } 45 }
47 46
48 void ForceUpdate() { 47 void ForceUpdate() override {
49 const Common::Input::CallbackStatus status{ 48 const Common::Input::CallbackStatus status{
50 .type = Common::Input::InputType::Button, 49 .type = Common::Input::InputType::Button,
51 .button_status = GetStatus(), 50 .button_status = GetStatus(),
@@ -94,7 +93,7 @@ public:
94 callback_key = input_engine->SetCallback(input_identifier); 93 callback_key = input_engine->SetCallback(input_identifier);
95 } 94 }
96 95
97 ~InputFromHatButton() { 96 ~InputFromHatButton() override {
98 input_engine->DeleteCallback(callback_key); 97 input_engine->DeleteCallback(callback_key);
99 } 98 }
100 99
@@ -106,7 +105,7 @@ public:
106 }; 105 };
107 } 106 }
108 107
109 void ForceUpdate() { 108 void ForceUpdate() override {
110 const Common::Input::CallbackStatus status{ 109 const Common::Input::CallbackStatus status{
111 .type = Common::Input::InputType::Button, 110 .type = Common::Input::InputType::Button,
112 .button_status = GetStatus(), 111 .button_status = GetStatus(),
@@ -167,7 +166,7 @@ public:
167 callback_key_y = input_engine->SetCallback(y_input_identifier); 166 callback_key_y = input_engine->SetCallback(y_input_identifier);
168 } 167 }
169 168
170 ~InputFromStick() { 169 ~InputFromStick() override {
171 input_engine->DeleteCallback(callback_key_x); 170 input_engine->DeleteCallback(callback_key_x);
172 input_engine->DeleteCallback(callback_key_y); 171 input_engine->DeleteCallback(callback_key_y);
173 } 172 }
@@ -190,7 +189,7 @@ public:
190 return status; 189 return status;
191 } 190 }
192 191
193 void ForceUpdate() { 192 void ForceUpdate() override {
194 const Common::Input::CallbackStatus status{ 193 const Common::Input::CallbackStatus status{
195 .type = Common::Input::InputType::Stick, 194 .type = Common::Input::InputType::Stick,
196 .stick_status = GetStatus(), 195 .stick_status = GetStatus(),
@@ -266,7 +265,7 @@ public:
266 callback_key_y = input_engine->SetCallback(y_input_identifier); 265 callback_key_y = input_engine->SetCallback(y_input_identifier);
267 } 266 }
268 267
269 ~InputFromTouch() { 268 ~InputFromTouch() override {
270 input_engine->DeleteCallback(callback_key_button); 269 input_engine->DeleteCallback(callback_key_button);
271 input_engine->DeleteCallback(callback_key_x); 270 input_engine->DeleteCallback(callback_key_x);
272 input_engine->DeleteCallback(callback_key_y); 271 input_engine->DeleteCallback(callback_key_y);
@@ -352,7 +351,7 @@ public:
352 axis_callback_key = input_engine->SetCallback(axis_input_identifier); 351 axis_callback_key = input_engine->SetCallback(axis_input_identifier);
353 } 352 }
354 353
355 ~InputFromTrigger() { 354 ~InputFromTrigger() override {
356 input_engine->DeleteCallback(callback_key_button); 355 input_engine->DeleteCallback(callback_key_button);
357 input_engine->DeleteCallback(axis_callback_key); 356 input_engine->DeleteCallback(axis_callback_key);
358 } 357 }
@@ -419,7 +418,7 @@ public:
419 callback_key = input_engine->SetCallback(input_identifier); 418 callback_key = input_engine->SetCallback(input_identifier);
420 } 419 }
421 420
422 ~InputFromAnalog() { 421 ~InputFromAnalog() override {
423 input_engine->DeleteCallback(callback_key); 422 input_engine->DeleteCallback(callback_key);
424 } 423 }
425 424
@@ -466,7 +465,7 @@ public:
466 callback_key = input_engine->SetCallback(input_identifier); 465 callback_key = input_engine->SetCallback(input_identifier);
467 } 466 }
468 467
469 ~InputFromBattery() { 468 ~InputFromBattery() override {
470 input_engine->DeleteCallback(callback_key); 469 input_engine->DeleteCallback(callback_key);
471 } 470 }
472 471
@@ -474,7 +473,7 @@ public:
474 return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier)); 473 return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier));
475 } 474 }
476 475
477 void ForceUpdate() { 476 void ForceUpdate() override {
478 const Common::Input::CallbackStatus status{ 477 const Common::Input::CallbackStatus status{
479 .type = Common::Input::InputType::Battery, 478 .type = Common::Input::InputType::Battery,
480 .battery_status = GetStatus(), 479 .battery_status = GetStatus(),
@@ -518,7 +517,7 @@ public:
518 callback_key = input_engine->SetCallback(input_identifier); 517 callback_key = input_engine->SetCallback(input_identifier);
519 } 518 }
520 519
521 ~InputFromMotion() { 520 ~InputFromMotion() override {
522 input_engine->DeleteCallback(callback_key); 521 input_engine->DeleteCallback(callback_key);
523 } 522 }
524 523
@@ -593,7 +592,7 @@ public:
593 callback_key_z = input_engine->SetCallback(z_input_identifier); 592 callback_key_z = input_engine->SetCallback(z_input_identifier);
594 } 593 }
595 594
596 ~InputFromAxisMotion() { 595 ~InputFromAxisMotion() override {
597 input_engine->DeleteCallback(callback_key_x); 596 input_engine->DeleteCallback(callback_key_x);
598 input_engine->DeleteCallback(callback_key_y); 597 input_engine->DeleteCallback(callback_key_y);
599 input_engine->DeleteCallback(callback_key_z); 598 input_engine->DeleteCallback(callback_key_z);
@@ -618,7 +617,7 @@ public:
618 return status; 617 return status;
619 } 618 }
620 619
621 void ForceUpdate() { 620 void ForceUpdate() override {
622 const Common::Input::CallbackStatus status{ 621 const Common::Input::CallbackStatus status{
623 .type = Common::Input::InputType::Motion, 622 .type = Common::Input::InputType::Motion,
624 .motion_status = GetStatus(), 623 .motion_status = GetStatus(),
@@ -668,16 +667,16 @@ public:
668 explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) 667 explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
669 : identifier(identifier_), input_engine(input_engine_) {} 668 : identifier(identifier_), input_engine(input_engine_) {}
670 669
671 virtual void SetLED(Common::Input::LedStatus led_status) { 670 void SetLED(const Common::Input::LedStatus& led_status) override {
672 input_engine->SetLeds(identifier, led_status); 671 input_engine->SetLeds(identifier, led_status);
673 } 672 }
674 673
675 virtual Common::Input::VibrationError SetVibration( 674 Common::Input::VibrationError SetVibration(
676 Common::Input::VibrationStatus vibration_status) { 675 const Common::Input::VibrationStatus& vibration_status) override {
677 return input_engine->SetRumble(identifier, vibration_status); 676 return input_engine->SetRumble(identifier, vibration_status);
678 } 677 }
679 678
680 virtual Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) { 679 Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override {
681 return input_engine->SetPollingMode(identifier, polling_mode); 680 return input_engine->SetPollingMode(identifier, polling_mode);
682 } 681 }
683 682
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
index 573f09fde..8a0977d58 100644
--- a/src/input_common/input_poller.h
+++ b/src/input_common/input_poller.h
@@ -13,9 +13,6 @@ class Factory;
13 13
14namespace InputCommon { 14namespace InputCommon {
15class InputEngine; 15class InputEngine;
16/**
17 * An Input factory. It receives input events and forward them to all input devices it created.
18 */
19 16
20class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> { 17class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> {
21public: 18public:
@@ -24,10 +21,10 @@ public:
24 /** 21 /**
25 * Creates an output device from the parameters given. 22 * Creates an output device from the parameters given.
26 * @param params contains parameters for creating the device: 23 * @param params contains parameters for creating the device:
27 * @param - "guid": text string for identifing controllers 24 * - "guid" text string for identifying controllers
28 * @param - "port": port of the connected device 25 * - "port": port of the connected device
29 * @param - "pad": slot of the connected controller 26 * - "pad": slot of the connected controller
30 * @return an unique ouput device with the parameters specified 27 * @returns a unique output device with the parameters specified
31 */ 28 */
32 std::unique_ptr<Common::Input::OutputDevice> Create( 29 std::unique_ptr<Common::Input::OutputDevice> Create(
33 const Common::ParamPackage& params) override; 30 const Common::ParamPackage& params) override;
@@ -36,6 +33,9 @@ private:
36 std::shared_ptr<InputEngine> input_engine; 33 std::shared_ptr<InputEngine> input_engine;
37}; 34};
38 35
36/**
37 * An Input factory. It receives input events and forward them to all input devices it created.
38 */
39class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> { 39class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> {
40public: 40public:
41 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_); 41 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
@@ -54,16 +54,16 @@ public:
54 * - battery: Contains "battery" 54 * - battery: Contains "battery"
55 * - output: Contains "output" 55 * - output: Contains "output"
56 * @param params contains parameters for creating the device: 56 * @param params contains parameters for creating the device:
57 * @param - "code": the code of the keyboard key to bind with the input 57 * - "code": the code of the keyboard key to bind with the input
58 * @param - "button": same as "code" but for controller buttons 58 * - "button": same as "code" but for controller buttons
59 * @param - "hat": similar as "button" but it's a group of hat buttons from SDL 59 * - "hat": similar as "button" but it's a group of hat buttons from SDL
60 * @param - "axis": the axis number of the axis to bind with the input 60 * - "axis": the axis number of the axis to bind with the input
61 * @param - "motion": the motion number of the motion to bind with the input 61 * - "motion": the motion number of the motion to bind with the input
62 * @param - "axis_x": same as axis but specifing horizontal direction 62 * - "axis_x": same as axis but specifying horizontal direction
63 * @param - "axis_y": same as axis but specifing vertical direction 63 * - "axis_y": same as axis but specifying vertical direction
64 * @param - "axis_z": same as axis but specifing forward direction 64 * - "axis_z": same as axis but specifying forward direction
65 * @param - "battery": Only used as a placeholder to set the input type 65 * - "battery": Only used as a placeholder to set the input type
66 * @return an unique input device with the parameters specified 66 * @returns a unique input device with the parameters specified
67 */ 67 */
68 std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override; 68 std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
69 69
@@ -71,14 +71,14 @@ private:
71 /** 71 /**
72 * Creates a button device from the parameters given. 72 * Creates a button device from the parameters given.
73 * @param params contains parameters for creating the device: 73 * @param params contains parameters for creating the device:
74 * @param - "code": the code of the keyboard key to bind with the input 74 * - "code": the code of the keyboard key to bind with the input
75 * @param - "button": same as "code" but for controller buttons 75 * - "button": same as "code" but for controller buttons
76 * @param - "toggle": press once to enable, press again to disable 76 * - "toggle": press once to enable, press again to disable
77 * @param - "inverted": inverts the output of the button 77 * - "inverted": inverts the output of the button
78 * @param - "guid": text string for identifing controllers 78 * - "guid": text string for identifying controllers
79 * @param - "port": port of the connected device 79 * - "port": port of the connected device
80 * @param - "pad": slot of the connected controller 80 * - "pad": slot of the connected controller
81 * @return an unique input device with the parameters specified 81 * @returns a unique input device with the parameters specified
82 */ 82 */
83 std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice( 83 std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice(
84 const Common::ParamPackage& params); 84 const Common::ParamPackage& params);
@@ -86,14 +86,14 @@ private:
86 /** 86 /**
87 * Creates a hat button device from the parameters given. 87 * Creates a hat button device from the parameters given.
88 * @param params contains parameters for creating the device: 88 * @param params contains parameters for creating the device:
89 * @param - "button": the controller hat id to bind with the input 89 * - "button": the controller hat id to bind with the input
90 * @param - "direction": the direction id to be detected 90 * - "direction": the direction id to be detected
91 * @param - "toggle": press once to enable, press again to disable 91 * - "toggle": press once to enable, press again to disable
92 * @param - "inverted": inverts the output of the button 92 * - "inverted": inverts the output of the button
93 * @param - "guid": text string for identifing controllers 93 * - "guid": text string for identifying controllers
94 * @param - "port": port of the connected device 94 * - "port": port of the connected device
95 * @param - "pad": slot of the connected controller 95 * - "pad": slot of the connected controller
96 * @return an unique input device with the parameters specified 96 * @returns a unique input device with the parameters specified
97 */ 97 */
98 std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice( 98 std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice(
99 const Common::ParamPackage& params); 99 const Common::ParamPackage& params);
@@ -101,19 +101,19 @@ private:
101 /** 101 /**
102 * Creates a stick device from the parameters given. 102 * Creates a stick device from the parameters given.
103 * @param params contains parameters for creating the device: 103 * @param params contains parameters for creating the device:
104 * @param - "axis_x": the controller horizontal axis id to bind with the input 104 * - "axis_x": the controller horizontal axis id to bind with the input
105 * @param - "axis_y": the controller vertical axis id to bind with the input 105 * - "axis_y": the controller vertical axis id to bind with the input
106 * @param - "deadzone": the mimimum required value to be detected 106 * - "deadzone": the minimum required value to be detected
107 * @param - "range": the maximum value required to reach 100% 107 * - "range": the maximum value required to reach 100%
108 * @param - "threshold": the mimimum required value to considered pressed 108 * - "threshold": the minimum required value to considered pressed
109 * @param - "offset_x": the amount of offset in the x axis 109 * - "offset_x": the amount of offset in the x axis
110 * @param - "offset_y": the amount of offset in the y axis 110 * - "offset_y": the amount of offset in the y axis
111 * @param - "invert_x": inverts the sign of the horizontal axis 111 * - "invert_x": inverts the sign of the horizontal axis
112 * @param - "invert_y": inverts the sign of the vertical axis 112 * - "invert_y": inverts the sign of the vertical axis
113 * @param - "guid": text string for identifing controllers 113 * - "guid": text string for identifying controllers
114 * @param - "port": port of the connected device 114 * - "port": port of the connected device
115 * @param - "pad": slot of the connected controller 115 * - "pad": slot of the connected controller
116 * @return an unique input device with the parameters specified 116 * @returns a unique input device with the parameters specified
117 */ 117 */
118 std::unique_ptr<Common::Input::InputDevice> CreateStickDevice( 118 std::unique_ptr<Common::Input::InputDevice> CreateStickDevice(
119 const Common::ParamPackage& params); 119 const Common::ParamPackage& params);
@@ -121,16 +121,16 @@ private:
121 /** 121 /**
122 * Creates an analog device from the parameters given. 122 * Creates an analog device from the parameters given.
123 * @param params contains parameters for creating the device: 123 * @param params contains parameters for creating the device:
124 * @param - "axis": the controller axis id to bind with the input 124 * - "axis": the controller axis id to bind with the input
125 * @param - "deadzone": the mimimum required value to be detected 125 * - "deadzone": the minimum required value to be detected
126 * @param - "range": the maximum value required to reach 100% 126 * - "range": the maximum value required to reach 100%
127 * @param - "threshold": the mimimum required value to considered pressed 127 * - "threshold": the minimum required value to considered pressed
128 * @param - "offset": the amount of offset in the axis 128 * - "offset": the amount of offset in the axis
129 * @param - "invert": inverts the sign of the axis 129 * - "invert": inverts the sign of the axis
130 * @param - "guid": text string for identifing controllers 130 * - "guid": text string for identifying controllers
131 * @param - "port": port of the connected device 131 * - "port": port of the connected device
132 * @param - "pad": slot of the connected controller 132 * - "pad": slot of the connected controller
133 * @return an unique input device with the parameters specified 133 * @returns a unique input device with the parameters specified
134 */ 134 */
135 std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice( 135 std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice(
136 const Common::ParamPackage& params); 136 const Common::ParamPackage& params);
@@ -138,20 +138,20 @@ private:
138 /** 138 /**
139 * Creates a trigger device from the parameters given. 139 * Creates a trigger device from the parameters given.
140 * @param params contains parameters for creating the device: 140 * @param params contains parameters for creating the device:
141 * @param - "button": the controller hat id to bind with the input 141 * - "button": the controller hat id to bind with the input
142 * @param - "direction": the direction id to be detected 142 * - "direction": the direction id to be detected
143 * @param - "toggle": press once to enable, press again to disable 143 * - "toggle": press once to enable, press again to disable
144 * @param - "inverted": inverts the output of the button 144 * - "inverted": inverts the output of the button
145 * @param - "axis": the controller axis id to bind with the input 145 * - "axis": the controller axis id to bind with the input
146 * @param - "deadzone": the mimimum required value to be detected 146 * - "deadzone": the minimum required value to be detected
147 * @param - "range": the maximum value required to reach 100% 147 * - "range": the maximum value required to reach 100%
148 * @param - "threshold": the mimimum required value to considered pressed 148 * - "threshold": the minimum required value to considered pressed
149 * @param - "offset": the amount of offset in the axis 149 * - "offset": the amount of offset in the axis
150 * @param - "invert": inverts the sign of the axis 150 * - "invert": inverts the sign of the axis
151 * @param - "guid": text string for identifing controllers 151 * - "guid": text string for identifying controllers
152 * @param - "port": port of the connected device 152 * - "port": port of the connected device
153 * @param - "pad": slot of the connected controller 153 * - "pad": slot of the connected controller
154 * @return an unique input device with the parameters specified 154 * @returns a unique input device with the parameters specified
155 */ 155 */
156 std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice( 156 std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice(
157 const Common::ParamPackage& params); 157 const Common::ParamPackage& params);
@@ -159,23 +159,23 @@ private:
159 /** 159 /**
160 * Creates a touch device from the parameters given. 160 * Creates a touch device from the parameters given.
161 * @param params contains parameters for creating the device: 161 * @param params contains parameters for creating the device:
162 * @param - "button": the controller hat id to bind with the input 162 * - "button": the controller hat id to bind with the input
163 * @param - "direction": the direction id to be detected 163 * - "direction": the direction id to be detected
164 * @param - "toggle": press once to enable, press again to disable 164 * - "toggle": press once to enable, press again to disable
165 * @param - "inverted": inverts the output of the button 165 * - "inverted": inverts the output of the button
166 * @param - "axis_x": the controller horizontal axis id to bind with the input 166 * - "axis_x": the controller horizontal axis id to bind with the input
167 * @param - "axis_y": the controller vertical axis id to bind with the input 167 * - "axis_y": the controller vertical axis id to bind with the input
168 * @param - "deadzone": the mimimum required value to be detected 168 * - "deadzone": the minimum required value to be detected
169 * @param - "range": the maximum value required to reach 100% 169 * - "range": the maximum value required to reach 100%
170 * @param - "threshold": the mimimum required value to considered pressed 170 * - "threshold": the minimum required value to considered pressed
171 * @param - "offset_x": the amount of offset in the x axis 171 * - "offset_x": the amount of offset in the x axis
172 * @param - "offset_y": the amount of offset in the y axis 172 * - "offset_y": the amount of offset in the y axis
173 * @param - "invert_x": inverts the sign of the horizontal axis 173 * - "invert_x": inverts the sign of the horizontal axis
174 * @param - "invert_y": inverts the sign of the vertical axis 174 * - "invert_y": inverts the sign of the vertical axis
175 * @param - "guid": text string for identifing controllers 175 * - "guid": text string for identifying controllers
176 * @param - "port": port of the connected device 176 * - "port": port of the connected device
177 * @param - "pad": slot of the connected controller 177 * - "pad": slot of the connected controller
178 * @return an unique input device with the parameters specified 178 * @returns a unique input device with the parameters specified
179 */ 179 */
180 std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice( 180 std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice(
181 const Common::ParamPackage& params); 181 const Common::ParamPackage& params);
@@ -183,10 +183,10 @@ private:
183 /** 183 /**
184 * Creates a battery device from the parameters given. 184 * Creates a battery device from the parameters given.
185 * @param params contains parameters for creating the device: 185 * @param params contains parameters for creating the device:
186 * @param - "guid": text string for identifing controllers 186 * - "guid": text string for identifying controllers
187 * @param - "port": port of the connected device 187 * - "port": port of the connected device
188 * @param - "pad": slot of the connected controller 188 * - "pad": slot of the connected controller
189 * @return an unique input device with the parameters specified 189 * @returns a unique input device with the parameters specified
190 */ 190 */
191 std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice( 191 std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice(
192 const Common::ParamPackage& params); 192 const Common::ParamPackage& params);
@@ -194,21 +194,21 @@ private:
194 /** 194 /**
195 * Creates a motion device from the parameters given. 195 * Creates a motion device from the parameters given.
196 * @param params contains parameters for creating the device: 196 * @param params contains parameters for creating the device:
197 * @param - "axis_x": the controller horizontal axis id to bind with the input 197 * - "axis_x": the controller horizontal axis id to bind with the input
198 * @param - "axis_y": the controller vertical axis id to bind with the input 198 * - "axis_y": the controller vertical axis id to bind with the input
199 * @param - "axis_z": the controller fordward axis id to bind with the input 199 * - "axis_z": the controller forward axis id to bind with the input
200 * @param - "deadzone": the mimimum required value to be detected 200 * - "deadzone": the minimum required value to be detected
201 * @param - "range": the maximum value required to reach 100% 201 * - "range": the maximum value required to reach 100%
202 * @param - "offset_x": the amount of offset in the x axis 202 * - "offset_x": the amount of offset in the x axis
203 * @param - "offset_y": the amount of offset in the y axis 203 * - "offset_y": the amount of offset in the y axis
204 * @param - "offset_z": the amount of offset in the z axis 204 * - "offset_z": the amount of offset in the z axis
205 * @param - "invert_x": inverts the sign of the horizontal axis 205 * - "invert_x": inverts the sign of the horizontal axis
206 * @param - "invert_y": inverts the sign of the vertical axis 206 * - "invert_y": inverts the sign of the vertical axis
207 * @param - "invert_z": inverts the sign of the fordward axis 207 * - "invert_z": inverts the sign of the forward axis
208 * @param - "guid": text string for identifing controllers 208 * - "guid": text string for identifying controllers
209 * @param - "port": port of the connected device 209 * - "port": port of the connected device
210 * @param - "pad": slot of the connected controller 210 * - "pad": slot of the connected controller
211 * @return an unique input device with the parameters specified 211 * @returns a unique input device with the parameters specified
212 */ 212 */
213 std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params); 213 std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
214 214