|
@@ -13,11 +13,11 @@
|
|
|
namespace InputCommon {
|
|
namespace InputCommon {
|
|
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
|
-std::string GetGUID(SDL_Joystick* joystick) {
|
|
|
|
|
|
|
+Common::UUID GetGUID(SDL_Joystick* joystick) {
|
|
|
const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
|
|
const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
|
|
|
- char guid_str[33];
|
|
|
|
|
- SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
|
|
|
|
|
- return guid_str;
|
|
|
|
|
|
|
+ std::array<u8, 16> data{};
|
|
|
|
|
+ std::memcpy(data.data(), guid.data, sizeof(data));
|
|
|
|
|
+ return Common::UUID{data};
|
|
|
}
|
|
}
|
|
|
} // Anonymous namespace
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
@@ -31,9 +31,9 @@ static int SDLEventWatcher(void* user_data, SDL_Event* event) {
|
|
|
|
|
|
|
|
class SDLJoystick {
|
|
class SDLJoystick {
|
|
|
public:
|
|
public:
|
|
|
- SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick,
|
|
|
|
|
|
|
+ SDLJoystick(Common::UUID guid_, int port_, SDL_Joystick* joystick,
|
|
|
SDL_GameController* game_controller)
|
|
SDL_GameController* game_controller)
|
|
|
- : guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose},
|
|
|
|
|
|
|
+ : guid{guid_}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose},
|
|
|
sdl_controller{game_controller, &SDL_GameControllerClose} {
|
|
sdl_controller{game_controller, &SDL_GameControllerClose} {
|
|
|
EnableMotion();
|
|
EnableMotion();
|
|
|
}
|
|
}
|
|
@@ -120,7 +120,7 @@ public:
|
|
|
*/
|
|
*/
|
|
|
const PadIdentifier GetPadIdentifier() const {
|
|
const PadIdentifier GetPadIdentifier() const {
|
|
|
return {
|
|
return {
|
|
|
- .guid = Common::UUID{guid},
|
|
|
|
|
|
|
+ .guid = guid,
|
|
|
.port = static_cast<std::size_t>(port),
|
|
.port = static_cast<std::size_t>(port),
|
|
|
.pad = 0,
|
|
.pad = 0,
|
|
|
};
|
|
};
|
|
@@ -129,7 +129,7 @@ public:
|
|
|
/**
|
|
/**
|
|
|
* The guid of the joystick
|
|
* The guid of the joystick
|
|
|
*/
|
|
*/
|
|
|
- const std::string& GetGUID() const {
|
|
|
|
|
|
|
+ const Common::UUID& GetGUID() const {
|
|
|
return guid;
|
|
return guid;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -228,7 +228,7 @@ public:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
- std::string guid;
|
|
|
|
|
|
|
+ Common::UUID guid;
|
|
|
int port;
|
|
int port;
|
|
|
std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
|
|
std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
|
|
|
std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller;
|
|
std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller;
|
|
@@ -240,7 +240,7 @@ private:
|
|
|
BasicMotion motion;
|
|
BasicMotion motion;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) {
|
|
|
|
|
|
|
+std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const Common::UUID& guid, int port) {
|
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
|
const auto it = joystick_map.find(guid);
|
|
const auto it = joystick_map.find(guid);
|
|
|
|
|
|
|
@@ -259,9 +259,13 @@ std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string&
|
|
|
return joystick_map[guid].emplace_back(std::move(joystick));
|
|
return joystick_map[guid].emplace_back(std::move(joystick));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) {
|
|
|
|
|
+ return GetSDLJoystickByGUID(Common::UUID{guid}, port);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
|
|
std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
|
|
|
auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
|
|
auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
|
|
|
- const std::string guid = GetGUID(sdl_joystick);
|
|
|
|
|
|
|
+ const auto guid = GetGUID(sdl_joystick);
|
|
|
|
|
|
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
|
const auto map_it = joystick_map.find(guid);
|
|
const auto map_it = joystick_map.find(guid);
|
|
@@ -295,7 +299,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const std::string guid = GetGUID(sdl_joystick);
|
|
|
|
|
|
|
+ const auto guid = GetGUID(sdl_joystick);
|
|
|
|
|
|
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
|
if (joystick_map.find(guid) == joystick_map.end()) {
|
|
if (joystick_map.find(guid) == joystick_map.end()) {
|
|
@@ -324,7 +328,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) {
|
|
void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) {
|
|
|
- const std::string guid = GetGUID(sdl_joystick);
|
|
|
|
|
|
|
+ const auto guid = GetGUID(sdl_joystick);
|
|
|
|
|
|
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
std::scoped_lock lock{joystick_map_mutex};
|
|
|
// This call to guid is safe since the joystick is guaranteed to be in the map
|
|
// 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 {
|
|
|
devices.emplace_back(Common::ParamPackage{
|
|
devices.emplace_back(Common::ParamPackage{
|
|
|
{"engine", GetEngineName()},
|
|
{"engine", GetEngineName()},
|
|
|
{"display", std::move(name)},
|
|
{"display", std::move(name)},
|
|
|
- {"guid", joystick->GetGUID()},
|
|
|
|
|
|
|
+ {"guid", joystick->GetGUID().RawString()},
|
|
|
{"port", std::to_string(joystick->GetPort())},
|
|
{"port", std::to_string(joystick->GetPort())},
|
|
|
});
|
|
});
|
|
|
if (joystick->IsJoyconLeft()) {
|
|
if (joystick->IsJoyconLeft()) {
|
|
@@ -493,8 +497,8 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
|
|
|
devices.emplace_back(Common::ParamPackage{
|
|
devices.emplace_back(Common::ParamPackage{
|
|
|
{"engine", GetEngineName()},
|
|
{"engine", GetEngineName()},
|
|
|
{"display", std::move(name)},
|
|
{"display", std::move(name)},
|
|
|
- {"guid", joystick->GetGUID()},
|
|
|
|
|
- {"guid2", joystick2->GetGUID()},
|
|
|
|
|
|
|
+ {"guid", joystick->GetGUID().RawString()},
|
|
|
|
|
+ {"guid2", joystick2->GetGUID().RawString()},
|
|
|
{"port", std::to_string(joystick->GetPort())},
|
|
{"port", std::to_string(joystick->GetPort())},
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -557,50 +561,50 @@ void SDLDriver::SendVibrations() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
|
|
|
|
|
|
|
+Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
|
|
|
s32 axis, float value) const {
|
|
s32 axis, float value) const {
|
|
|
Common::ParamPackage params{};
|
|
Common::ParamPackage params{};
|
|
|
params.Set("engine", GetEngineName());
|
|
params.Set("engine", GetEngineName());
|
|
|
params.Set("port", port);
|
|
params.Set("port", port);
|
|
|
- params.Set("guid", std::move(guid));
|
|
|
|
|
|
|
+ params.Set("guid", guid.RawString());
|
|
|
params.Set("axis", axis);
|
|
params.Set("axis", axis);
|
|
|
params.Set("threshold", "0.5");
|
|
params.Set("threshold", "0.5");
|
|
|
params.Set("invert", value < 0 ? "-" : "+");
|
|
params.Set("invert", value < 0 ? "-" : "+");
|
|
|
return params;
|
|
return params;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::string guid,
|
|
|
|
|
|
|
+Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, const Common::UUID& guid,
|
|
|
s32 button) const {
|
|
s32 button) const {
|
|
|
Common::ParamPackage params{};
|
|
Common::ParamPackage params{};
|
|
|
params.Set("engine", GetEngineName());
|
|
params.Set("engine", GetEngineName());
|
|
|
params.Set("port", port);
|
|
params.Set("port", port);
|
|
|
- params.Set("guid", std::move(guid));
|
|
|
|
|
|
|
+ params.Set("guid", guid.RawString());
|
|
|
params.Set("button", button);
|
|
params.Set("button", button);
|
|
|
return params;
|
|
return params;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::string guid, s32 hat,
|
|
|
|
|
- u8 value) const {
|
|
|
|
|
|
|
+Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, const Common::UUID& guid,
|
|
|
|
|
+ s32 hat, u8 value) const {
|
|
|
Common::ParamPackage params{};
|
|
Common::ParamPackage params{};
|
|
|
params.Set("engine", GetEngineName());
|
|
params.Set("engine", GetEngineName());
|
|
|
params.Set("port", port);
|
|
params.Set("port", port);
|
|
|
- params.Set("guid", std::move(guid));
|
|
|
|
|
|
|
+ params.Set("guid", guid.RawString());
|
|
|
params.Set("hat", hat);
|
|
params.Set("hat", hat);
|
|
|
params.Set("direction", GetHatButtonName(value));
|
|
params.Set("direction", GetHatButtonName(value));
|
|
|
return params;
|
|
return params;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Common::ParamPackage SDLDriver::BuildMotionParam(int port, std::string guid) const {
|
|
|
|
|
|
|
+Common::ParamPackage SDLDriver::BuildMotionParam(int port, const Common::UUID& guid) const {
|
|
|
Common::ParamPackage params{};
|
|
Common::ParamPackage params{};
|
|
|
params.Set("engine", GetEngineName());
|
|
params.Set("engine", GetEngineName());
|
|
|
params.Set("motion", 0);
|
|
params.Set("motion", 0);
|
|
|
params.Set("port", port);
|
|
params.Set("port", port);
|
|
|
- params.Set("guid", std::move(guid));
|
|
|
|
|
|
|
+ params.Set("guid", guid.RawString());
|
|
|
return params;
|
|
return params;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Common::ParamPackage SDLDriver::BuildParamPackageForBinding(
|
|
Common::ParamPackage SDLDriver::BuildParamPackageForBinding(
|
|
|
- int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const {
|
|
|
|
|
|
|
+ int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const {
|
|
|
switch (binding.bindType) {
|
|
switch (binding.bindType) {
|
|
|
case SDL_CONTROLLER_BINDTYPE_NONE:
|
|
case SDL_CONTROLLER_BINDTYPE_NONE:
|
|
|
break;
|
|
break;
|