diff options
Diffstat (limited to 'src/input_common')
| -rwxr-xr-x | src/input_common/analog_from_button.cpp | 22 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 28 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 25 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 26 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 5 |
5 files changed, 88 insertions, 18 deletions
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp index d748c1c04..40b516f85 100755 --- a/src/input_common/analog_from_button.cpp +++ b/src/input_common/analog_from_button.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <cmath> | 6 | #include <cmath> |
| 7 | #include <thread> | 7 | #include <thread> |
| 8 | #include "common/math_util.h" | 8 | #include "common/math_util.h" |
| 9 | #include "core/settings.h" | ||
| 9 | #include "input_common/analog_from_button.h" | 10 | #include "input_common/analog_from_button.h" |
| 10 | 11 | ||
| 11 | namespace InputCommon { | 12 | namespace InputCommon { |
| @@ -112,7 +113,26 @@ public: | |||
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | std::tuple<float, float> GetStatus() const override { | 115 | std::tuple<float, float> GetStatus() const override { |
| 115 | return std::make_tuple(std::cos(angle) * amplitude, std::sin(angle) * amplitude); | 116 | if (Settings::values.emulate_analog_keyboard) { |
| 117 | return std::make_tuple(std::cos(angle) * amplitude, std::sin(angle) * amplitude); | ||
| 118 | } | ||
| 119 | constexpr float SQRT_HALF = 0.707106781f; | ||
| 120 | int x = 0, y = 0; | ||
| 121 | if (right->GetStatus()) { | ||
| 122 | ++x; | ||
| 123 | } | ||
| 124 | if (left->GetStatus()) { | ||
| 125 | --x; | ||
| 126 | } | ||
| 127 | if (up->GetStatus()) { | ||
| 128 | ++y; | ||
| 129 | } | ||
| 130 | if (down->GetStatus()) { | ||
| 131 | --y; | ||
| 132 | } | ||
| 133 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | ||
| 134 | return std::make_tuple(static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF), | ||
| 135 | static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF)); | ||
| 116 | } | 136 | } |
| 117 | 137 | ||
| 118 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | 138 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 4d1052414..9670bdeb2 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -139,10 +139,10 @@ void GCButtonFactory::EndConfiguration() { | |||
| 139 | 139 | ||
| 140 | class GCAnalog final : public Input::AnalogDevice { | 140 | class GCAnalog final : public Input::AnalogDevice { |
| 141 | public: | 141 | public: |
| 142 | explicit GCAnalog(u32 port_, u32 axis_x_, u32 axis_y_, float deadzone_, | 142 | explicit GCAnalog(u32 port_, u32 axis_x_, u32 axis_y_, bool invert_x_, bool invert_y_, |
| 143 | const GCAdapter::Adapter* adapter, float range_) | 143 | float deadzone_, float range_, const GCAdapter::Adapter* adapter) |
| 144 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), | 144 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), invert_y(invert_y_), |
| 145 | range(range_) {} | 145 | deadzone(deadzone_), range(range_), gcadapter(adapter) {} |
| 146 | 146 | ||
| 147 | float GetAxis(u32 axis) const { | 147 | float GetAxis(u32 axis) const { |
| 148 | if (gcadapter->DeviceConnected(port)) { | 148 | if (gcadapter->DeviceConnected(port)) { |
| @@ -157,7 +157,12 @@ public: | |||
| 157 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { | 157 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |
| 158 | float x = GetAxis(analog_axis_x); | 158 | float x = GetAxis(analog_axis_x); |
| 159 | float y = GetAxis(analog_axis_y); | 159 | float y = GetAxis(analog_axis_y); |
| 160 | 160 | if (invert_x) { | |
| 161 | x = -x; | ||
| 162 | } | ||
| 163 | if (invert_y) { | ||
| 164 | y = -y; | ||
| 165 | } | ||
| 161 | // Make sure the coordinates are in the unit circle, | 166 | // Make sure the coordinates are in the unit circle, |
| 162 | // otherwise normalize it. | 167 | // otherwise normalize it. |
| 163 | float r = x * x + y * y; | 168 | float r = x * x + y * y; |
| @@ -200,9 +205,11 @@ private: | |||
| 200 | const u32 port; | 205 | const u32 port; |
| 201 | const u32 axis_x; | 206 | const u32 axis_x; |
| 202 | const u32 axis_y; | 207 | const u32 axis_y; |
| 208 | const bool invert_x; | ||
| 209 | const bool invert_y; | ||
| 203 | const float deadzone; | 210 | const float deadzone; |
| 204 | const GCAdapter::Adapter* gcadapter; | ||
| 205 | const float range; | 211 | const float range; |
| 212 | const GCAdapter::Adapter* gcadapter; | ||
| 206 | mutable std::mutex mutex; | 213 | mutable std::mutex mutex; |
| 207 | }; | 214 | }; |
| 208 | 215 | ||
| @@ -223,8 +230,13 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param | |||
| 223 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 230 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 224 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 231 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 225 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 232 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 233 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 234 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 235 | const bool invert_x = invert_x_value == "-"; | ||
| 236 | const bool invert_y = invert_y_value == "-"; | ||
| 226 | 237 | ||
| 227 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); | 238 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, invert_x, invert_y, deadzone, range, |
| 239 | adapter.get()); | ||
| 228 | } | 240 | } |
| 229 | 241 | ||
| 230 | void GCAnalogFactory::BeginConfiguration() { | 242 | void GCAnalogFactory::BeginConfiguration() { |
| @@ -282,6 +294,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 282 | params.Set("port", controller_number); | 294 | params.Set("port", controller_number); |
| 283 | params.Set("axis_x", analog_x_axis); | 295 | params.Set("axis_x", analog_x_axis); |
| 284 | params.Set("axis_y", analog_y_axis); | 296 | params.Set("axis_y", analog_y_axis); |
| 297 | params.Set("invert_x", "+"); | ||
| 298 | params.Set("invert_y", "+"); | ||
| 285 | analog_x_axis = -1; | 299 | analog_x_axis = -1; |
| 286 | analog_y_axis = -1; | 300 | analog_y_axis = -1; |
| 287 | controller_number = -1; | 301 | controller_number = -1; |
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index 7445ad3ad..508eb0c7d 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp | |||
| @@ -62,10 +62,10 @@ void MouseButtonFactory::EndConfiguration() { | |||
| 62 | 62 | ||
| 63 | class MouseAnalog final : public Input::AnalogDevice { | 63 | class MouseAnalog final : public Input::AnalogDevice { |
| 64 | public: | 64 | public: |
| 65 | explicit MouseAnalog(u32 port_, u32 axis_x_, u32 axis_y_, float deadzone_, float range_, | 65 | explicit MouseAnalog(u32 port_, u32 axis_x_, u32 axis_y_, bool invert_x_, bool invert_y_, |
| 66 | const MouseInput::Mouse* mouse_input_) | 66 | float deadzone_, float range_, const MouseInput::Mouse* mouse_input_) |
| 67 | : button(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), range(range_), | 67 | : button(port_), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), invert_y(invert_y_), |
| 68 | mouse_input(mouse_input_) {} | 68 | deadzone(deadzone_), range(range_), mouse_input(mouse_input_) {} |
| 69 | 69 | ||
| 70 | float GetAxis(u32 axis) const { | 70 | float GetAxis(u32 axis) const { |
| 71 | std::lock_guard lock{mutex}; | 71 | std::lock_guard lock{mutex}; |
| @@ -77,6 +77,12 @@ public: | |||
| 77 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { | 77 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |
| 78 | float x = GetAxis(analog_axis_x); | 78 | float x = GetAxis(analog_axis_x); |
| 79 | float y = GetAxis(analog_axis_y); | 79 | float y = GetAxis(analog_axis_y); |
| 80 | if (invert_x) { | ||
| 81 | x = -x; | ||
| 82 | } | ||
| 83 | if (invert_y) { | ||
| 84 | y = -y; | ||
| 85 | } | ||
| 80 | 86 | ||
| 81 | // Make sure the coordinates are in the unit circle, | 87 | // Make sure the coordinates are in the unit circle, |
| 82 | // otherwise normalize it. | 88 | // otherwise normalize it. |
| @@ -104,6 +110,8 @@ private: | |||
| 104 | const u32 button; | 110 | const u32 button; |
| 105 | const u32 axis_x; | 111 | const u32 axis_x; |
| 106 | const u32 axis_y; | 112 | const u32 axis_y; |
| 113 | const bool invert_x; | ||
| 114 | const bool invert_y; | ||
| 107 | const float deadzone; | 115 | const float deadzone; |
| 108 | const float range; | 116 | const float range; |
| 109 | const MouseInput::Mouse* mouse_input; | 117 | const MouseInput::Mouse* mouse_input; |
| @@ -128,8 +136,13 @@ std::unique_ptr<Input::AnalogDevice> MouseAnalogFactory::Create( | |||
| 128 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | 136 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 129 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 137 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 130 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 138 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 139 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 140 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 141 | const bool invert_x = invert_x_value == "-"; | ||
| 142 | const bool invert_y = invert_y_value == "-"; | ||
| 131 | 143 | ||
| 132 | return std::make_unique<MouseAnalog>(port, axis_x, axis_y, deadzone, range, mouse_input.get()); | 144 | return std::make_unique<MouseAnalog>(port, axis_x, axis_y, invert_x, invert_y, deadzone, range, |
| 145 | mouse_input.get()); | ||
| 133 | } | 146 | } |
| 134 | 147 | ||
| 135 | void MouseAnalogFactory::BeginConfiguration() { | 148 | void MouseAnalogFactory::BeginConfiguration() { |
| @@ -153,6 +166,8 @@ Common::ParamPackage MouseAnalogFactory::GetNextInput() const { | |||
| 153 | params.Set("port", static_cast<u16>(pad.button)); | 166 | params.Set("port", static_cast<u16>(pad.button)); |
| 154 | params.Set("axis_x", 0); | 167 | params.Set("axis_x", 0); |
| 155 | params.Set("axis_y", 1); | 168 | params.Set("axis_y", 1); |
| 169 | params.Set("invert_x", "+"); | ||
| 170 | params.Set("invert_y", "+"); | ||
| 156 | return params; | 171 | return params; |
| 157 | } | 172 | } |
| 158 | } | 173 | } |
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index d56b7587b..d32eb732a 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -352,13 +352,20 @@ private: | |||
| 352 | class SDLAnalog final : public Input::AnalogDevice { | 352 | class SDLAnalog final : public Input::AnalogDevice { |
| 353 | public: | 353 | public: |
| 354 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, | 354 | explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, |
| 355 | float deadzone_, float range_) | 355 | bool invert_x_, bool invert_y_, float deadzone_, float range_) |
| 356 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), | 356 | : joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_), |
| 357 | range(range_) {} | 357 | invert_y(invert_y_), deadzone(deadzone_), range(range_) {} |
| 358 | 358 | ||
| 359 | std::tuple<float, float> GetStatus() const override { | 359 | std::tuple<float, float> GetStatus() const override { |
| 360 | const auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range); | 360 | auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range); |
| 361 | const float r = std::sqrt((x * x) + (y * y)); | 361 | const float r = std::sqrt((x * x) + (y * y)); |
| 362 | if (invert_x) { | ||
| 363 | x = -x; | ||
| 364 | } | ||
| 365 | if (invert_y) { | ||
| 366 | y = -y; | ||
| 367 | } | ||
| 368 | |||
| 362 | if (r > deadzone) { | 369 | if (r > deadzone) { |
| 363 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), | 370 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), |
| 364 | y / r * (r - deadzone) / (1 - deadzone)); | 371 | y / r * (r - deadzone) / (1 - deadzone)); |
| @@ -386,6 +393,8 @@ private: | |||
| 386 | std::shared_ptr<SDLJoystick> joystick; | 393 | std::shared_ptr<SDLJoystick> joystick; |
| 387 | const int axis_x; | 394 | const int axis_x; |
| 388 | const int axis_y; | 395 | const int axis_y; |
| 396 | const bool invert_x; | ||
| 397 | const bool invert_y; | ||
| 389 | const float deadzone; | 398 | const float deadzone; |
| 390 | const float range; | 399 | const float range; |
| 391 | }; | 400 | }; |
| @@ -572,12 +581,17 @@ public: | |||
| 572 | const int axis_y = params.Get("axis_y", 1); | 581 | const int axis_y = params.Get("axis_y", 1); |
| 573 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 582 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 574 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 583 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 584 | const std::string invert_x_value = params.Get("invert_x", "+"); | ||
| 585 | const std::string invert_y_value = params.Get("invert_y", "+"); | ||
| 586 | const bool invert_x = invert_x_value == "-"; | ||
| 587 | const bool invert_y = invert_y_value == "-"; | ||
| 575 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 588 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 576 | 589 | ||
| 577 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash | 590 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash |
| 578 | joystick->SetAxis(axis_x, 0); | 591 | joystick->SetAxis(axis_x, 0); |
| 579 | joystick->SetAxis(axis_y, 0); | 592 | joystick->SetAxis(axis_y, 0); |
| 580 | return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, deadzone, range); | 593 | return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, invert_x, invert_y, deadzone, |
| 594 | range); | ||
| 581 | } | 595 | } |
| 582 | 596 | ||
| 583 | private: | 597 | private: |
| @@ -886,6 +900,8 @@ Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& gui | |||
| 886 | params.Set("guid", guid); | 900 | params.Set("guid", guid); |
| 887 | params.Set("axis_x", axis_x); | 901 | params.Set("axis_x", axis_x); |
| 888 | params.Set("axis_y", axis_y); | 902 | params.Set("axis_y", axis_y); |
| 903 | params.Set("invert_x", "+"); | ||
| 904 | params.Set("invert_y", "+"); | ||
| 889 | return params; | 905 | return params; |
| 890 | } | 906 | } |
| 891 | } // Anonymous namespace | 907 | } // Anonymous namespace |
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 17a9225d7..412d57896 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -225,6 +225,11 @@ void Client::OnPortInfo([[maybe_unused]] Response::PortInfo data) { | |||
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | void Client::OnPadData(Response::PadData data, std::size_t client) { | 227 | void Client::OnPadData(Response::PadData data, std::size_t client) { |
| 228 | // Accept packets only for the correct pad | ||
| 229 | if (static_cast<u8>(clients[client].pad_index) != data.info.id) { | ||
| 230 | return; | ||
| 231 | } | ||
| 232 | |||
| 228 | LOG_TRACE(Input, "PadData packet received"); | 233 | LOG_TRACE(Input, "PadData packet received"); |
| 229 | if (data.packet_counter == clients[client].packet_sequence) { | 234 | if (data.packet_counter == clients[client].packet_sequence) { |
| 230 | LOG_WARNING( | 235 | LOG_WARNING( |