diff options
| author | 2022-04-21 22:21:59 -0700 | |
|---|---|---|
| committer | 2022-04-21 22:21:59 -0700 | |
| commit | 764e5c7fe50bbbc64898fb657cfc5b1f8360454b (patch) | |
| tree | ee42eede68cb935595769104e0b94d55b1530141 /src | |
| parent | Merge pull request #8222 from german77/sixaxis_test (diff) | |
| parent | input_common: Map sticks correctly when mapped sideways (diff) | |
| download | yuzu-764e5c7fe50bbbc64898fb657cfc5b1f8360454b.tar.gz yuzu-764e5c7fe50bbbc64898fb657cfc5b1f8360454b.tar.xz yuzu-764e5c7fe50bbbc64898fb657cfc5b1f8360454b.zip | |
Merge pull request #7978 from german77/sideway
input_common: Map sticks correctly when mapped sideways
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/drivers/gc_adapter.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/drivers/gc_adapter.h | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 33 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.h | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.h | 2 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 5 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 29 | ||||
| -rw-r--r-- | src/input_common/main.h | 3 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 19 |
10 files changed, 127 insertions, 0 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 155caae42..8abd41726 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp | |||
| @@ -524,4 +524,20 @@ Common::Input::ButtonNames GCAdapter::GetUIName(const Common::ParamPackage& para | |||
| 524 | return Common::Input::ButtonNames::Invalid; | 524 | return Common::Input::ButtonNames::Invalid; |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | bool GCAdapter::IsStickInverted(const Common::ParamPackage& params) { | ||
| 528 | if (!params.Has("port")) { | ||
| 529 | return false; | ||
| 530 | } | ||
| 531 | |||
| 532 | const auto x_axis = static_cast<PadAxes>(params.Get("axis_x", 0)); | ||
| 533 | const auto y_axis = static_cast<PadAxes>(params.Get("axis_y", 0)); | ||
| 534 | if (x_axis != PadAxes::StickY && x_axis != PadAxes::SubstickY) { | ||
| 535 | return false; | ||
| 536 | } | ||
| 537 | if (y_axis != PadAxes::StickX && y_axis != PadAxes::SubstickX) { | ||
| 538 | return false; | ||
| 539 | } | ||
| 540 | return true; | ||
| 541 | } | ||
| 542 | |||
| 527 | } // namespace InputCommon | 543 | } // namespace InputCommon |
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h index 43ad58c85..894ab65a4 100644 --- a/src/input_common/drivers/gc_adapter.h +++ b/src/input_common/drivers/gc_adapter.h | |||
| @@ -35,6 +35,8 @@ public: | |||
| 35 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; | 35 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; |
| 36 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; | 36 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; |
| 37 | 37 | ||
| 38 | bool IsStickInverted(const Common::ParamPackage& params) override; | ||
| 39 | |||
| 38 | private: | 40 | private: |
| 39 | enum class PadButton { | 41 | enum class PadButton { |
| 40 | Undefined = 0x0000, | 42 | Undefined = 0x0000, |
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index b3e4c3f64..a5c63e74a 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -934,4 +934,37 @@ u8 SDLDriver::GetHatButtonId(const std::string& direction_name) const { | |||
| 934 | return direction; | 934 | return direction; |
| 935 | } | 935 | } |
| 936 | 936 | ||
| 937 | bool SDLDriver::IsStickInverted(const Common::ParamPackage& params) { | ||
| 938 | if (!params.Has("guid") || !params.Has("port")) { | ||
| 939 | return false; | ||
| 940 | } | ||
| 941 | const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0)); | ||
| 942 | if (joystick == nullptr) { | ||
| 943 | return false; | ||
| 944 | } | ||
| 945 | auto* controller = joystick->GetSDLGameController(); | ||
| 946 | if (controller == nullptr) { | ||
| 947 | return false; | ||
| 948 | } | ||
| 949 | |||
| 950 | const auto& axis_x = params.Get("axis_x", 0); | ||
| 951 | const auto& axis_y = params.Get("axis_y", 0); | ||
| 952 | const auto& binding_left_x = | ||
| 953 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX); | ||
| 954 | const auto& binding_right_x = | ||
| 955 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX); | ||
| 956 | const auto& binding_left_y = | ||
| 957 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY); | ||
| 958 | const auto& binding_right_y = | ||
| 959 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY); | ||
| 960 | |||
| 961 | if (axis_x != binding_left_y.value.axis && axis_x != binding_right_y.value.axis) { | ||
| 962 | return false; | ||
| 963 | } | ||
| 964 | if (axis_y != binding_left_x.value.axis && axis_y != binding_right_x.value.axis) { | ||
| 965 | return false; | ||
| 966 | } | ||
| 967 | return true; | ||
| 968 | } | ||
| 969 | |||
| 937 | } // namespace InputCommon | 970 | } // namespace InputCommon |
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index 4cde3606f..dcd0d1e64 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h | |||
| @@ -58,6 +58,8 @@ public: | |||
| 58 | std::string GetHatButtonName(u8 direction_value) const override; | 58 | std::string GetHatButtonName(u8 direction_value) const override; |
| 59 | u8 GetHatButtonId(const std::string& direction_name) const override; | 59 | u8 GetHatButtonId(const std::string& direction_name) const override; |
| 60 | 60 | ||
| 61 | bool IsStickInverted(const Common::ParamPackage& params) override; | ||
| 62 | |||
| 61 | Common::Input::VibrationError SetRumble( | 63 | Common::Input::VibrationError SetRumble( |
| 62 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override; | 64 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override; |
| 63 | 65 | ||
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 9780ead10..825262a07 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -547,6 +547,22 @@ Common::Input::ButtonNames UDPClient::GetUIName(const Common::ParamPackage& para | |||
| 547 | return Common::Input::ButtonNames::Invalid; | 547 | return Common::Input::ButtonNames::Invalid; |
| 548 | } | 548 | } |
| 549 | 549 | ||
| 550 | bool UDPClient::IsStickInverted(const Common::ParamPackage& params) { | ||
| 551 | if (!params.Has("guid") || !params.Has("port") || !params.Has("pad")) { | ||
| 552 | return false; | ||
| 553 | } | ||
| 554 | |||
| 555 | const auto x_axis = static_cast<PadAxes>(params.Get("axis_x", 0)); | ||
| 556 | const auto y_axis = static_cast<PadAxes>(params.Get("axis_y", 0)); | ||
| 557 | if (x_axis != PadAxes::LeftStickY && x_axis != PadAxes::RightStickY) { | ||
| 558 | return false; | ||
| 559 | } | ||
| 560 | if (y_axis != PadAxes::LeftStickX && y_axis != PadAxes::RightStickX) { | ||
| 561 | return false; | ||
| 562 | } | ||
| 563 | return true; | ||
| 564 | } | ||
| 565 | |||
| 550 | void TestCommunication(const std::string& host, u16 port, | 566 | void TestCommunication(const std::string& host, u16 port, |
| 551 | const std::function<void()>& success_callback, | 567 | const std::function<void()>& success_callback, |
| 552 | const std::function<void()>& failure_callback) { | 568 | const std::function<void()>& failure_callback) { |
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index c7cc7d846..dece2a45b 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -64,6 +64,8 @@ public: | |||
| 64 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; | 64 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; |
| 65 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; | 65 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; |
| 66 | 66 | ||
| 67 | bool IsStickInverted(const Common::ParamPackage& params) override; | ||
| 68 | |||
| 67 | private: | 69 | private: |
| 68 | enum class PadButton { | 70 | enum class PadButton { |
| 69 | Undefined = 0x0000, | 71 | Undefined = 0x0000, |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index f44e0799b..f94b7669c 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -157,6 +157,11 @@ public: | |||
| 157 | return 0; | 157 | return 0; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | /// Returns true if axis of a stick aren't mapped in the correct direction | ||
| 161 | virtual bool IsStickInverted([[maybe_unused]] const Common::ParamPackage& params) { | ||
| 162 | return false; | ||
| 163 | } | ||
| 164 | |||
| 160 | void PreSetController(const PadIdentifier& identifier); | 165 | void PreSetController(const PadIdentifier& identifier); |
| 161 | void PreSetButton(const PadIdentifier& identifier, int button); | 166 | void PreSetButton(const PadIdentifier& identifier, int button); |
| 162 | void PreSetHatButton(const PadIdentifier& identifier, int button); | 167 | void PreSetHatButton(const PadIdentifier& identifier, int button); |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 28769c6d8..21834fb6b 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -241,6 +241,28 @@ struct InputSubsystem::Impl { | |||
| 241 | return Common::Input::ButtonNames::Invalid; | 241 | return Common::Input::ButtonNames::Invalid; |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | bool IsStickInverted(const Common::ParamPackage& params) { | ||
| 245 | const std::string engine = params.Get("engine", ""); | ||
| 246 | if (engine == mouse->GetEngineName()) { | ||
| 247 | return mouse->IsStickInverted(params); | ||
| 248 | } | ||
| 249 | if (engine == gcadapter->GetEngineName()) { | ||
| 250 | return gcadapter->IsStickInverted(params); | ||
| 251 | } | ||
| 252 | if (engine == udp_client->GetEngineName()) { | ||
| 253 | return udp_client->IsStickInverted(params); | ||
| 254 | } | ||
| 255 | if (engine == tas_input->GetEngineName()) { | ||
| 256 | return tas_input->IsStickInverted(params); | ||
| 257 | } | ||
| 258 | #ifdef HAVE_SDL2 | ||
| 259 | if (engine == sdl->GetEngineName()) { | ||
| 260 | return sdl->IsStickInverted(params); | ||
| 261 | } | ||
| 262 | #endif | ||
| 263 | return false; | ||
| 264 | } | ||
| 265 | |||
| 244 | bool IsController(const Common::ParamPackage& params) { | 266 | bool IsController(const Common::ParamPackage& params) { |
| 245 | const std::string engine = params.Get("engine", ""); | 267 | const std::string engine = params.Get("engine", ""); |
| 246 | if (engine == mouse->GetEngineName()) { | 268 | if (engine == mouse->GetEngineName()) { |
| @@ -384,6 +406,13 @@ bool InputSubsystem::IsController(const Common::ParamPackage& params) const { | |||
| 384 | return impl->IsController(params); | 406 | return impl->IsController(params); |
| 385 | } | 407 | } |
| 386 | 408 | ||
| 409 | bool InputSubsystem::IsStickInverted(const Common::ParamPackage& params) const { | ||
| 410 | if (params.Has("axis_x") && params.Has("axis_y")) { | ||
| 411 | return impl->IsStickInverted(params); | ||
| 412 | } | ||
| 413 | return false; | ||
| 414 | } | ||
| 415 | |||
| 387 | void InputSubsystem::ReloadInputDevices() { | 416 | void InputSubsystem::ReloadInputDevices() { |
| 388 | impl->udp_client.get()->ReloadSockets(); | 417 | impl->udp_client.get()->ReloadSockets(); |
| 389 | } | 418 | } |
diff --git a/src/input_common/main.h b/src/input_common/main.h index baf107e0f..147c310c4 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -119,6 +119,9 @@ public: | |||
| 119 | /// Returns true if device is a controller. | 119 | /// Returns true if device is a controller. |
| 120 | [[nodiscard]] bool IsController(const Common::ParamPackage& params) const; | 120 | [[nodiscard]] bool IsController(const Common::ParamPackage& params) const; |
| 121 | 121 | ||
| 122 | /// Returns true if axis of a stick aren't mapped in the correct direction | ||
| 123 | [[nodiscard]] bool IsStickInverted(const Common::ParamPackage& device) const; | ||
| 124 | |||
| 122 | /// Reloads the input devices. | 125 | /// Reloads the input devices. |
| 123 | void ReloadInputDevices(); | 126 | void ReloadInputDevices(); |
| 124 | 127 | ||
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index a0f29d147..b4f5d172a 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -489,6 +489,25 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 489 | [=, this](const Common::ParamPackage& params) { | 489 | [=, this](const Common::ParamPackage& params) { |
| 490 | Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 490 | Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); |
| 491 | SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]); | 491 | SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]); |
| 492 | // Correct axis direction for inverted sticks | ||
| 493 | if (input_subsystem->IsStickInverted(param)) { | ||
| 494 | switch (analog_id) { | ||
| 495 | case Settings::NativeAnalog::LStick: { | ||
| 496 | const bool invert_value = param.Get("invert_x", "+") == "-"; | ||
| 497 | const std::string invert_str = invert_value ? "+" : "-"; | ||
| 498 | param.Set("invert_x", invert_str); | ||
| 499 | break; | ||
| 500 | } | ||
| 501 | case Settings::NativeAnalog::RStick: { | ||
| 502 | const bool invert_value = param.Get("invert_y", "+") == "-"; | ||
| 503 | const std::string invert_str = invert_value ? "+" : "-"; | ||
| 504 | param.Set("invert_y", invert_str); | ||
| 505 | break; | ||
| 506 | } | ||
| 507 | default: | ||
| 508 | break; | ||
| 509 | } | ||
| 510 | } | ||
| 492 | emulated_controller->SetStickParam(analog_id, param); | 511 | emulated_controller->SetStickParam(analog_id, param); |
| 493 | }, | 512 | }, |
| 494 | InputCommon::Polling::InputType::Stick); | 513 | InputCommon::Polling::InputType::Stick); |