diff options
| author | 2020-06-21 23:56:56 -0400 | |
|---|---|---|
| committer | 2020-06-21 23:56:56 -0400 | |
| commit | 28046ae3a9cd5e32c7cae1cf64aa005502bf1749 (patch) | |
| tree | e26cc2a7266fe3709a2417acba6536ee58a77964 /src/input_common/gcadapter/gc_poller.cpp | |
| parent | fix for sleep using stl (diff) | |
| download | yuzu-28046ae3a9cd5e32c7cae1cf64aa005502bf1749.tar.gz yuzu-28046ae3a9cd5e32c7cae1cf64aa005502bf1749.tar.xz yuzu-28046ae3a9cd5e32c7cae1cf64aa005502bf1749.zip | |
Tidy up the pointers, use pair over tuple where appropriate
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index ad8b4b431..be7c600a2 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -14,8 +14,7 @@ namespace InputCommon { | |||
| 14 | 14 | ||
| 15 | class GCButton final : public Input::ButtonDevice { | 15 | class GCButton final : public Input::ButtonDevice { |
| 16 | public: | 16 | public: |
| 17 | explicit GCButton(int port_, int button_, int axis_, | 17 | explicit GCButton(int port_, int button_, int axis_, GCAdapter::Adapter* adapter) |
| 18 | std::shared_ptr<GCAdapter::Adapter> adapter) | ||
| 19 | : port(port_), button(button_), gcadapter(adapter) {} | 18 | : port(port_), button(button_), gcadapter(adapter) {} |
| 20 | 19 | ||
| 21 | ~GCButton() override; | 20 | ~GCButton() override; |
| @@ -27,13 +26,13 @@ public: | |||
| 27 | private: | 26 | private: |
| 28 | const int port; | 27 | const int port; |
| 29 | const int button; | 28 | const int button; |
| 30 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | 29 | GCAdapter::Adapter* gcadapter; |
| 31 | }; | 30 | }; |
| 32 | 31 | ||
| 33 | class GCAxisButton final : public Input::ButtonDevice { | 32 | class GCAxisButton final : public Input::ButtonDevice { |
| 34 | public: | 33 | public: |
| 35 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, | 34 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, |
| 36 | std::shared_ptr<GCAdapter::Adapter> adapter) | 35 | GCAdapter::Adapter* adapter) |
| 37 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), | 36 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), |
| 38 | gcadapter(adapter) {} | 37 | gcadapter(adapter) {} |
| 39 | 38 | ||
| @@ -50,11 +49,11 @@ private: | |||
| 50 | const int axis; | 49 | const int axis; |
| 51 | float threshold; | 50 | float threshold; |
| 52 | bool trigger_if_greater; | 51 | bool trigger_if_greater; |
| 53 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | 52 | GCAdapter::Adapter* gcadapter; |
| 54 | }; | 53 | }; |
| 55 | 54 | ||
| 56 | GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | 55 | GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) |
| 57 | : adapter(adapter_) {} | 56 | : adapter(std::move(adapter_)) {} |
| 58 | 57 | ||
| 59 | GCButton::~GCButton() = default; | 58 | GCButton::~GCButton() = default; |
| 60 | 59 | ||
| @@ -75,11 +74,12 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 75 | trigger_if_greater = true; | 74 | trigger_if_greater = true; |
| 76 | LOG_ERROR(Input, "Unknown direction {}", direction_name); | 75 | LOG_ERROR(Input, "Unknown direction {}", direction_name); |
| 77 | } | 76 | } |
| 78 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, adapter); | 77 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, |
| 78 | adapter.get()); | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | std::unique_ptr<GCButton> button = | 81 | std::unique_ptr<GCButton> button = |
| 82 | std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter); | 82 | std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); |
| 83 | return std::move(button); | 83 | return std::move(button); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| @@ -171,8 +171,7 @@ void GCButtonFactory::EndConfiguration() { | |||
| 171 | 171 | ||
| 172 | class GCAnalog final : public Input::AnalogDevice { | 172 | class GCAnalog final : public Input::AnalogDevice { |
| 173 | public: | 173 | public: |
| 174 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, | 174 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) |
| 175 | std::shared_ptr<GCAdapter::Adapter> adapter) | ||
| 176 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} | 175 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} |
| 177 | 176 | ||
| 178 | float GetAxis(int axis) const { | 177 | float GetAxis(int axis) const { |
| @@ -183,7 +182,7 @@ public: | |||
| 183 | return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; | 182 | return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; |
| 184 | } | 183 | } |
| 185 | 184 | ||
| 186 | std::tuple<float, float> GetAnalog(int axis_x, int axis_y) const { | 185 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { |
| 187 | float x = GetAxis(axis_x); | 186 | float x = GetAxis(axis_x); |
| 188 | float y = GetAxis(axis_y); | 187 | float y = GetAxis(axis_y); |
| 189 | 188 | ||
| @@ -196,17 +195,17 @@ public: | |||
| 196 | y /= r; | 195 | y /= r; |
| 197 | } | 196 | } |
| 198 | 197 | ||
| 199 | return std::make_tuple(x, y); | 198 | return {x, y}; |
| 200 | } | 199 | } |
| 201 | 200 | ||
| 202 | std::tuple<float, float> GetStatus() const override { | 201 | std::tuple<float, float> GetStatus() const override { |
| 203 | const auto [x, y] = GetAnalog(axis_x, axis_y); | 202 | const auto [x, y] = GetAnalog(axis_x, axis_y); |
| 204 | const float r = std::sqrt((x * x) + (y * y)); | 203 | const float r = std::sqrt((x * x) + (y * y)); |
| 205 | if (r > deadzone) { | 204 | if (r > deadzone) { |
| 206 | return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), | 205 | return {x / r * (r - deadzone) / (1 - deadzone), |
| 207 | y / r * (r - deadzone) / (1 - deadzone)); | 206 | y / r * (r - deadzone) / (1 - deadzone)}; |
| 208 | } | 207 | } |
| 209 | return std::make_tuple<float, float>(0.0f, 0.0f); | 208 | return {0.0f, 0.0f}; |
| 210 | } | 209 | } |
| 211 | 210 | ||
| 212 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | 211 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { |
| @@ -231,12 +230,12 @@ private: | |||
| 231 | const int axis_y; | 230 | const int axis_y; |
| 232 | const float deadzone; | 231 | const float deadzone; |
| 233 | mutable std::mutex mutex; | 232 | mutable std::mutex mutex; |
| 234 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | 233 | GCAdapter::Adapter* gcadapter; |
| 235 | }; | 234 | }; |
| 236 | 235 | ||
| 237 | /// An analog device factory that creates analog devices from GC Adapter | 236 | /// An analog device factory that creates analog devices from GC Adapter |
| 238 | GCAnalogFactory::GCAnalogFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | 237 | GCAnalogFactory::GCAnalogFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) |
| 239 | : adapter(adapter_) {} | 238 | : adapter(std::move(adapter_)) {} |
| 240 | 239 | ||
| 241 | /** | 240 | /** |
| 242 | * Creates analog device from joystick axes | 241 | * Creates analog device from joystick axes |
| @@ -246,13 +245,12 @@ GCAnalogFactory::GCAnalogFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | |||
| 246 | * - "axis_y": the index of the axis to be bind as y-axis | 245 | * - "axis_y": the index of the axis to be bind as y-axis |
| 247 | */ | 246 | */ |
| 248 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { | 247 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { |
| 249 | const std::string guid = params.Get("guid", "0"); | ||
| 250 | const int port = params.Get("port", 0); | 248 | const int port = params.Get("port", 0); |
| 251 | const int axis_x = params.Get("axis_x", 0); | 249 | const int axis_x = params.Get("axis_x", 0); |
| 252 | const int axis_y = params.Get("axis_y", 1); | 250 | const int axis_y = params.Get("axis_y", 1); |
| 253 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); | 251 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); |
| 254 | 252 | ||
| 255 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter); | 253 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get()); |
| 256 | } | 254 | } |
| 257 | 255 | ||
| 258 | void GCAnalogFactory::BeginConfiguration() { | 256 | void GCAnalogFactory::BeginConfiguration() { |