diff options
author | Ameer <aj662@drexel.edu> | 2020-07-02 21:54:44 +0200 |
---|---|---|
committer | Ameer <aj662@drexel.edu> | 2020-07-02 21:54:44 +0200 |
commit | 6b7c8e469b2d7943cd7771648659bc362e5d1ddd (patch) | |
tree | 3f4c20300866b1826fb9cd95e01251b2df3ea084 /src/input_common/gcadapter/gc_poller.cpp | |
parent | Reset adapter state on init, fixes errors relating driver hang from unexpected unplug (diff) | |
download | yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.tar yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.tar.gz yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.tar.bz2 yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.tar.lz yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.tar.xz yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.tar.zst yuzu-6b7c8e469b2d7943cd7771648659bc362e5d1ddd.zip |
Diffstat (limited to '')
-rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index a9de9fedf..a04c507b8 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -34,7 +34,13 @@ public: explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, GCAdapter::Adapter* adapter) : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), - gcadapter(adapter) {} + gcadapter(adapter) { + // L/R triggers range is only in positive direction beginning near 0 + // 0.0 threshold equates to near half trigger press, but threshold accounts for variability. + if (axis > 3) { + threshold *= -0.5; + } + } bool GetStatus() const override { const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; @@ -60,10 +66,20 @@ GCButton::~GCButton() = default; std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { const int button_id = params.Get("button", 0); const int port = params.Get("port", 0); + + constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); + + // button is not an axis/stick button + if (button_id != PAD_STICK_ID) { + std::unique_ptr<GCButton> button = + std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); + return std::move(button); + } + // For Axis buttons, used by the binary sticks. - if (params.Has("axis")) { + if (button_id == PAD_STICK_ID) { const int axis = params.Get("axis", 0); - const float threshold = params.Get("threshold", 0.5f); + const float threshold = params.Get("threshold", 0.25f); const std::string direction_name = params.Get("direction", ""); bool trigger_if_greater; if (direction_name == "+") { @@ -77,10 +93,6 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, adapter.get()); } - - std::unique_ptr<GCButton> button = - std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); - return std::move(button); } Common::ParamPackage GCButtonFactory::GetNextInput() { @@ -106,10 +118,10 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK)); if (pad.axis_value > 128) { params.Set("direction", "+"); - params.Set("threshold", "0.5"); + params.Set("threshold", "0.25"); } else { params.Set("direction", "-"); - params.Set("threshold", "-0.5"); + params.Set("threshold", "-0.25"); } break; } @@ -232,7 +244,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { continue; } // An analog device needs two axes, so we need to store the axis for later and wait for - // a second SDL event. The axes also must be from the same joystick. + // a second input event. The axes also must be from the same joystick. const u8 axis = static_cast<u8>(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; |