diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 88 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 5 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 11 |
3 files changed, 103 insertions, 1 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index c507c9891..89c148aba 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -15,7 +15,9 @@ | |||
| 15 | #endif | 15 | #endif |
| 16 | 16 | ||
| 17 | #include "common/logging/log.h" | 17 | #include "common/logging/log.h" |
| 18 | #include "common/param_package.h" | ||
| 18 | #include "input_common/gcadapter/gc_adapter.h" | 19 | #include "input_common/gcadapter/gc_adapter.h" |
| 20 | #include "input_common/settings.h" | ||
| 19 | 21 | ||
| 20 | namespace GCAdapter { | 22 | namespace GCAdapter { |
| 21 | 23 | ||
| @@ -292,6 +294,92 @@ void Adapter::Reset() { | |||
| 292 | } | 294 | } |
| 293 | } | 295 | } |
| 294 | 296 | ||
| 297 | std::vector<Common::ParamPackage> Adapter::GetInputDevices() const { | ||
| 298 | std::vector<Common::ParamPackage> devices; | ||
| 299 | for (std::size_t port = 0; port < state.size(); ++port) { | ||
| 300 | if (!DeviceConnected(port)) { | ||
| 301 | continue; | ||
| 302 | } | ||
| 303 | std::string name = fmt::format("Gamecube Controller {}", port); | ||
| 304 | devices.emplace_back(Common::ParamPackage{ | ||
| 305 | {"class", "gcpad"}, | ||
| 306 | {"display", std::move(name)}, | ||
| 307 | {"port", std::to_string(port)}, | ||
| 308 | }); | ||
| 309 | } | ||
| 310 | return devices; | ||
| 311 | } | ||
| 312 | |||
| 313 | InputCommon::ButtonMapping Adapter::GetButtonMappingForDevice( | ||
| 314 | const Common::ParamPackage& params) const { | ||
| 315 | // This list is missing ZL/ZR since those are not considered buttons. | ||
| 316 | // We will add those afterwards | ||
| 317 | // This list also excludes any button that can't be really mapped | ||
| 318 | static constexpr std::array<std::pair<Settings::NativeButton::Values, PadButton>, 12> | ||
| 319 | switch_to_gcadapter_button = { | ||
| 320 | std::pair{Settings::NativeButton::A, PadButton::PAD_BUTTON_A}, | ||
| 321 | {Settings::NativeButton::B, PadButton::PAD_BUTTON_B}, | ||
| 322 | {Settings::NativeButton::X, PadButton::PAD_BUTTON_X}, | ||
| 323 | {Settings::NativeButton::Y, PadButton::PAD_BUTTON_Y}, | ||
| 324 | {Settings::NativeButton::Plus, PadButton::PAD_BUTTON_START}, | ||
| 325 | {Settings::NativeButton::DLeft, PadButton::PAD_BUTTON_LEFT}, | ||
| 326 | {Settings::NativeButton::DUp, PadButton::PAD_BUTTON_UP}, | ||
| 327 | {Settings::NativeButton::DRight, PadButton::PAD_BUTTON_RIGHT}, | ||
| 328 | {Settings::NativeButton::DDown, PadButton::PAD_BUTTON_DOWN}, | ||
| 329 | {Settings::NativeButton::SL, PadButton::PAD_TRIGGER_L}, | ||
| 330 | {Settings::NativeButton::SR, PadButton::PAD_TRIGGER_R}, | ||
| 331 | {Settings::NativeButton::R, PadButton::PAD_TRIGGER_Z}, | ||
| 332 | }; | ||
| 333 | if (!params.Has("port")) { | ||
| 334 | return {}; | ||
| 335 | } | ||
| 336 | |||
| 337 | InputCommon::ButtonMapping mapping{}; | ||
| 338 | for (const auto& [switch_button, gcadapter_button] : switch_to_gcadapter_button) { | ||
| 339 | Common::ParamPackage button_params({{"engine", "gcpad"}}); | ||
| 340 | button_params.Set("port", params.Get("port", 0)); | ||
| 341 | button_params.Set("button", static_cast<int>(gcadapter_button)); | ||
| 342 | mapping.insert_or_assign(switch_button, std::move(button_params)); | ||
| 343 | } | ||
| 344 | |||
| 345 | // Add the missing bindings for ZL/ZR | ||
| 346 | static constexpr std::array<std::pair<Settings::NativeButton::Values, PadAxes>, 2> | ||
| 347 | switch_to_gcadapter_axis = { | ||
| 348 | std::pair{Settings::NativeButton::ZL, PadAxes::TriggerLeft}, | ||
| 349 | {Settings::NativeButton::ZR, PadAxes::TriggerRight}, | ||
| 350 | }; | ||
| 351 | for (const auto& [switch_button, gcadapter_axis] : switch_to_gcadapter_axis) { | ||
| 352 | Common::ParamPackage button_params({{"engine", "gcpad"}}); | ||
| 353 | button_params.Set("port", params.Get("port", 0)); | ||
| 354 | button_params.Set("button", static_cast<int>(PadButton::PAD_STICK)); | ||
| 355 | button_params.Set("axis", static_cast<int>(gcadapter_axis)); | ||
| 356 | mapping.insert_or_assign(switch_button, std::move(button_params)); | ||
| 357 | } | ||
| 358 | return mapping; | ||
| 359 | } | ||
| 360 | |||
| 361 | InputCommon::AnalogMapping Adapter::GetAnalogMappingForDevice( | ||
| 362 | const Common::ParamPackage& params) const { | ||
| 363 | if (!params.Has("port")) { | ||
| 364 | return {}; | ||
| 365 | } | ||
| 366 | |||
| 367 | InputCommon::AnalogMapping mapping = {}; | ||
| 368 | Common::ParamPackage left_analog_params; | ||
| 369 | left_analog_params.Set("engine", "gcpad"); | ||
| 370 | left_analog_params.Set("port", params.Get("port", 0)); | ||
| 371 | left_analog_params.Set("axis_x", static_cast<int>(PadAxes::StickX)); | ||
| 372 | left_analog_params.Set("axis_y", static_cast<int>(PadAxes::StickY)); | ||
| 373 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params)); | ||
| 374 | Common::ParamPackage right_analog_params; | ||
| 375 | right_analog_params.Set("engine", "gcpad"); | ||
| 376 | right_analog_params.Set("port", params.Get("port", 0)); | ||
| 377 | right_analog_params.Set("axis_x", static_cast<int>(PadAxes::SubstickX)); | ||
| 378 | right_analog_params.Set("axis_y", static_cast<int>(PadAxes::SubstickY)); | ||
| 379 | mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params)); | ||
| 380 | return mapping; | ||
| 381 | } | ||
| 382 | |||
| 295 | bool Adapter::DeviceConnected(std::size_t port) const { | 383 | bool Adapter::DeviceConnected(std::size_t port) const { |
| 296 | return adapter_controllers_status[port] != ControllerTypes::None; | 384 | return adapter_controllers_status[port] != ControllerTypes::None; |
| 297 | } | 385 | } |
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 20e97d283..75bf9fe74 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <unordered_map> | 10 | #include <unordered_map> |
| 11 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 12 | #include "common/threadsafe_queue.h" | 12 | #include "common/threadsafe_queue.h" |
| 13 | #include "input_common/main.h" | ||
| 13 | 14 | ||
| 14 | struct libusb_context; | 15 | struct libusb_context; |
| 15 | struct libusb_device; | 16 | struct libusb_device; |
| @@ -75,6 +76,10 @@ public: | |||
| 75 | void BeginConfiguration(); | 76 | void BeginConfiguration(); |
| 76 | void EndConfiguration(); | 77 | void EndConfiguration(); |
| 77 | 78 | ||
| 79 | std::vector<Common::ParamPackage> GetInputDevices() const; | ||
| 80 | InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const; | ||
| 81 | InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const; | ||
| 82 | |||
| 78 | /// Returns true if there is a device connected to port | 83 | /// Returns true if there is a device connected to port |
| 79 | bool DeviceConnected(std::size_t port) const; | 84 | bool DeviceConnected(std::size_t port) const; |
| 80 | 85 | ||
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 062ec66b5..8da829132 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -22,7 +22,7 @@ namespace InputCommon { | |||
| 22 | 22 | ||
| 23 | struct InputSubsystem::Impl { | 23 | struct InputSubsystem::Impl { |
| 24 | void Initialize() { | 24 | void Initialize() { |
| 25 | auto gcadapter = std::make_shared<GCAdapter::Adapter>(); | 25 | gcadapter = std::make_shared<GCAdapter::Adapter>(); |
| 26 | gcbuttons = std::make_shared<GCButtonFactory>(gcadapter); | 26 | gcbuttons = std::make_shared<GCButtonFactory>(gcadapter); |
| 27 | Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); | 27 | Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); |
| 28 | gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); | 28 | gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); |
| @@ -82,6 +82,8 @@ struct InputSubsystem::Impl { | |||
| 82 | #endif | 82 | #endif |
| 83 | auto udp_devices = udp->GetInputDevices(); | 83 | auto udp_devices = udp->GetInputDevices(); |
| 84 | devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); | 84 | devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); |
| 85 | auto gcpad_devices = gcadapter->GetInputDevices(); | ||
| 86 | devices.insert(devices.end(), gcpad_devices.begin(), gcpad_devices.end()); | ||
| 85 | return devices; | 87 | return devices; |
| 86 | } | 88 | } |
| 87 | 89 | ||
| @@ -94,6 +96,9 @@ struct InputSubsystem::Impl { | |||
| 94 | // TODO consider returning the SDL key codes for the default keybindings | 96 | // TODO consider returning the SDL key codes for the default keybindings |
| 95 | return {}; | 97 | return {}; |
| 96 | } | 98 | } |
| 99 | if (params.Get("class", "") == "gcpad") { | ||
| 100 | return gcadapter->GetAnalogMappingForDevice(params); | ||
| 101 | } | ||
| 97 | #ifdef HAVE_SDL2 | 102 | #ifdef HAVE_SDL2 |
| 98 | if (params.Get("class", "") == "sdl") { | 103 | if (params.Get("class", "") == "sdl") { |
| 99 | return sdl->GetAnalogMappingForDevice(params); | 104 | return sdl->GetAnalogMappingForDevice(params); |
| @@ -111,6 +116,9 @@ struct InputSubsystem::Impl { | |||
| 111 | // TODO consider returning the SDL key codes for the default keybindings | 116 | // TODO consider returning the SDL key codes for the default keybindings |
| 112 | return {}; | 117 | return {}; |
| 113 | } | 118 | } |
| 119 | if (params.Get("class", "") == "gcpad") { | ||
| 120 | return gcadapter->GetButtonMappingForDevice(params); | ||
| 121 | } | ||
| 114 | #ifdef HAVE_SDL2 | 122 | #ifdef HAVE_SDL2 |
| 115 | if (params.Get("class", "") == "sdl") { | 123 | if (params.Get("class", "") == "sdl") { |
| 116 | return sdl->GetButtonMappingForDevice(params); | 124 | return sdl->GetButtonMappingForDevice(params); |
| @@ -141,6 +149,7 @@ struct InputSubsystem::Impl { | |||
| 141 | std::shared_ptr<UDPMotionFactory> udpmotion; | 149 | std::shared_ptr<UDPMotionFactory> udpmotion; |
| 142 | std::shared_ptr<UDPTouchFactory> udptouch; | 150 | std::shared_ptr<UDPTouchFactory> udptouch; |
| 143 | std::shared_ptr<CemuhookUDP::Client> udp; | 151 | std::shared_ptr<CemuhookUDP::Client> udp; |
| 152 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | ||
| 144 | }; | 153 | }; |
| 145 | 154 | ||
| 146 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} | 155 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} |