diff options
| author | 2020-10-15 20:59:34 -0700 | |
|---|---|---|
| committer | 2020-10-15 20:59:34 -0700 | |
| commit | 64f967fd4958abb5a02191a81e91fc8b33bcf4c5 (patch) | |
| tree | 97a73da4871f006b39eafca3a881ae2ea42f206a /src/input_common/gcadapter/gc_poller.cpp | |
| parent | Merge pull request #4784 from bunnei/cancelbuffer (diff) | |
| parent | input_common/CMakeLists: Make some warnings errors (diff) | |
| download | yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.gz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.xz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.zip | |
Merge pull request #4790 from lioncash/input-common
input_common/CMakeLists: Make some warnings errors
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 92e9e8e89..893556916 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -15,7 +15,7 @@ namespace InputCommon { | |||
| 15 | 15 | ||
| 16 | class GCButton final : public Input::ButtonDevice { | 16 | class GCButton final : public Input::ButtonDevice { |
| 17 | public: | 17 | public: |
| 18 | explicit GCButton(int port_, int button_, const GCAdapter::Adapter* adapter) | 18 | explicit GCButton(u32 port_, int button_, const GCAdapter::Adapter* adapter) |
| 19 | : port(port_), button(button_), gcadapter(adapter) {} | 19 | : port(port_), button(button_), gcadapter(adapter) {} |
| 20 | 20 | ||
| 21 | ~GCButton() override; | 21 | ~GCButton() override; |
| @@ -28,14 +28,14 @@ public: | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | private: | 30 | private: |
| 31 | const int port; | 31 | const u32 port; |
| 32 | const int button; | 32 | const int button; |
| 33 | const GCAdapter::Adapter* gcadapter; | 33 | const GCAdapter::Adapter* gcadapter; |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | class GCAxisButton final : public Input::ButtonDevice { | 36 | class GCAxisButton final : public Input::ButtonDevice { |
| 37 | public: | 37 | public: |
| 38 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, | 38 | explicit GCAxisButton(u32 port_, u32 axis_, float threshold_, bool trigger_if_greater_, |
| 39 | const GCAdapter::Adapter* adapter) | 39 | const GCAdapter::Adapter* adapter) |
| 40 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), | 40 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), |
| 41 | gcadapter(adapter), | 41 | gcadapter(adapter), |
| @@ -56,8 +56,8 @@ public: | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | private: | 58 | private: |
| 59 | const int port; | 59 | const u32 port; |
| 60 | const int axis; | 60 | const u32 axis; |
| 61 | float threshold; | 61 | float threshold; |
| 62 | bool trigger_if_greater; | 62 | bool trigger_if_greater; |
| 63 | const GCAdapter::Adapter* gcadapter; | 63 | const GCAdapter::Adapter* gcadapter; |
| @@ -70,8 +70,8 @@ GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | |||
| 70 | GCButton::~GCButton() = default; | 70 | GCButton::~GCButton() = default; |
| 71 | 71 | ||
| 72 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { | 72 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { |
| 73 | const int button_id = params.Get("button", 0); | 73 | const auto button_id = params.Get("button", 0); |
| 74 | const int port = params.Get("port", 0); | 74 | const auto port = static_cast<u32>(params.Get("port", 0)); |
| 75 | 75 | ||
| 76 | constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); | 76 | constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); |
| 77 | 77 | ||
| @@ -149,25 +149,27 @@ void GCButtonFactory::EndConfiguration() { | |||
| 149 | 149 | ||
| 150 | class GCAnalog final : public Input::AnalogDevice { | 150 | class GCAnalog final : public Input::AnalogDevice { |
| 151 | public: | 151 | public: |
| 152 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, | 152 | explicit GCAnalog(u32 port_, u32 axis_x_, u32 axis_y_, float deadzone_, |
| 153 | const GCAdapter::Adapter* adapter, float range_) | 153 | const GCAdapter::Adapter* adapter, float range_) |
| 154 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), | 154 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), |
| 155 | origin_value_x(static_cast<float>(adapter->GetOriginValue(port_, axis_x_))), | 155 | origin_value_x(static_cast<float>(adapter->GetOriginValue(port_, axis_x_))), |
| 156 | origin_value_y(static_cast<float>(adapter->GetOriginValue(port_, axis_y_))), | 156 | origin_value_y(static_cast<float>(adapter->GetOriginValue(port_, axis_y_))), |
| 157 | range(range_) {} | 157 | range(range_) {} |
| 158 | 158 | ||
| 159 | float GetAxis(int axis) const { | 159 | float GetAxis(u32 axis) const { |
| 160 | if (gcadapter->DeviceConnected(port)) { | 160 | if (gcadapter->DeviceConnected(port)) { |
| 161 | std::lock_guard lock{mutex}; | 161 | std::lock_guard lock{mutex}; |
| 162 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; | 162 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; |
| 163 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / (100.0f * range); | 163 | const auto axis_value = |
| 164 | static_cast<float>(gcadapter->GetPadState()[port].axes.at(axis)); | ||
| 165 | return (axis_value - origin_value) / (100.0f * range); | ||
| 164 | } | 166 | } |
| 165 | return 0.0f; | 167 | return 0.0f; |
| 166 | } | 168 | } |
| 167 | 169 | ||
| 168 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { | 170 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |
| 169 | float x = GetAxis(axis_x); | 171 | float x = GetAxis(analog_axis_x); |
| 170 | float y = GetAxis(axis_y); | 172 | float y = GetAxis(analog_axis_y); |
| 171 | 173 | ||
| 172 | // Make sure the coordinates are in the unit circle, | 174 | // Make sure the coordinates are in the unit circle, |
| 173 | // otherwise normalize it. | 175 | // otherwise normalize it. |
| @@ -208,9 +210,9 @@ public: | |||
| 208 | } | 210 | } |
| 209 | 211 | ||
| 210 | private: | 212 | private: |
| 211 | const int port; | 213 | const u32 port; |
| 212 | const int axis_x; | 214 | const u32 axis_x; |
| 213 | const int axis_y; | 215 | const u32 axis_y; |
| 214 | const float deadzone; | 216 | const float deadzone; |
| 215 | const GCAdapter::Adapter* gcadapter; | 217 | const GCAdapter::Adapter* gcadapter; |
| 216 | const float origin_value_x; | 218 | const float origin_value_x; |
| @@ -231,11 +233,11 @@ GCAnalogFactory::GCAnalogFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | |||
| 231 | * - "axis_y": the index of the axis to be bind as y-axis | 233 | * - "axis_y": the index of the axis to be bind as y-axis |
| 232 | */ | 234 | */ |
| 233 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { | 235 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { |
| 234 | const int port = params.Get("port", 0); | 236 | const auto port = static_cast<u32>(params.Get("port", 0)); |
| 235 | const int axis_x = params.Get("axis_x", 0); | 237 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); |
| 236 | const int axis_y = params.Get("axis_y", 1); | 238 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); |
| 237 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); | 239 | const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 238 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | 240 | const auto range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); |
| 239 | 241 | ||
| 240 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); | 242 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); |
| 241 | } | 243 | } |
| @@ -256,7 +258,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 256 | for (std::size_t port = 0; port < queue.size(); ++port) { | 258 | for (std::size_t port = 0; port < queue.size(); ++port) { |
| 257 | while (queue[port].Pop(pad)) { | 259 | while (queue[port].Pop(pad)) { |
| 258 | if (pad.axis == GCAdapter::PadAxes::Undefined || | 260 | if (pad.axis == GCAdapter::PadAxes::Undefined || |
| 259 | std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { | 261 | std::abs((static_cast<float>(pad.axis_value) - 128.0f) / 128.0f) < 0.1f) { |
| 260 | continue; | 262 | continue; |
| 261 | } | 263 | } |
| 262 | // An analog device needs two axes, so we need to store the axis for later and wait for | 264 | // An analog device needs two axes, so we need to store the axis for later and wait for |