summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/sdl_driver.cpp
diff options
context:
space:
mode:
authorGravatar Narr the Reg2022-06-06 19:39:22 -0500
committerGravatar Narr the Reg2022-06-06 19:56:37 -0500
commit28877cea31202bdadfee5e1871bc6725a7072b4f (patch)
tree0af1118659e28176bd1a4233705a92eb92e5b79b /src/input_common/drivers/sdl_driver.cpp
parentMerge pull request #8395 from german77/ir_stub (diff)
downloadyuzu-28877cea31202bdadfee5e1871bc6725a7072b4f.tar.gz
yuzu-28877cea31202bdadfee5e1871bc6725a7072b4f.tar.xz
yuzu-28877cea31202bdadfee5e1871bc6725a7072b4f.zip
input_common: Replace usage of string guid to common uuid
Diffstat (limited to 'src/input_common/drivers/sdl_driver.cpp')
-rw-r--r--src/input_common/drivers/sdl_driver.cpp56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index 1a14ef10b..446c027d3 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -13,11 +13,11 @@
13namespace InputCommon { 13namespace InputCommon {
14 14
15namespace { 15namespace {
16std::string GetGUID(SDL_Joystick* joystick) { 16Common::UUID GetGUID(SDL_Joystick* joystick) {
17 const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick); 17 const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
18 char guid_str[33]; 18 std::array<u8, 16> data{};
19 SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); 19 std::memcpy(data.data(), guid.data, sizeof(data));
20 return guid_str; 20 return Common::UUID{data};
21} 21}
22} // Anonymous namespace 22} // Anonymous namespace
23 23
@@ -31,9 +31,9 @@ static int SDLEventWatcher(void* user_data, SDL_Event* event) {
31 31
32class SDLJoystick { 32class SDLJoystick {
33public: 33public:
34 SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick, 34 SDLJoystick(Common::UUID guid_, int port_, SDL_Joystick* joystick,
35 SDL_GameController* game_controller) 35 SDL_GameController* game_controller)
36 : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose}, 36 : guid{guid_}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose},
37 sdl_controller{game_controller, &SDL_GameControllerClose} { 37 sdl_controller{game_controller, &SDL_GameControllerClose} {
38 EnableMotion(); 38 EnableMotion();
39 } 39 }
@@ -120,7 +120,7 @@ public:
120 */ 120 */
121 const PadIdentifier GetPadIdentifier() const { 121 const PadIdentifier GetPadIdentifier() const {
122 return { 122 return {
123 .guid = Common::UUID{guid}, 123 .guid = guid,
124 .port = static_cast<std::size_t>(port), 124 .port = static_cast<std::size_t>(port),
125 .pad = 0, 125 .pad = 0,
126 }; 126 };
@@ -129,7 +129,7 @@ public:
129 /** 129 /**
130 * The guid of the joystick 130 * The guid of the joystick
131 */ 131 */
132 const std::string& GetGUID() const { 132 const Common::UUID& GetGUID() const {
133 return guid; 133 return guid;
134 } 134 }
135 135
@@ -228,7 +228,7 @@ public:
228 } 228 }
229 229
230private: 230private:
231 std::string guid; 231 Common::UUID guid;
232 int port; 232 int port;
233 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick; 233 std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
234 std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller; 234 std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller;
@@ -240,7 +240,7 @@ private:
240 BasicMotion motion; 240 BasicMotion motion;
241}; 241};
242 242
243std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) { 243std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const Common::UUID& guid, int port) {
244 std::scoped_lock lock{joystick_map_mutex}; 244 std::scoped_lock lock{joystick_map_mutex};
245 const auto it = joystick_map.find(guid); 245 const auto it = joystick_map.find(guid);
246 246
@@ -259,9 +259,13 @@ std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string&
259 return joystick_map[guid].emplace_back(std::move(joystick)); 259 return joystick_map[guid].emplace_back(std::move(joystick));
260} 260}
261 261
262std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) {
263 return GetSDLJoystickByGUID(Common::UUID{guid}, port);
264}
265
262std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) { 266std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
263 auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id); 267 auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
264 const std::string guid = GetGUID(sdl_joystick); 268 const auto guid = GetGUID(sdl_joystick);
265 269
266 std::scoped_lock lock{joystick_map_mutex}; 270 std::scoped_lock lock{joystick_map_mutex};
267 const auto map_it = joystick_map.find(guid); 271 const auto map_it = joystick_map.find(guid);
@@ -295,7 +299,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
295 return; 299 return;
296 } 300 }
297 301
298 const std::string guid = GetGUID(sdl_joystick); 302 const auto guid = GetGUID(sdl_joystick);
299 303
300 std::scoped_lock lock{joystick_map_mutex}; 304 std::scoped_lock lock{joystick_map_mutex};
301 if (joystick_map.find(guid) == joystick_map.end()) { 305 if (joystick_map.find(guid) == joystick_map.end()) {
@@ -324,7 +328,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
324} 328}
325 329
326void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) { 330void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) {
327 const std::string guid = GetGUID(sdl_joystick); 331 const auto guid = GetGUID(sdl_joystick);
328 332
329 std::scoped_lock lock{joystick_map_mutex}; 333 std::scoped_lock lock{joystick_map_mutex};
330 // This call to guid is safe since the joystick is guaranteed to be in the map 334 // This call to guid is safe since the joystick is guaranteed to be in the map
@@ -470,7 +474,7 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
470 devices.emplace_back(Common::ParamPackage{ 474 devices.emplace_back(Common::ParamPackage{
471 {"engine", GetEngineName()}, 475 {"engine", GetEngineName()},
472 {"display", std::move(name)}, 476 {"display", std::move(name)},
473 {"guid", joystick->GetGUID()}, 477 {"guid", joystick->GetGUID().RawString()},
474 {"port", std::to_string(joystick->GetPort())}, 478 {"port", std::to_string(joystick->GetPort())},
475 }); 479 });
476 if (joystick->IsJoyconLeft()) { 480 if (joystick->IsJoyconLeft()) {
@@ -493,8 +497,8 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
493 devices.emplace_back(Common::ParamPackage{ 497 devices.emplace_back(Common::ParamPackage{
494 {"engine", GetEngineName()}, 498 {"engine", GetEngineName()},
495 {"display", std::move(name)}, 499 {"display", std::move(name)},
496 {"guid", joystick->GetGUID()}, 500 {"guid", joystick->GetGUID().RawString()},
497 {"guid2", joystick2->GetGUID()}, 501 {"guid2", joystick2->GetGUID().RawString()},
498 {"port", std::to_string(joystick->GetPort())}, 502 {"port", std::to_string(joystick->GetPort())},
499 }); 503 });
500 } 504 }
@@ -557,50 +561,50 @@ void SDLDriver::SendVibrations() {
557 } 561 }
558} 562}
559 563
560Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid, 564Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
561 s32 axis, float value) const { 565 s32 axis, float value) const {
562 Common::ParamPackage params{}; 566 Common::ParamPackage params{};
563 params.Set("engine", GetEngineName()); 567 params.Set("engine", GetEngineName());
564 params.Set("port", port); 568 params.Set("port", port);
565 params.Set("guid", std::move(guid)); 569 params.Set("guid", guid.RawString());
566 params.Set("axis", axis); 570 params.Set("axis", axis);
567 params.Set("threshold", "0.5"); 571 params.Set("threshold", "0.5");
568 params.Set("invert", value < 0 ? "-" : "+"); 572 params.Set("invert", value < 0 ? "-" : "+");
569 return params; 573 return params;
570} 574}
571 575
572Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::string guid, 576Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, const Common::UUID& guid,
573 s32 button) const { 577 s32 button) const {
574 Common::ParamPackage params{}; 578 Common::ParamPackage params{};
575 params.Set("engine", GetEngineName()); 579 params.Set("engine", GetEngineName());
576 params.Set("port", port); 580 params.Set("port", port);
577 params.Set("guid", std::move(guid)); 581 params.Set("guid", guid.RawString());
578 params.Set("button", button); 582 params.Set("button", button);
579 return params; 583 return params;
580} 584}
581 585
582Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::string guid, s32 hat, 586Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, const Common::UUID& guid,
583 u8 value) const { 587 s32 hat, u8 value) const {
584 Common::ParamPackage params{}; 588 Common::ParamPackage params{};
585 params.Set("engine", GetEngineName()); 589 params.Set("engine", GetEngineName());
586 params.Set("port", port); 590 params.Set("port", port);
587 params.Set("guid", std::move(guid)); 591 params.Set("guid", guid.RawString());
588 params.Set("hat", hat); 592 params.Set("hat", hat);
589 params.Set("direction", GetHatButtonName(value)); 593 params.Set("direction", GetHatButtonName(value));
590 return params; 594 return params;
591} 595}
592 596
593Common::ParamPackage SDLDriver::BuildMotionParam(int port, std::string guid) const { 597Common::ParamPackage SDLDriver::BuildMotionParam(int port, const Common::UUID& guid) const {
594 Common::ParamPackage params{}; 598 Common::ParamPackage params{};
595 params.Set("engine", GetEngineName()); 599 params.Set("engine", GetEngineName());
596 params.Set("motion", 0); 600 params.Set("motion", 0);
597 params.Set("port", port); 601 params.Set("port", port);
598 params.Set("guid", std::move(guid)); 602 params.Set("guid", guid.RawString());
599 return params; 603 return params;
600} 604}
601 605
602Common::ParamPackage SDLDriver::BuildParamPackageForBinding( 606Common::ParamPackage SDLDriver::BuildParamPackageForBinding(
603 int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const { 607 int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const {
604 switch (binding.bindType) { 608 switch (binding.bindType) {
605 case SDL_CONTROLLER_BINDTYPE_NONE: 609 case SDL_CONTROLLER_BINDTYPE_NONE:
606 break; 610 break;