summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsrc/input_common/analog_from_button.cpp3
-rw-r--r--src/input_common/keyboard.cpp9
-rw-r--r--src/input_common/main.cpp4
-rw-r--r--src/input_common/motion_emu.cpp5
-rw-r--r--src/input_common/sdl/sdl_impl.cpp52
-rw-r--r--src/input_common/udp/client.cpp140
-rw-r--r--src/input_common/udp/client.h2
-rw-r--r--src/input_common/udp/protocol.h32
-rw-r--r--src/input_common/udp/udp.cpp18
9 files changed, 98 insertions, 167 deletions
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp
index 8116fcf9f..6cabdaa3c 100755
--- a/src/input_common/analog_from_button.cpp
+++ b/src/input_common/analog_from_button.cpp
@@ -14,8 +14,7 @@ public:
14 float modifier_scale_) 14 float modifier_scale_)
15 : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), 15 : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
16 right(std::move(right_)), modifier(std::move(modifier_)), 16 right(std::move(right_)), modifier(std::move(modifier_)),
17 modifier_scale(modifier_scale_) { 17 modifier_scale(modifier_scale_) {}
18 }
19 18
20 std::tuple<float, float> GetStatus() const override { 19 std::tuple<float, float> GetStatus() const override {
21 constexpr float SQRT_HALF = 0.707106781f; 20 constexpr float SQRT_HALF = 0.707106781f;
diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp
index d76791860..9138a7563 100644
--- a/src/input_common/keyboard.cpp
+++ b/src/input_common/keyboard.cpp
@@ -13,8 +13,7 @@ namespace InputCommon {
13class KeyButton final : public Input::ButtonDevice { 13class KeyButton final : public Input::ButtonDevice {
14public: 14public:
15 explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_) 15 explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_)
16 : key_button_list(std::move(key_button_list_)) { 16 : key_button_list(std::move(key_button_list_)) {}
17 }
18 17
19 ~KeyButton() override; 18 ~KeyButton() override;
20 19
@@ -69,9 +68,7 @@ private:
69 std::list<KeyButtonPair> list; 68 std::list<KeyButtonPair> list;
70}; 69};
71 70
72Keyboard::Keyboard() 71Keyboard::Keyboard() : key_button_list{std::make_shared<KeyButtonList>()} {}
73 : key_button_list{std::make_shared<KeyButtonList>()} {
74}
75 72
76KeyButton::~KeyButton() { 73KeyButton::~KeyButton() {
77 key_button_list->RemoveKeyButton(this); 74 key_button_list->RemoveKeyButton(this);
@@ -81,7 +78,7 @@ std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage
81 int key_code = params.Get("code", 0); 78 int key_code = params.Get("code", 0);
82 std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list); 79 std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list);
83 key_button_list->AddKeyButton(key_code, button.get()); 80 key_button_list->AddKeyButton(key_code, button.get());
84 return std::move(button); 81 return button;
85} 82}
86 83
87void Keyboard::PressKey(int key_code) { 84void Keyboard::PressKey(int key_code) {
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index be13129af..7fc0e2db4 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -5,7 +5,6 @@
5#include <memory> 5#include <memory>
6#include <thread> 6#include <thread>
7#include <libusb.h> 7#include <libusb.h>
8#include <iostream>
9#include "common/param_package.h" 8#include "common/param_package.h"
10#include "input_common/analog_from_button.h" 9#include "input_common/analog_from_button.h"
11#include "input_common/gcadapter/gc_poller.h" 10#include "input_common/gcadapter/gc_poller.h"
@@ -44,10 +43,7 @@ void Init() {
44#ifdef HAVE_SDL2 43#ifdef HAVE_SDL2
45 sdl = SDL::Init(); 44 sdl = SDL::Init();
46#endif 45#endif
47 /*
48
49 udp = CemuhookUDP::Init(); 46 udp = CemuhookUDP::Init();
50 */
51} 47}
52 48
53void Shutdown() { 49void Shutdown() {
diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp
index b7120311a..d4cdf76a3 100644
--- a/src/input_common/motion_emu.cpp
+++ b/src/input_common/motion_emu.cpp
@@ -22,8 +22,7 @@ public:
22 : update_millisecond(update_millisecond), 22 : update_millisecond(update_millisecond),
23 update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>( 23 update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>(
24 std::chrono::milliseconds(update_millisecond))), 24 std::chrono::milliseconds(update_millisecond))),
25 sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) { 25 sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {}
26 }
27 26
28 ~MotionEmuDevice() { 27 ~MotionEmuDevice() {
29 if (motion_emu_thread.joinable()) { 28 if (motion_emu_thread.joinable()) {
@@ -146,7 +145,7 @@ std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackag
146 // Previously created device is disconnected here. Having two motion devices for 3DS is not 145 // Previously created device is disconnected here. Having two motion devices for 3DS is not
147 // expected. 146 // expected.
148 current_device = device_wrapper->device; 147 current_device = device_wrapper->device;
149 return std::move(device_wrapper); 148 return device_wrapper;
150} 149}
151 150
152void MotionEmu::BeginTilt(int x, int y) { 151void MotionEmu::BeginTilt(int x, int y) {
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 3c1820c4a..6b264f2a6 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -49,8 +49,7 @@ static int SDLEventWatcher(void* user_data, SDL_Event* event) {
49class SDLJoystick { 49class SDLJoystick {
50public: 50public:
51 SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick) 51 SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick)
52 : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose} { 52 : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose} {}
53 }
54 53
55 void SetButton(int button, bool value) { 54 void SetButton(int button, bool value) {
56 std::lock_guard lock{mutex}; 55 std::lock_guard lock{mutex};
@@ -98,7 +97,6 @@ public:
98 std::lock_guard lock{mutex}; 97 std::lock_guard lock{mutex};
99 return (state.hats.at(hat) & direction) != 0; 98 return (state.hats.at(hat) & direction) != 0;
100 } 99 }
101
102 /** 100 /**
103 * The guid of the joystick 101 * The guid of the joystick
104 */ 102 */
@@ -127,7 +125,6 @@ private:
127 std::unordered_map<int, Sint16> axes; 125 std::unordered_map<int, Sint16> axes;
128 std::unordered_map<int, Uint8> hats; 126 std::unordered_map<int, Uint8> hats;
129 } state; 127 } state;
130
131 std::string guid; 128 std::string guid;
132 int port; 129 int port;
133 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick; 130 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
@@ -158,8 +155,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_
158 if (map_it != joystick_map.end()) { 155 if (map_it != joystick_map.end()) {
159 const auto vec_it = 156 const auto vec_it =
160 std::find_if(map_it->second.begin(), map_it->second.end(), 157 std::find_if(map_it->second.begin(), map_it->second.end(),
161 [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) 158 [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) {
162 {
163 return sdl_joystick == joystick->GetSDLJoystick(); 159 return sdl_joystick == joystick->GetSDLJoystick();
164 }); 160 });
165 if (vec_it != map_it->second.end()) { 161 if (vec_it != map_it->second.end()) {
@@ -170,8 +166,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_
170 166
171 // Search for a SDLJoystick without a mapped SDL_Joystick... 167 // Search for a SDLJoystick without a mapped SDL_Joystick...
172 const auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(), 168 const auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(),
173 [](const std::shared_ptr<SDLJoystick>& joystick) 169 [](const std::shared_ptr<SDLJoystick>& joystick) {
174 {
175 return !joystick->GetSDLJoystick(); 170 return !joystick->GetSDLJoystick();
176 }); 171 });
177 if (nullptr_it != map_it->second.end()) { 172 if (nullptr_it != map_it->second.end()) {
@@ -228,8 +223,7 @@ void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
228 const auto& joystick_guid_list = joystick_map[guid]; 223 const auto& joystick_guid_list = joystick_map[guid];
229 const auto joystick_it = 224 const auto joystick_it =
230 std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(), 225 std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(),
231 [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) 226 [&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) {
232 {
233 return joystick->GetSDLJoystick() == sdl_joystick; 227 return joystick->GetSDLJoystick() == sdl_joystick;
234 }); 228 });
235 joystick = *joystick_it; 229 joystick = *joystick_it;
@@ -285,8 +279,7 @@ void SDLState::CloseJoysticks() {
285class SDLButton final : public Input::ButtonDevice { 279class SDLButton final : public Input::ButtonDevice {
286public: 280public:
287 explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_) 281 explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_)
288 : joystick(std::move(joystick_)), button(button_) { 282 : joystick(std::move(joystick_)), button(button_) {}
289 }
290 283
291 bool GetStatus() const override { 284 bool GetStatus() const override {
292 return joystick->GetButton(button); 285 return joystick->GetButton(button);
@@ -300,8 +293,7 @@ private:
300class SDLDirectionButton final : public Input::ButtonDevice { 293class SDLDirectionButton final : public Input::ButtonDevice {
301public: 294public:
302 explicit SDLDirectionButton(std::shared_ptr<SDLJoystick> joystick_, int hat_, Uint8 direction_) 295 explicit SDLDirectionButton(std::shared_ptr<SDLJoystick> joystick_, int hat_, Uint8 direction_)
303 : joystick(std::move(joystick_)), hat(hat_), direction(direction_) { 296 : joystick(std::move(joystick_)), hat(hat_), direction(direction_) {}
304 }
305 297
306 bool GetStatus() const override { 298 bool GetStatus() const override {
307 return joystick->GetHatDirection(hat, direction); 299 return joystick->GetHatDirection(hat, direction);
@@ -318,8 +310,7 @@ public:
318 explicit SDLAxisButton(std::shared_ptr<SDLJoystick> joystick_, int axis_, float threshold_, 310 explicit SDLAxisButton(std::shared_ptr<SDLJoystick> joystick_, int axis_, float threshold_,
319 bool trigger_if_greater_) 311 bool trigger_if_greater_)
320 : joystick(std::move(joystick_)), axis(axis_), threshold(threshold_), 312 : joystick(std::move(joystick_)), axis(axis_), threshold(threshold_),
321 trigger_if_greater(trigger_if_greater_) { 313 trigger_if_greater(trigger_if_greater_) {}
322 }
323 314
324 bool GetStatus() const override { 315 bool GetStatus() const override {
325 const float axis_value = joystick->GetAxis(axis); 316 const float axis_value = joystick->GetAxis(axis);
@@ -339,8 +330,7 @@ private:
339class SDLAnalog final : public Input::AnalogDevice { 330class SDLAnalog final : public Input::AnalogDevice {
340public: 331public:
341 SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, float deadzone_) 332 SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, float deadzone_)
342 : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) { 333 : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {}
343 }
344 334
345 std::tuple<float, float> GetStatus() const override { 335 std::tuple<float, float> GetStatus() const override {
346 const auto [x, y] = joystick->GetAnalog(axis_x, axis_y); 336 const auto [x, y] = joystick->GetAnalog(axis_x, axis_y);
@@ -378,9 +368,7 @@ private:
378/// A button device factory that creates button devices from SDL joystick 368/// A button device factory that creates button devices from SDL joystick
379class SDLButtonFactory final : public Input::Factory<Input::ButtonDevice> { 369class SDLButtonFactory final : public Input::Factory<Input::ButtonDevice> {
380public: 370public:
381 explicit SDLButtonFactory(SDLState& state_) 371 explicit SDLButtonFactory(SDLState& state_) : state(state_) {}
382 : state(state_) {
383 }
384 372
385 /** 373 /**
386 * Creates a button device from a joystick button 374 * Creates a button device from a joystick button
@@ -455,9 +443,7 @@ private:
455/// An analog device factory that creates analog devices from SDL joystick 443/// An analog device factory that creates analog devices from SDL joystick
456class SDLAnalogFactory final : public Input::Factory<Input::AnalogDevice> { 444class SDLAnalogFactory final : public Input::Factory<Input::AnalogDevice> {
457public: 445public:
458 explicit SDLAnalogFactory(SDLState& state_) 446 explicit SDLAnalogFactory(SDLState& state_) : state(state_) {}
459 : state(state_) {
460 }
461 447
462 /** 448 /**
463 * Creates analog device from joystick axes 449 * Creates analog device from joystick axes
@@ -505,8 +491,7 @@ SDLState::SDLState() {
505 491
506 initialized = true; 492 initialized = true;
507 if (start_thread) { 493 if (start_thread) {
508 poll_thread = std::thread([this] 494 poll_thread = std::thread([this] {
509 {
510 using namespace std::chrono_literals; 495 using namespace std::chrono_literals;
511 while (initialized) { 496 while (initialized) {
512 SDL_PumpEvents(); 497 SDL_PumpEvents();
@@ -592,9 +577,7 @@ namespace Polling {
592 577
593class SDLPoller : public InputCommon::Polling::DevicePoller { 578class SDLPoller : public InputCommon::Polling::DevicePoller {
594public: 579public:
595 explicit SDLPoller(SDLState& state_) 580 explicit SDLPoller(SDLState& state_) : state(state_) {}
596 : state(state_) {
597 }
598 581
599 void Start() override { 582 void Start() override {
600 state.event_queue.Clear(); 583 state.event_queue.Clear();
@@ -611,9 +594,7 @@ protected:
611 594
612class SDLButtonPoller final : public SDLPoller { 595class SDLButtonPoller final : public SDLPoller {
613public: 596public:
614 explicit SDLButtonPoller(SDLState& state_) 597 explicit SDLButtonPoller(SDLState& state_) : SDLPoller(state_) {}
615 : SDLPoller(state_) {
616 }
617 598
618 Common::ParamPackage GetNextInput() override { 599 Common::ParamPackage GetNextInput() override {
619 SDL_Event event; 600 SDL_Event event;
@@ -622,7 +603,8 @@ public:
622 case SDL_JOYAXISMOTION: 603 case SDL_JOYAXISMOTION:
623 if (std::abs(event.jaxis.value / 32767.0) < 0.5) { 604 if (std::abs(event.jaxis.value / 32767.0) < 0.5) {
624 break; 605 break;
625 }[[fallthrough]]; 606 }
607 [[fallthrough]];
626 case SDL_JOYBUTTONUP: 608 case SDL_JOYBUTTONUP:
627 case SDL_JOYHATMOTION: 609 case SDL_JOYHATMOTION:
628 return SDLEventToButtonParamPackage(state, event); 610 return SDLEventToButtonParamPackage(state, event);
@@ -634,9 +616,7 @@ public:
634 616
635class SDLAnalogPoller final : public SDLPoller { 617class SDLAnalogPoller final : public SDLPoller {
636public: 618public:
637 explicit SDLAnalogPoller(SDLState& state_) 619 explicit SDLAnalogPoller(SDLState& state_) : SDLPoller(state_) {}
638 : SDLPoller(state_) {
639 }
640 620
641 void Start() override { 621 void Start() override {
642 SDLPoller::Start(); 622 SDLPoller::Start();
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp
index befa4c86d..da5227058 100644
--- a/src/input_common/udp/client.cpp
+++ b/src/input_common/udp/client.cpp
@@ -59,8 +59,7 @@ public:
59 void StartReceive() { 59 void StartReceive() {
60 socket.async_receive_from( 60 socket.async_receive_from(
61 boost::asio::buffer(receive_buffer), receive_endpoint, 61 boost::asio::buffer(receive_buffer), receive_endpoint,
62 [this](const boost::system::error_code& error, std::size_t bytes_transferred) 62 [this](const boost::system::error_code& error, std::size_t bytes_transferred) {
63 {
64 HandleReceive(error, bytes_transferred); 63 HandleReceive(error, bytes_transferred);
65 }); 64 });
66 } 65 }
@@ -212,27 +211,21 @@ void Client::StartCommunication(const std::string& host, u16 port, u8 pad_index,
212void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, 211void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id,
213 std::function<void()> success_callback, 212 std::function<void()> success_callback,
214 std::function<void()> failure_callback) { 213 std::function<void()> failure_callback) {
215 std::thread([=] 214 std::thread([=] {
216 { 215 Common::Event success_event;
217 Common::Event success_event; 216 SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
218 SocketCallback callback{[](Response::Version version) 217 [&](Response::PadData data) { success_event.Set(); }};
219 { 218 Socket socket{host, port, pad_index, client_id, std::move(callback)};
220 }, 219 std::thread worker_thread{SocketLoop, &socket};
221 [](Response::PortInfo info) 220 bool result = success_event.WaitFor(std::chrono::seconds(8));
222 { 221 socket.Stop();
223 }, 222 worker_thread.join();
224 [&](Response::PadData data) { success_event.Set(); }}; 223 if (result) {
225 Socket socket{host, port, pad_index, client_id, std::move(callback)}; 224 success_callback();
226 std::thread worker_thread{SocketLoop, &socket}; 225 } else {
227 bool result = success_event.WaitFor(std::chrono::seconds(8)); 226 failure_callback();
228 socket.Stop(); 227 }
229 worker_thread.join(); 228 })
230 if (result) {
231 success_callback();
232 } else {
233 failure_callback();
234 }
235 })
236 .detach(); 229 .detach();
237} 230}
238 231
@@ -241,60 +234,53 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
241 std::function<void(Status)> status_callback, 234 std::function<void(Status)> status_callback,
242 std::function<void(u16, u16, u16, u16)> data_callback) { 235 std::function<void(u16, u16, u16, u16)> data_callback) {
243 236
244 std::thread([=] 237 std::thread([=] {
245 { 238 constexpr u16 CALIBRATION_THRESHOLD = 100;
246 constexpr u16 CALIBRATION_THRESHOLD = 100; 239
247 240 u16 min_x{UINT16_MAX};
248 u16 min_x{UINT16_MAX}; 241 u16 min_y{UINT16_MAX};
249 u16 min_y{UINT16_MAX}; 242 u16 max_x{};
250 u16 max_x{}; 243 u16 max_y{};
251 u16 max_y{}; 244
252 245 Status current_status{Status::Initialized};
253 Status current_status{Status::Initialized}; 246 SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
254 SocketCallback callback{[](Response::Version version) 247 [&](Response::PadData data) {
255 { 248 if (current_status == Status::Initialized) {
256 }, 249 // Receiving data means the communication is ready now
257 [](Response::PortInfo info) 250 current_status = Status::Ready;
258 { 251 status_callback(current_status);
259 }, 252 }
260 [&](Response::PadData data) 253 if (!data.touch_1.is_active) {
261 { 254 return;
262 if (current_status == Status::Initialized) { 255 }
263 // Receiving data means the communication is ready now 256 LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x,
264 current_status = Status::Ready; 257 data.touch_1.y);
265 status_callback(current_status); 258 min_x = std::min(min_x, static_cast<u16>(data.touch_1.x));
266 } 259 min_y = std::min(min_y, static_cast<u16>(data.touch_1.y));
267 if (!data.touch_1.is_active) { 260 if (current_status == Status::Ready) {
268 return; 261 // First touch - min data (min_x/min_y)
269 } 262 current_status = Status::Stage1Completed;
270 LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, 263 status_callback(current_status);
271 data.touch_1.y); 264 }
272 min_x = std::min(min_x, static_cast<u16>(data.touch_1.x)); 265 if (data.touch_1.x - min_x > CALIBRATION_THRESHOLD &&
273 min_y = std::min(min_y, static_cast<u16>(data.touch_1.y)); 266 data.touch_1.y - min_y > CALIBRATION_THRESHOLD) {
274 if (current_status == Status::Ready) { 267 // Set the current position as max value and finishes
275 // First touch - min data (min_x/min_y) 268 // configuration
276 current_status = Status::Stage1Completed; 269 max_x = data.touch_1.x;
277 status_callback(current_status); 270 max_y = data.touch_1.y;
278 } 271 current_status = Status::Completed;
279 if (data.touch_1.x - min_x > CALIBRATION_THRESHOLD && 272 data_callback(min_x, min_y, max_x, max_y);
280 data.touch_1.y - min_y > CALIBRATION_THRESHOLD) { 273 status_callback(current_status);
281 // Set the current position as max value and finishes 274
282 // configuration 275 complete_event.Set();
283 max_x = data.touch_1.x; 276 }
284 max_y = data.touch_1.y; 277 }};
285 current_status = Status::Completed; 278 Socket socket{host, port, pad_index, client_id, std::move(callback)};
286 data_callback(min_x, min_y, max_x, max_y); 279 std::thread worker_thread{SocketLoop, &socket};
287 status_callback(current_status); 280 complete_event.Wait();
288 281 socket.Stop();
289 complete_event.Set(); 282 worker_thread.join();
290 } 283 })
291 }};
292 Socket socket{host, port, pad_index, client_id, std::move(callback)};
293 std::thread worker_thread{SocketLoop, &socket};
294 complete_event.Wait();
295 socket.Stop();
296 worker_thread.join();
297 })
298 .detach(); 284 .detach();
299} 285}
300 286
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h
index b58e319b6..b8c654755 100644
--- a/src/input_common/udp/client.h
+++ b/src/input_common/udp/client.h
@@ -40,7 +40,6 @@ struct DeviceStatus {
40 u16 max_x{}; 40 u16 max_x{};
41 u16 max_y{}; 41 u16 max_y{};
42 }; 42 };
43
44 std::optional<CalibrationData> touch_calibration; 43 std::optional<CalibrationData> touch_calibration;
45}; 44};
46 45
@@ -73,7 +72,6 @@ public:
73 Stage1Completed, 72 Stage1Completed,
74 Completed, 73 Completed,
75 }; 74 };
76
77 /** 75 /**
78 * Constructs and starts the job with the specified parameter. 76 * Constructs and starts the job with the specified parameter.
79 * 77 *
diff --git a/src/input_common/udp/protocol.h b/src/input_common/udp/protocol.h
index 2b31846db..3ba4d1fc8 100644
--- a/src/input_common/udp/protocol.h
+++ b/src/input_common/udp/protocol.h
@@ -35,7 +35,6 @@ struct Header {
35 ///> the data 35 ///> the data
36 Type type{}; 36 Type type{};
37}; 37};
38
39static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size"); 38static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size");
40static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable"); 39static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable");
41 40
@@ -55,9 +54,7 @@ constexpr Type GetMessageType();
55 54
56namespace Request { 55namespace Request {
57 56
58struct Version { 57struct Version {};
59};
60
61/** 58/**
62 * Requests the server to send information about what controllers are plugged into the ports 59 * Requests the server to send information about what controllers are plugged into the ports
63 * In citra's case, we only have one controller, so for simplicity's sake, we can just send a 60 * In citra's case, we only have one controller, so for simplicity's sake, we can just send a
@@ -65,14 +62,12 @@ struct Version {
65 * nice to make this configurable 62 * nice to make this configurable
66 */ 63 */
67constexpr u32 MAX_PORTS = 4; 64constexpr u32 MAX_PORTS = 4;
68
69struct PortInfo { 65struct PortInfo {
70 u32_le pad_count{}; ///> Number of ports to request data for 66 u32_le pad_count{}; ///> Number of ports to request data for
71 std::array<u8, MAX_PORTS> port; 67 std::array<u8, MAX_PORTS> port;
72}; 68};
73
74static_assert(std::is_trivially_copyable_v<PortInfo>, 69static_assert(std::is_trivially_copyable_v<PortInfo>,
75 "UDP Request PortInfo is not trivially copyable"); 70 "UDP Request PortInfo is not trivially copyable");
76 71
77/** 72/**
78 * Request the latest pad information from the server. If the server hasn't received this message 73 * Request the latest pad information from the server. If the server hasn't received this message
@@ -85,7 +80,6 @@ struct PadData {
85 Id, 80 Id,
86 Mac, 81 Mac,
87 }; 82 };
88
89 /// Determines which method will be used as a look up for the controller 83 /// Determines which method will be used as a look up for the controller
90 Flags flags{}; 84 Flags flags{};
91 /// Index of the port of the controller to retrieve data about 85 /// Index of the port of the controller to retrieve data about
@@ -93,10 +87,9 @@ struct PadData {
93 /// Mac address of the controller to retrieve data about 87 /// Mac address of the controller to retrieve data about
94 MacAddress mac; 88 MacAddress mac;
95}; 89};
96
97static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size"); 90static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size");
98static_assert(std::is_trivially_copyable_v<PadData>, 91static_assert(std::is_trivially_copyable_v<PadData>,
99 "UDP Request PadData is not trivially copyable"); 92 "UDP Request PadData is not trivially copyable");
100 93
101/** 94/**
102 * Creates a message with the proper header data that can be sent to the server. 95 * Creates a message with the proper header data that can be sent to the server.
@@ -121,10 +114,9 @@ namespace Response {
121struct Version { 114struct Version {
122 u16_le version{}; 115 u16_le version{};
123}; 116};
124
125static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size"); 117static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size");
126static_assert(std::is_trivially_copyable_v<Version>, 118static_assert(std::is_trivially_copyable_v<Version>,
127 "UDP Response Version is not trivially copyable"); 119 "UDP Response Version is not trivially copyable");
128 120
129struct PortInfo { 121struct PortInfo {
130 u8 id{}; 122 u8 id{};
@@ -135,10 +127,9 @@ struct PortInfo {
135 u8 battery{}; 127 u8 battery{};
136 u8 is_pad_active{}; 128 u8 is_pad_active{};
137}; 129};
138
139static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size"); 130static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size");
140static_assert(std::is_trivially_copyable_v<PortInfo>, 131static_assert(std::is_trivially_copyable_v<PortInfo>,
141 "UDP Response PortInfo is not trivially copyable"); 132 "UDP Response PortInfo is not trivially copyable");
142 133
143#pragma pack(push, 1) 134#pragma pack(push, 1)
144struct PadData { 135struct PadData {
@@ -215,16 +206,16 @@ struct PadData {
215 206
216static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size "); 207static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size ");
217static_assert(std::is_trivially_copyable_v<PadData>, 208static_assert(std::is_trivially_copyable_v<PadData>,
218 "UDP Response PadData is not trivially copyable"); 209 "UDP Response PadData is not trivially copyable");
219 210
220static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE, 211static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE,
221 "UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>"); 212 "UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>");
222 213
223static_assert(sizeof(PadData::AnalogButton) == 12, 214static_assert(sizeof(PadData::AnalogButton) == 12,
224 "UDP Response AnalogButton struct has wrong size "); 215 "UDP Response AnalogButton struct has wrong size ");
225static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size "); 216static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size ");
226static_assert(sizeof(PadData::Accelerometer) == 12, 217static_assert(sizeof(PadData::Accelerometer) == 12,
227 "UDP Response Accelerometer struct has wrong size "); 218 "UDP Response Accelerometer struct has wrong size ");
228static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size "); 219static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size ");
229 220
230/** 221/**
@@ -241,27 +232,22 @@ template <>
241constexpr Type GetMessageType<Request::Version>() { 232constexpr Type GetMessageType<Request::Version>() {
242 return Type::Version; 233 return Type::Version;
243} 234}
244
245template <> 235template <>
246constexpr Type GetMessageType<Request::PortInfo>() { 236constexpr Type GetMessageType<Request::PortInfo>() {
247 return Type::PortInfo; 237 return Type::PortInfo;
248} 238}
249
250template <> 239template <>
251constexpr Type GetMessageType<Request::PadData>() { 240constexpr Type GetMessageType<Request::PadData>() {
252 return Type::PadData; 241 return Type::PadData;
253} 242}
254
255template <> 243template <>
256constexpr Type GetMessageType<Response::Version>() { 244constexpr Type GetMessageType<Response::Version>() {
257 return Type::Version; 245 return Type::Version;
258} 246}
259
260template <> 247template <>
261constexpr Type GetMessageType<Response::PortInfo>() { 248constexpr Type GetMessageType<Response::PortInfo>() {
262 return Type::PortInfo; 249 return Type::PortInfo;
263} 250}
264
265template <> 251template <>
266constexpr Type GetMessageType<Response::PadData>() { 252constexpr Type GetMessageType<Response::PadData>() {
267 return Type::PadData; 253 return Type::PadData;
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp
index 343c3985e..8c6ef1394 100644
--- a/src/input_common/udp/udp.cpp
+++ b/src/input_common/udp/udp.cpp
@@ -16,10 +16,7 @@ namespace InputCommon::CemuhookUDP {
16 16
17class UDPTouchDevice final : public Input::TouchDevice { 17class UDPTouchDevice final : public Input::TouchDevice {
18public: 18public:
19 explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) 19 explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
20 : status(std::move(status_)) {
21 }
22
23 std::tuple<float, float, bool> GetStatus() const override { 20 std::tuple<float, float, bool> GetStatus() const override {
24 std::lock_guard guard(status->update_mutex); 21 std::lock_guard guard(status->update_mutex);
25 return status->touch_status; 22 return status->touch_status;
@@ -31,10 +28,7 @@ private:
31 28
32class UDPMotionDevice final : public Input::MotionDevice { 29class UDPMotionDevice final : public Input::MotionDevice {
33public: 30public:
34 explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) 31 explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
35 : status(std::move(status_)) {
36 }
37
38 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override { 32 std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override {
39 std::lock_guard guard(status->update_mutex); 33 std::lock_guard guard(status->update_mutex);
40 return status->motion_status; 34 return status->motion_status;
@@ -46,9 +40,7 @@ private:
46 40
47class UDPTouchFactory final : public Input::Factory<Input::TouchDevice> { 41class UDPTouchFactory final : public Input::Factory<Input::TouchDevice> {
48public: 42public:
49 explicit UDPTouchFactory(std::shared_ptr<DeviceStatus> status_) 43 explicit UDPTouchFactory(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
50 : status(std::move(status_)) {
51 }
52 44
53 std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override { 45 std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override {
54 { 46 {
@@ -69,9 +61,7 @@ private:
69 61
70class UDPMotionFactory final : public Input::Factory<Input::MotionDevice> { 62class UDPMotionFactory final : public Input::Factory<Input::MotionDevice> {
71public: 63public:
72 explicit UDPMotionFactory(std::shared_ptr<DeviceStatus> status_) 64 explicit UDPMotionFactory(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
73 : status(std::move(status_)) {
74 }
75 65
76 std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override { 66 std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override {
77 return std::make_unique<UDPMotionDevice>(status); 67 return std::make_unique<UDPMotionDevice>(status);