diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/CMakeLists.txt | 12 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/input_common/helpers/stick_from_buttons.cpp (renamed from src/input_common/analog_from_button.cpp) | 142 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/input_common/helpers/stick_from_buttons.h (renamed from src/input_common/analog_from_button.h) | 8 | ||||
| -rw-r--r-- | src/input_common/helpers/touch_from_buttons.cpp | 70 | ||||
| -rw-r--r-- | src/input_common/helpers/touch_from_buttons.h (renamed from src/input_common/touch_from_button.h) | 7 | ||||
| -rw-r--r-- | src/input_common/helpers/udp_protocol.cpp (renamed from src/input_common/udp/protocol.cpp) | 2 | ||||
| -rw-r--r-- | src/input_common/helpers/udp_protocol.h (renamed from src/input_common/udp/protocol.h) | 0 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 8 | ||||
| -rw-r--r-- | src/input_common/touch_from_button.cpp | 53 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 2 |
10 files changed, 172 insertions, 132 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 72f1e0f4a..90e7618ce 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -1,8 +1,12 @@ | |||
| 1 | add_library(input_common STATIC | 1 | add_library(input_common STATIC |
| 2 | analog_from_button.cpp | ||
| 3 | analog_from_button.h | ||
| 4 | keyboard.cpp | 2 | keyboard.cpp |
| 5 | keyboard.h | 3 | keyboard.h |
| 4 | helpers/stick_from_buttons.cpp | ||
| 5 | helpers/stick_from_buttons.h | ||
| 6 | helpers/touch_from_buttons.cpp | ||
| 7 | helpers/touch_from_buttons.h | ||
| 8 | helpers/udp_protocol.cpp | ||
| 9 | helpers/udp_protocol.h | ||
| 6 | input_engine.cpp | 10 | input_engine.cpp |
| 7 | input_engine.h | 11 | input_engine.h |
| 8 | input_mapping.cpp | 12 | input_mapping.cpp |
| @@ -15,8 +19,6 @@ add_library(input_common STATIC | |||
| 15 | motion_from_button.h | 19 | motion_from_button.h |
| 16 | motion_input.cpp | 20 | motion_input.cpp |
| 17 | motion_input.h | 21 | motion_input.h |
| 18 | touch_from_button.cpp | ||
| 19 | touch_from_button.h | ||
| 20 | gcadapter/gc_adapter.cpp | 22 | gcadapter/gc_adapter.cpp |
| 21 | gcadapter/gc_adapter.h | 23 | gcadapter/gc_adapter.h |
| 22 | gcadapter/gc_poller.cpp | 24 | gcadapter/gc_poller.cpp |
| @@ -33,8 +35,6 @@ add_library(input_common STATIC | |||
| 33 | tas/tas_poller.h | 35 | tas/tas_poller.h |
| 34 | udp/client.cpp | 36 | udp/client.cpp |
| 35 | udp/client.h | 37 | udp/client.h |
| 36 | udp/protocol.cpp | ||
| 37 | udp/protocol.h | ||
| 38 | udp/udp.cpp | 38 | udp/udp.cpp |
| 39 | udp/udp.h | 39 | udp/udp.h |
| 40 | ) | 40 | ) |
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 2fafd077f..38f150746 100755..100644 --- a/src/input_common/analog_from_button.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp | |||
| @@ -2,32 +2,38 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | #include <chrono> | 5 | #include <chrono> |
| 7 | #include <cmath> | 6 | #include <cmath> |
| 8 | #include <thread> | ||
| 9 | #include "common/math_util.h" | 7 | #include "common/math_util.h" |
| 10 | #include "common/settings.h" | 8 | #include "common/settings.h" |
| 11 | #include "input_common/analog_from_button.h" | 9 | #include "input_common/helpers/stick_from_buttons.h" |
| 12 | 10 | ||
| 13 | namespace InputCommon { | 11 | namespace InputCommon { |
| 14 | 12 | ||
| 15 | class Analog final : public Input::AnalogDevice { | 13 | class Stick final : public Input::InputDevice { |
| 16 | public: | 14 | public: |
| 17 | using Button = std::unique_ptr<Input::ButtonDevice>; | 15 | using Button = std::unique_ptr<Input::InputDevice>; |
| 18 | 16 | ||
| 19 | Analog(Button up_, Button down_, Button left_, Button right_, Button modifier_, | 17 | Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, |
| 20 | float modifier_scale_, float modifier_angle_) | 18 | float modifier_scale_, float modifier_angle_) |
| 21 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), | 19 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), |
| 22 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), | 20 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), |
| 23 | modifier_angle(modifier_angle_) { | 21 | modifier_angle(modifier_angle_) { |
| 24 | Input::InputCallback<bool> callbacks{ | 22 | Input::InputCallback button_up_callback{ |
| 25 | [this]([[maybe_unused]] bool status) { UpdateStatus(); }}; | 23 | [this](Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }}; |
| 26 | up->SetCallback(callbacks); | 24 | Input::InputCallback button_down_callback{ |
| 27 | down->SetCallback(callbacks); | 25 | [this](Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }}; |
| 28 | left->SetCallback(callbacks); | 26 | Input::InputCallback button_left_callback{ |
| 29 | right->SetCallback(callbacks); | 27 | [this](Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }}; |
| 30 | modifier->SetCallback(callbacks); | 28 | Input::InputCallback button_right_callback{ |
| 29 | [this](Input::CallbackStatus callback_) { UpdateRightButtonStatus(callback_); }}; | ||
| 30 | Input::InputCallback button_modifier_callback{ | ||
| 31 | [this](Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }}; | ||
| 32 | up->SetCallback(button_up_callback); | ||
| 33 | down->SetCallback(button_down_callback); | ||
| 34 | left->SetCallback(button_left_callback); | ||
| 35 | right->SetCallback(button_right_callback); | ||
| 36 | modifier->SetCallback(button_modifier_callback); | ||
| 31 | } | 37 | } |
| 32 | 38 | ||
| 33 | bool IsAngleGreater(float old_angle, float new_angle) const { | 39 | bool IsAngleGreater(float old_angle, float new_angle) const { |
| @@ -123,13 +129,38 @@ public: | |||
| 123 | } | 129 | } |
| 124 | } | 130 | } |
| 125 | 131 | ||
| 132 | void UpdateUpButtonStatus(Input::CallbackStatus button_callback) { | ||
| 133 | up_status = button_callback.button_status.value; | ||
| 134 | UpdateStatus(); | ||
| 135 | } | ||
| 136 | |||
| 137 | void UpdateDownButtonStatus(Input::CallbackStatus button_callback) { | ||
| 138 | down_status = button_callback.button_status.value; | ||
| 139 | UpdateStatus(); | ||
| 140 | } | ||
| 141 | |||
| 142 | void UpdateLeftButtonStatus(Input::CallbackStatus button_callback) { | ||
| 143 | left_status = button_callback.button_status.value; | ||
| 144 | UpdateStatus(); | ||
| 145 | } | ||
| 146 | |||
| 147 | void UpdateRightButtonStatus(Input::CallbackStatus button_callback) { | ||
| 148 | right_status = button_callback.button_status.value; | ||
| 149 | UpdateStatus(); | ||
| 150 | } | ||
| 151 | |||
| 152 | void UpdateModButtonStatus(Input::CallbackStatus button_callback) { | ||
| 153 | modifier_status = button_callback.button_status.value; | ||
| 154 | UpdateStatus(); | ||
| 155 | } | ||
| 156 | |||
| 126 | void UpdateStatus() { | 157 | void UpdateStatus() { |
| 127 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | 158 | const float coef = modifier_status ? modifier_scale : 1.0f; |
| 128 | 159 | ||
| 129 | bool r = right->GetStatus(); | 160 | bool r = right_status; |
| 130 | bool l = left->GetStatus(); | 161 | bool l = left_status; |
| 131 | bool u = up->GetStatus(); | 162 | bool u = up_status; |
| 132 | bool d = down->GetStatus(); | 163 | bool d = down_status; |
| 133 | 164 | ||
| 134 | // Eliminate contradictory movements | 165 | // Eliminate contradictory movements |
| 135 | if (r && l) { | 166 | if (r && l) { |
| @@ -162,49 +193,42 @@ public: | |||
| 162 | } | 193 | } |
| 163 | 194 | ||
| 164 | last_update = now; | 195 | last_update = now; |
| 196 | Input::CallbackStatus status{ | ||
| 197 | .type = Input::InputType::Stick, | ||
| 198 | .stick_status = GetStatus(), | ||
| 199 | }; | ||
| 200 | TriggerOnChange(status); | ||
| 165 | } | 201 | } |
| 166 | 202 | ||
| 167 | std::tuple<float, float> GetStatus() const override { | 203 | Input::StickStatus GetStatus() const { |
| 204 | Input::StickStatus status{}; | ||
| 205 | status.x.properties = properties; | ||
| 206 | status.y.properties = properties; | ||
| 168 | if (Settings::values.emulate_analog_keyboard) { | 207 | if (Settings::values.emulate_analog_keyboard) { |
| 169 | const auto now = std::chrono::steady_clock::now(); | 208 | const auto now = std::chrono::steady_clock::now(); |
| 170 | float angle_ = GetAngle(now); | 209 | float angle_ = GetAngle(now); |
| 171 | return std::make_tuple(std::cos(angle_) * amplitude, std::sin(angle_) * amplitude); | 210 | status.x.raw_value = std::cos(angle_) * amplitude; |
| 211 | status.y.raw_value = std::sin(angle_) * amplitude; | ||
| 212 | return status; | ||
| 172 | } | 213 | } |
| 173 | constexpr float SQRT_HALF = 0.707106781f; | 214 | constexpr float SQRT_HALF = 0.707106781f; |
| 174 | int x = 0, y = 0; | 215 | int x = 0, y = 0; |
| 175 | if (right->GetStatus()) { | 216 | if (right_status) { |
| 176 | ++x; | 217 | ++x; |
| 177 | } | 218 | } |
| 178 | if (left->GetStatus()) { | 219 | if (left_status) { |
| 179 | --x; | 220 | --x; |
| 180 | } | 221 | } |
| 181 | if (up->GetStatus()) { | 222 | if (up_status) { |
| 182 | ++y; | 223 | ++y; |
| 183 | } | 224 | } |
| 184 | if (down->GetStatus()) { | 225 | if (down_status) { |
| 185 | --y; | 226 | --y; |
| 186 | } | 227 | } |
| 187 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | 228 | const float coef = modifier_status ? modifier_scale : 1.0f; |
| 188 | return std::make_tuple(static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF), | 229 | status.x.raw_value = static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF); |
| 189 | static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF)); | 230 | status.y.raw_value = static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF); |
| 190 | } | 231 | return status; |
| 191 | |||
| 192 | Input::AnalogProperties GetAnalogProperties() const override { | ||
| 193 | return {modifier_scale, 1.0f, 0.5f}; | ||
| 194 | } | ||
| 195 | |||
| 196 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | ||
| 197 | switch (direction) { | ||
| 198 | case Input::AnalogDirection::RIGHT: | ||
| 199 | return right->GetStatus(); | ||
| 200 | case Input::AnalogDirection::LEFT: | ||
| 201 | return left->GetStatus(); | ||
| 202 | case Input::AnalogDirection::UP: | ||
| 203 | return up->GetStatus(); | ||
| 204 | case Input::AnalogDirection::DOWN: | ||
| 205 | return down->GetStatus(); | ||
| 206 | } | ||
| 207 | return false; | ||
| 208 | } | 232 | } |
| 209 | 233 | ||
| 210 | private: | 234 | private: |
| @@ -218,21 +242,29 @@ private: | |||
| 218 | float angle{}; | 242 | float angle{}; |
| 219 | float goal_angle{}; | 243 | float goal_angle{}; |
| 220 | float amplitude{}; | 244 | float amplitude{}; |
| 245 | bool up_status; | ||
| 246 | bool down_status; | ||
| 247 | bool left_status; | ||
| 248 | bool right_status; | ||
| 249 | bool modifier_status; | ||
| 250 | const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; | ||
| 221 | std::chrono::time_point<std::chrono::steady_clock> last_update; | 251 | std::chrono::time_point<std::chrono::steady_clock> last_update; |
| 222 | }; | 252 | }; |
| 223 | 253 | ||
| 224 | std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) { | 254 | std::unique_ptr<Input::InputDevice> StickFromButton::Create(const Common::ParamPackage& params) { |
| 225 | const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); | 255 | const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); |
| 226 | auto up = Input::CreateDevice<Input::ButtonDevice>(params.Get("up", null_engine)); | 256 | auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine)); |
| 227 | auto down = Input::CreateDevice<Input::ButtonDevice>(params.Get("down", null_engine)); | 257 | auto down = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("down", null_engine)); |
| 228 | auto left = Input::CreateDevice<Input::ButtonDevice>(params.Get("left", null_engine)); | 258 | auto left = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("left", null_engine)); |
| 229 | auto right = Input::CreateDevice<Input::ButtonDevice>(params.Get("right", null_engine)); | 259 | auto right = |
| 230 | auto modifier = Input::CreateDevice<Input::ButtonDevice>(params.Get("modifier", null_engine)); | 260 | Input::CreateDeviceFromString<Input::InputDevice>(params.Get("right", null_engine)); |
| 261 | auto modifier = | ||
| 262 | Input::CreateDeviceFromString<Input::InputDevice>(params.Get("modifier", null_engine)); | ||
| 231 | auto modifier_scale = params.Get("modifier_scale", 0.5f); | 263 | auto modifier_scale = params.Get("modifier_scale", 0.5f); |
| 232 | auto modifier_angle = params.Get("modifier_angle", 5.5f); | 264 | auto modifier_angle = params.Get("modifier_angle", 5.5f); |
| 233 | return std::make_unique<Analog>(std::move(up), std::move(down), std::move(left), | 265 | return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left), |
| 234 | std::move(right), std::move(modifier), modifier_scale, | 266 | std::move(right), std::move(modifier), modifier_scale, |
| 235 | modifier_angle); | 267 | modifier_angle); |
| 236 | } | 268 | } |
| 237 | 269 | ||
| 238 | } // namespace InputCommon | 270 | } // namespace InputCommon |
diff --git a/src/input_common/analog_from_button.h b/src/input_common/helpers/stick_from_buttons.h index bbd583dd9..1d6e24c98 100755..100644 --- a/src/input_common/analog_from_button.h +++ b/src/input_common/helpers/stick_from_buttons.h | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | |||
| 1 | // Copyright 2017 Citra Emulator Project | 2 | // Copyright 2017 Citra Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 3 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 4 | // Refer to the license.txt file included. |
| 4 | 5 | ||
| 5 | #pragma once | 6 | #pragma once |
| 6 | 7 | ||
| 7 | #include <memory> | 8 | #include "common/input.h" |
| 8 | #include "core/frontend/input.h" | ||
| 9 | 9 | ||
| 10 | namespace InputCommon { | 10 | namespace InputCommon { |
| 11 | 11 | ||
| @@ -13,7 +13,7 @@ namespace InputCommon { | |||
| 13 | * An analog device factory that takes direction button devices and combines them into a analog | 13 | * An analog device factory that takes direction button devices and combines them into a analog |
| 14 | * device. | 14 | * device. |
| 15 | */ | 15 | */ |
| 16 | class AnalogFromButton final : public Input::Factory<Input::AnalogDevice> { | 16 | class StickFromButton final : public Input::Factory<Input::InputDevice> { |
| 17 | public: | 17 | public: |
| 18 | /** | 18 | /** |
| 19 | * Creates an analog device from direction button devices | 19 | * Creates an analog device from direction button devices |
| @@ -25,7 +25,7 @@ public: | |||
| 25 | * - "modifier": a serialized ParamPackage for creating a button device as the modifier | 25 | * - "modifier": a serialized ParamPackage for creating a button device as the modifier |
| 26 | * - "modifier_scale": a float for the multiplier the modifier gives to the position | 26 | * - "modifier_scale": a float for the multiplier the modifier gives to the position |
| 27 | */ | 27 | */ |
| 28 | std::unique_ptr<Input::AnalogDevice> Create(const Common::ParamPackage& params) override; | 28 | std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | } // namespace InputCommon | 31 | } // namespace InputCommon |
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp new file mode 100644 index 000000000..2abfaf841 --- /dev/null +++ b/src/input_common/helpers/touch_from_buttons.cpp | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | // Copyright 2020 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include "common/settings.h" | ||
| 7 | #include "core/frontend/framebuffer_layout.h" | ||
| 8 | #include "input_common/helpers/touch_from_buttons.h" | ||
| 9 | |||
| 10 | namespace InputCommon { | ||
| 11 | |||
| 12 | class TouchFromButtonDevice final : public Input::InputDevice { | ||
| 13 | public: | ||
| 14 | using Button = std::unique_ptr<Input::InputDevice>; | ||
| 15 | TouchFromButtonDevice(Button button_, u32 touch_id_, float x_, float y_) | ||
| 16 | : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { | ||
| 17 | Input::InputCallback button_up_callback{ | ||
| 18 | [this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; | ||
| 19 | button->SetCallback(button_up_callback); | ||
| 20 | } | ||
| 21 | |||
| 22 | Input::TouchStatus GetStatus(bool pressed) const { | ||
| 23 | const Input::ButtonStatus button_status{ | ||
| 24 | .value = pressed, | ||
| 25 | }; | ||
| 26 | Input::TouchStatus status{ | ||
| 27 | .pressed = button_status, | ||
| 28 | .x = {}, | ||
| 29 | .y = {}, | ||
| 30 | .id = touch_id, | ||
| 31 | }; | ||
| 32 | status.x.properties = properties; | ||
| 33 | status.y.properties = properties; | ||
| 34 | |||
| 35 | if (!pressed) { | ||
| 36 | return status; | ||
| 37 | } | ||
| 38 | |||
| 39 | status.x.raw_value = x; | ||
| 40 | status.y.raw_value = y; | ||
| 41 | return status; | ||
| 42 | } | ||
| 43 | |||
| 44 | void UpdateButtonStatus(Input::CallbackStatus button_callback) { | ||
| 45 | const Input::CallbackStatus status{ | ||
| 46 | .type = Input::InputType::Touch, | ||
| 47 | .touch_status = GetStatus(button_callback.button_status.value), | ||
| 48 | }; | ||
| 49 | TriggerOnChange(status); | ||
| 50 | } | ||
| 51 | |||
| 52 | private: | ||
| 53 | Button button; | ||
| 54 | const u32 touch_id; | ||
| 55 | const float x; | ||
| 56 | const float y; | ||
| 57 | const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; | ||
| 58 | }; | ||
| 59 | |||
| 60 | std::unique_ptr<Input::InputDevice> TouchFromButton::Create(const Common::ParamPackage& params) { | ||
| 61 | const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); | ||
| 62 | auto button = | ||
| 63 | Input::CreateDeviceFromString<Input::InputDevice>(params.Get("button", null_engine)); | ||
| 64 | const auto touch_id = params.Get("touch_id", 0); | ||
| 65 | const float x = params.Get("x", 0.0f) / 1280.0f; | ||
| 66 | const float y = params.Get("y", 0.0f) / 720.0f; | ||
| 67 | return std::make_unique<TouchFromButtonDevice>(std::move(button), touch_id, x, y); | ||
| 68 | } | ||
| 69 | |||
| 70 | } // namespace InputCommon | ||
diff --git a/src/input_common/touch_from_button.h b/src/input_common/helpers/touch_from_buttons.h index 8b4d1aa96..21b353728 100644 --- a/src/input_common/touch_from_button.h +++ b/src/input_common/helpers/touch_from_buttons.h | |||
| @@ -4,20 +4,19 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include "common/input.h" |
| 8 | #include "core/frontend/input.h" | ||
| 9 | 8 | ||
| 10 | namespace InputCommon { | 9 | namespace InputCommon { |
| 11 | 10 | ||
| 12 | /** | 11 | /** |
| 13 | * A touch device factory that takes a list of button devices and combines them into a touch device. | 12 | * A touch device factory that takes a list of button devices and combines them into a touch device. |
| 14 | */ | 13 | */ |
| 15 | class TouchFromButtonFactory final : public Input::Factory<Input::TouchDevice> { | 14 | class TouchFromButton final : public Input::Factory<Input::InputDevice> { |
| 16 | public: | 15 | public: |
| 17 | /** | 16 | /** |
| 18 | * Creates a touch device from a list of button devices | 17 | * Creates a touch device from a list of button devices |
| 19 | */ | 18 | */ |
| 20 | std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override; | 19 | std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; |
| 21 | }; | 20 | }; |
| 22 | 21 | ||
| 23 | } // namespace InputCommon | 22 | } // namespace InputCommon |
diff --git a/src/input_common/udp/protocol.cpp b/src/input_common/helpers/udp_protocol.cpp index 5e50bd612..cdeab7e11 100644 --- a/src/input_common/udp/protocol.cpp +++ b/src/input_common/helpers/udp_protocol.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include <cstddef> | 5 | #include <cstddef> |
| 6 | #include <cstring> | 6 | #include <cstring> |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "input_common/udp/protocol.h" | 8 | #include "input_common/helpers/udp_protocol.h" |
| 9 | 9 | ||
| 10 | namespace InputCommon::CemuhookUDP { | 10 | namespace InputCommon::CemuhookUDP { |
| 11 | 11 | ||
diff --git a/src/input_common/udp/protocol.h b/src/input_common/helpers/udp_protocol.h index 1bdc9209e..1bdc9209e 100644 --- a/src/input_common/udp/protocol.h +++ b/src/input_common/helpers/udp_protocol.h | |||
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index f3907c65a..7a5c29b40 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | #include <thread> | 6 | #include <thread> |
| 7 | #include "common/param_package.h" | 7 | #include "common/param_package.h" |
| 8 | #include "common/settings.h" | 8 | #include "common/settings.h" |
| 9 | #include "input_common/analog_from_button.h" | ||
| 10 | #include "input_common/gcadapter/gc_adapter.h" | 9 | #include "input_common/gcadapter/gc_adapter.h" |
| 11 | #include "input_common/gcadapter/gc_poller.h" | 10 | #include "input_common/gcadapter/gc_poller.h" |
| 12 | #include "input_common/keyboard.h" | 11 | #include "input_common/keyboard.h" |
| @@ -16,7 +15,6 @@ | |||
| 16 | #include "input_common/mouse/mouse_poller.h" | 15 | #include "input_common/mouse/mouse_poller.h" |
| 17 | #include "input_common/tas/tas_input.h" | 16 | #include "input_common/tas/tas_input.h" |
| 18 | #include "input_common/tas/tas_poller.h" | 17 | #include "input_common/tas/tas_poller.h" |
| 19 | #include "input_common/touch_from_button.h" | ||
| 20 | #include "input_common/udp/client.h" | 18 | #include "input_common/udp/client.h" |
| 21 | #include "input_common/udp/udp.h" | 19 | #include "input_common/udp/udp.h" |
| 22 | #ifdef HAVE_SDL2 | 20 | #ifdef HAVE_SDL2 |
| @@ -37,12 +35,8 @@ struct InputSubsystem::Impl { | |||
| 37 | 35 | ||
| 38 | keyboard = std::make_shared<Keyboard>(); | 36 | keyboard = std::make_shared<Keyboard>(); |
| 39 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); | 37 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); |
| 40 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", | ||
| 41 | std::make_shared<AnalogFromButton>()); | ||
| 42 | Input::RegisterFactory<Input::MotionDevice>("keyboard", | 38 | Input::RegisterFactory<Input::MotionDevice>("keyboard", |
| 43 | std::make_shared<MotionFromButton>()); | 39 | std::make_shared<MotionFromButton>()); |
| 44 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", | ||
| 45 | std::make_shared<TouchFromButtonFactory>()); | ||
| 46 | 40 | ||
| 47 | #ifdef HAVE_SDL2 | 41 | #ifdef HAVE_SDL2 |
| 48 | sdl = SDL::Init(); | 42 | sdl = SDL::Init(); |
| @@ -75,8 +69,6 @@ struct InputSubsystem::Impl { | |||
| 75 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); | 69 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); |
| 76 | Input::UnregisterFactory<Input::MotionDevice>("keyboard"); | 70 | Input::UnregisterFactory<Input::MotionDevice>("keyboard"); |
| 77 | keyboard.reset(); | 71 | keyboard.reset(); |
| 78 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | ||
| 79 | Input::UnregisterFactory<Input::TouchDevice>("touch_from_button"); | ||
| 80 | #ifdef HAVE_SDL2 | 72 | #ifdef HAVE_SDL2 |
| 81 | sdl.reset(); | 73 | sdl.reset(); |
| 82 | #endif | 74 | #endif |
diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp deleted file mode 100644 index 7878a56d7..000000000 --- a/src/input_common/touch_from_button.cpp +++ /dev/null | |||
| @@ -1,53 +0,0 @@ | |||
| 1 | // Copyright 2020 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include "common/settings.h" | ||
| 7 | #include "core/frontend/framebuffer_layout.h" | ||
| 8 | #include "input_common/touch_from_button.h" | ||
| 9 | |||
| 10 | namespace InputCommon { | ||
| 11 | |||
| 12 | class TouchFromButtonDevice final : public Input::TouchDevice { | ||
| 13 | public: | ||
| 14 | TouchFromButtonDevice() { | ||
| 15 | const auto button_index = | ||
| 16 | static_cast<u64>(Settings::values.touch_from_button_map_index.GetValue()); | ||
| 17 | const auto& buttons = Settings::values.touch_from_button_maps[button_index].buttons; | ||
| 18 | |||
| 19 | for (const auto& config_entry : buttons) { | ||
| 20 | const Common::ParamPackage package{config_entry}; | ||
| 21 | map.emplace_back( | ||
| 22 | Input::CreateDevice<Input::ButtonDevice>(config_entry), | ||
| 23 | std::clamp(package.Get("x", 0), 0, static_cast<int>(Layout::ScreenUndocked::Width)), | ||
| 24 | std::clamp(package.Get("y", 0), 0, | ||
| 25 | static_cast<int>(Layout::ScreenUndocked::Height))); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | Input::TouchStatus GetStatus() const override { | ||
| 30 | Input::TouchStatus touch_status{}; | ||
| 31 | for (std::size_t id = 0; id < map.size() && id < touch_status.size(); ++id) { | ||
| 32 | const bool state = std::get<0>(map[id])->GetStatus(); | ||
| 33 | if (state) { | ||
| 34 | const float x = static_cast<float>(std::get<1>(map[id])) / | ||
| 35 | static_cast<int>(Layout::ScreenUndocked::Width); | ||
| 36 | const float y = static_cast<float>(std::get<2>(map[id])) / | ||
| 37 | static_cast<int>(Layout::ScreenUndocked::Height); | ||
| 38 | touch_status[id] = {x, y, true}; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return touch_status; | ||
| 42 | } | ||
| 43 | |||
| 44 | private: | ||
| 45 | // A vector of the mapped button, its x and its y-coordinate | ||
| 46 | std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; | ||
| 47 | }; | ||
| 48 | |||
| 49 | std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(const Common::ParamPackage&) { | ||
| 50 | return std::make_unique<TouchFromButtonDevice>(); | ||
| 51 | } | ||
| 52 | |||
| 53 | } // namespace InputCommon | ||
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index b9512aa2e..bcc29c4e0 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "common/settings.h" | 12 | #include "common/settings.h" |
| 13 | #include "input_common/udp/client.h" | 13 | #include "input_common/udp/client.h" |
| 14 | #include "input_common/udp/protocol.h" | 14 | #include "input_common/helpers/udp_protocol.h" |
| 15 | 15 | ||
| 16 | using boost::asio::ip::udp; | 16 | using boost::asio::ip::udp; |
| 17 | 17 | ||