From 0248614add99c1df1bc7c9ff97091f678ff75aca Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 12:36:28 -0400 Subject: GC Adapter Implementation --- src/input_common/gcadapter/gc_poller.cpp | 310 +++++++++++++++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 src/input_common/gcadapter/gc_poller.cpp (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp new file mode 100644 index 000000000..772bd8890 --- /dev/null +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -0,0 +1,310 @@ +#include +#include +#include +#include +#include "input_common/gcadapter/gc_poller.h" +#include "input_common/gcadapter/gc_adapter.h" +#include "common/threadsafe_queue.h" + +// Using extern as to avoid multply defined symbols. +extern Common::SPSCQueue pad_queue[4]; +extern struct GCState state[4]; + +namespace InputCommon { + +class GCButton final : public Input::ButtonDevice { +public: + explicit GCButton(int port_, int button_, int axis_) + : port(port_), button(button_) { + } + + ~GCButton() override; + + bool GetStatus() const override { + return state[port].buttons.at(button); + } + +private: + const int port; + const int button; +}; + +class GCAxisButton final : public Input::ButtonDevice { +public: + explicit GCAxisButton(int port_, int axis_, float threshold_, + bool trigger_if_greater_) + : port(port_), axis(axis_), threshold(threshold_), + trigger_if_greater(trigger_if_greater_) { + } + + + bool GetStatus() const override { + const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; + if (trigger_if_greater) { + return axis_value > 0.10f; //TODO(ameerj) : Fix threshold. + } + return axis_value < -0.10f; + } + +private: + const int port; + const int axis; + float threshold; + bool trigger_if_greater; +}; + +GCButtonFactory::GCButtonFactory() { + GCAdapter::Init(); +} + +GCButton::~GCButton() { + GCAdapter::Shutdown(); +} + +std::unique_ptr GCButtonFactory::Create(const Common::ParamPackage& params) { + int button_id = params.Get("button", 0); + int port = params.Get("port", 0); + // For Axis buttons, used by the binary sticks. + if (params.Has("axis")) { + const int axis = params.Get("axis", 0); + const float threshold = params.Get("threshold", 0.5f); + const std::string direction_name = params.Get("direction", ""); + bool trigger_if_greater; + if (direction_name == "+") { + trigger_if_greater = true; + } else if (direction_name == "-") { + trigger_if_greater = false; + } else { + trigger_if_greater = true; + LOG_ERROR(Input, "Unknown direction {}", direction_name); + } + return std::make_unique(port, axis, threshold, trigger_if_greater); + } + + std::unique_ptr button = + std::make_unique(port, button_id, params.Get("axis", 0)); + return std::move(button); +} + +Common::ParamPackage GCButtonFactory::GetNextInput() { + Common::ParamPackage params; + GCPadStatus pad; + for (int i = 0; i < 4; i++) { + while (pad_queue[i].Pop(pad)) { + // This while loop will break on the earliest detected button + params.Set("engine", "gcpad"); + params.Set("port", i); + // I was debating whether to keep these verbose for ease of reading + // or to use a while loop shifting the bits to test and set the value. + if (pad.button & PAD_BUTTON_A) { + params.Set("button", PAD_BUTTON_A); + break; + } + if (pad.button & PAD_BUTTON_B) { + params.Set("button", PAD_BUTTON_B); + break; + } + if (pad.button & PAD_BUTTON_X) { + params.Set("button", PAD_BUTTON_X); + break; + } + if (pad.button & PAD_BUTTON_Y) { + params.Set("button", PAD_BUTTON_Y); + break; + } + if (pad.button & PAD_BUTTON_DOWN) { + params.Set("button", PAD_BUTTON_DOWN); + break; + } + if (pad.button & PAD_BUTTON_LEFT) { + params.Set("button", PAD_BUTTON_LEFT); + break; + } + if (pad.button & PAD_BUTTON_RIGHT) { + params.Set("button", PAD_BUTTON_RIGHT); + break; + } + if (pad.button & PAD_BUTTON_UP) { + params.Set("button", PAD_BUTTON_UP); + break; + } + if (pad.button & PAD_TRIGGER_L) { + params.Set("button", PAD_TRIGGER_L); + break; + } + if (pad.button & PAD_TRIGGER_R) { + params.Set("button", PAD_TRIGGER_R); + break; + } + if (pad.button & PAD_TRIGGER_Z) { + params.Set("button", PAD_TRIGGER_Z); + break; + } + if (pad.button & PAD_BUTTON_START) { + params.Set("button", PAD_BUTTON_START); + break; + } + // For Axis button implementation + if (pad.axis_which != 255) { + params.Set("axis", pad.axis_which); + params.Set("button", PAD_STICK); + if (pad.axis_value > 128) { + params.Set("direction", "+"); + params.Set("threshold", "0.5"); + } else { + params.Set("direction", "-"); + params.Set("threshold", "-0.5"); + } + break; + } + } + } + return params; +} + +void GCButtonFactory::BeginConfiguration() { + polling = true; + for (int i = 0; i < 4; i++) + pad_queue[i].Clear(); + GCAdapter::BeginConfiguration(); +} + +void GCButtonFactory::EndConfiguration() { + polling = false; + + for (int i = 0; i < 4; i++) + pad_queue[i].Clear(); + GCAdapter::EndConfiguration(); +} + +class GCAnalog final : public Input::AnalogDevice { +public: + GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) + : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) { + } + + float GetAxis(int axis) const { + std::lock_guard lock{mutex}; + // division is not by a perfect 128 to account for some variance in center location + // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range [20-230] + return (state[port].axes.at(axis) - 128.0f) / 95.0f; + } + + std::tuple GetAnalog(int axis_x, int axis_y) const { + float x = GetAxis(axis_x); + float y = GetAxis(axis_y); + + // Make sure the coordinates are in the unit circle, + // otherwise normalize it. + float r = x * x + y * y; + if (r > 1.0f) { + r = std::sqrt(r); + x /= r; + y /= r; + } + + return std::make_tuple(x, y); + } + + std::tuple GetStatus() const override { + const auto [x, y] = GetAnalog(axis_x, axis_y); + const float r = std::sqrt((x * x) + (y * y)); + if (r > deadzone) { + return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), + y / r * (r - deadzone) / (1 - deadzone)); + } + return std::make_tuple(0.0f, 0.0f); + } + + bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { + const auto [x, y] = GetStatus(); + const float directional_deadzone = 0.4f; + switch (direction) { + case Input::AnalogDirection::RIGHT: + return x > directional_deadzone; + case Input::AnalogDirection::LEFT: + return x < -directional_deadzone; + case Input::AnalogDirection::UP: + return y > directional_deadzone; + case Input::AnalogDirection::DOWN: + return y < -directional_deadzone; + } + return false; + } + +private: + const int port; + const int axis_x; + const int axis_y; + const float deadzone; + mutable std::mutex mutex; +}; + + +/// An analog device factory that creates analog devices from GC Adapter +GCAnalogFactory::GCAnalogFactory() {}; + + +/** +* Creates analog device from joystick axes +* @param params contains parameters for creating the device: +* - "port": the nth gcpad on the adapter +* - "axis_x": the index of the axis to be bind as x-axis +* - "axis_y": the index of the axis to be bind as y-axis +*/ +std::unique_ptr GCAnalogFactory::Create(const Common::ParamPackage& params) { + const std::string guid = params.Get("guid", "0"); + const int port = params.Get("port", 0); + const int axis_x = params.Get("axis_x", 0); + const int axis_y = params.Get("axis_y", 1); + const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); + + return std::make_unique(port, axis_x, axis_y, deadzone); +} + +void GCAnalogFactory::BeginConfiguration() { + polling = true; + for (int i = 0; i < 4; i++) + pad_queue[i].Clear(); + GCAdapter::BeginConfiguration(); +} + +void GCAnalogFactory::EndConfiguration() { + polling = false; + for (int i = 0; i < 4; i++) + pad_queue[i].Clear(); + GCAdapter::EndConfiguration(); +} + +Common::ParamPackage GCAnalogFactory::GetNextInput() { + GCPadStatus pad; + for (int i = 0; i < 4; i++) { + while (pad_queue[i].Pop(pad)) { + if (pad.axis_which == 255 || std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { + 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. + const int axis = pad.axis_which; + if (analog_x_axis == -1) { + analog_x_axis = axis; + controller_number = i; + } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == i) { + analog_y_axis = axis; + } + } + } + Common::ParamPackage params; + if (analog_x_axis != -1 && analog_y_axis != -1) { + params.Set("engine", "gcpad"); + params.Set("port", controller_number); + params.Set("axis_x", analog_x_axis); + params.Set("axis_y", analog_y_axis); + analog_x_axis = -1; + analog_y_axis = -1; + controller_number = -1; + return params; + } + return params; +} +} // namespace InputCommon -- cgit v1.2.3 From c94583d867fd909d8731ba50e085352aae0e6885 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 15:31:57 -0400 Subject: Clang Formatting --- src/input_common/gcadapter/gc_poller.cpp | 56 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 772bd8890..51b3362d6 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -1,10 +1,14 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + #include #include #include #include -#include "input_common/gcadapter/gc_poller.h" -#include "input_common/gcadapter/gc_adapter.h" #include "common/threadsafe_queue.h" +#include "input_common/gcadapter/gc_adapter.h" +#include "input_common/gcadapter/gc_poller.h" // Using extern as to avoid multply defined symbols. extern Common::SPSCQueue pad_queue[4]; @@ -14,9 +18,7 @@ namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_) - : port(port_), button(button_) { - } + explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {} ~GCButton() override; @@ -31,17 +33,14 @@ private: class GCAxisButton final : public Input::ButtonDevice { public: - explicit GCAxisButton(int port_, int axis_, float threshold_, - bool trigger_if_greater_) - : port(port_), axis(axis_), threshold(threshold_), - trigger_if_greater(trigger_if_greater_) { + explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_) + : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) { } - bool GetStatus() const override { const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; if (trigger_if_greater) { - return axis_value > 0.10f; //TODO(ameerj) : Fix threshold. + return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. } return axis_value < -0.10f; } @@ -164,29 +163,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { void GCButtonFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::BeginConfiguration(); } void GCButtonFactory::EndConfiguration() { polling = false; - - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::EndConfiguration(); } class GCAnalog final : public Input::AnalogDevice { public: GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) - : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) { - } + : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {} float GetAxis(int axis) const { std::lock_guard lock{mutex}; // division is not by a perfect 128 to account for some variance in center location - // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range [20-230] + // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range + // [20-230] return (state[port].axes.at(axis) - 128.0f) / 95.0f; } @@ -240,18 +240,16 @@ private: mutable std::mutex mutex; }; - /// An analog device factory that creates analog devices from GC Adapter -GCAnalogFactory::GCAnalogFactory() {}; - +GCAnalogFactory::GCAnalogFactory(){}; /** -* Creates analog device from joystick axes -* @param params contains parameters for creating the device: -* - "port": the nth gcpad on the adapter -* - "axis_x": the index of the axis to be bind as x-axis -* - "axis_y": the index of the axis to be bind as y-axis -*/ + * Creates analog device from joystick axes + * @param params contains parameters for creating the device: + * - "port": the nth gcpad on the adapter + * - "axis_x": the index of the axis to be bind as x-axis + * - "axis_y": the index of the axis to be bind as y-axis + */ std::unique_ptr GCAnalogFactory::Create(const Common::ParamPackage& params) { const std::string guid = params.Get("guid", "0"); const int port = params.Get("port", 0); @@ -264,15 +262,17 @@ std::unique_ptr GCAnalogFactory::Create(const Common::Param void GCAnalogFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::BeginConfiguration(); } void GCAnalogFactory::EndConfiguration() { polling = false; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::EndConfiguration(); } -- cgit v1.2.3 From 121af3646dad0f80453d2ffffa688dd4435d3acc Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 18:43:01 -0400 Subject: Singleton GC Adapter class, remove globals, fix naming convention Fix clang formatting Manual fix for configure_input_player formatting Add missing lib usb cmake command --- src/input_common/gcadapter/gc_poller.cpp | 125 ++++++++++++++++--------------- 1 file changed, 65 insertions(+), 60 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 51b3362d6..0e591baca 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -10,35 +10,34 @@ #include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" -// Using extern as to avoid multply defined symbols. -extern Common::SPSCQueue pad_queue[4]; -extern struct GCState state[4]; - namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {} + explicit GCButton(int port_, int button_, int axis_, GCAdapter::Adapter* adapter) + : port(port_), button(button_), gcadapter(adapter) {} ~GCButton() override; bool GetStatus() const override { - return state[port].buttons.at(button); + return gcadapter->GetPadState()[port].buttons.at(button); } private: const int port; const int button; + GCAdapter::Adapter* gcadapter; }; class GCAxisButton final : public Input::ButtonDevice { public: - explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_) - : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) { - } + 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) {} bool GetStatus() const override { - const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; + const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; if (trigger_if_greater) { return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. } @@ -50,14 +49,15 @@ private: const int axis; float threshold; bool trigger_if_greater; + GCAdapter::Adapter* gcadapter; }; GCButtonFactory::GCButtonFactory() { - GCAdapter::Init(); + adapter = GCAdapter::Adapter::GetInstance(); } GCButton::~GCButton() { - GCAdapter::Shutdown(); + // GCAdapter::Shutdown(); } std::unique_ptr GCButtonFactory::Create(const Common::ParamPackage& params) { @@ -77,76 +77,76 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param trigger_if_greater = true; LOG_ERROR(Input, "Unknown direction {}", direction_name); } - return std::make_unique(port, axis, threshold, trigger_if_greater); + return std::make_unique(port, axis, threshold, trigger_if_greater, adapter); } std::unique_ptr button = - std::make_unique(port, button_id, params.Get("axis", 0)); + std::make_unique(port, button_id, params.Get("axis", 0), adapter); return std::move(button); } Common::ParamPackage GCButtonFactory::GetNextInput() { Common::ParamPackage params; - GCPadStatus pad; + GCAdapter::GCPadStatus pad; for (int i = 0; i < 4; i++) { - while (pad_queue[i].Pop(pad)) { + while (adapter->GetPadQueue()[i].Pop(pad)) { // This while loop will break on the earliest detected button params.Set("engine", "gcpad"); params.Set("port", i); // I was debating whether to keep these verbose for ease of reading // or to use a while loop shifting the bits to test and set the value. - if (pad.button & PAD_BUTTON_A) { - params.Set("button", PAD_BUTTON_A); + if (pad.button & GCAdapter::PAD_BUTTON_A) { + params.Set("button", GCAdapter::PAD_BUTTON_A); break; } - if (pad.button & PAD_BUTTON_B) { - params.Set("button", PAD_BUTTON_B); + if (pad.button & GCAdapter::PAD_BUTTON_B) { + params.Set("button", GCAdapter::PAD_BUTTON_B); break; } - if (pad.button & PAD_BUTTON_X) { - params.Set("button", PAD_BUTTON_X); + if (pad.button & GCAdapter::PAD_BUTTON_X) { + params.Set("button", GCAdapter::PAD_BUTTON_X); break; } - if (pad.button & PAD_BUTTON_Y) { - params.Set("button", PAD_BUTTON_Y); + if (pad.button & GCAdapter::PAD_BUTTON_Y) { + params.Set("button", GCAdapter::PAD_BUTTON_Y); break; } - if (pad.button & PAD_BUTTON_DOWN) { - params.Set("button", PAD_BUTTON_DOWN); + if (pad.button & GCAdapter::PAD_BUTTON_DOWN) { + params.Set("button", GCAdapter::PAD_BUTTON_DOWN); break; } - if (pad.button & PAD_BUTTON_LEFT) { - params.Set("button", PAD_BUTTON_LEFT); + if (pad.button & GCAdapter::PAD_BUTTON_LEFT) { + params.Set("button", GCAdapter::PAD_BUTTON_LEFT); break; } - if (pad.button & PAD_BUTTON_RIGHT) { - params.Set("button", PAD_BUTTON_RIGHT); + if (pad.button & GCAdapter::PAD_BUTTON_RIGHT) { + params.Set("button", GCAdapter::PAD_BUTTON_RIGHT); break; } - if (pad.button & PAD_BUTTON_UP) { - params.Set("button", PAD_BUTTON_UP); + if (pad.button & GCAdapter::PAD_BUTTON_UP) { + params.Set("button", GCAdapter::PAD_BUTTON_UP); break; } - if (pad.button & PAD_TRIGGER_L) { - params.Set("button", PAD_TRIGGER_L); + if (pad.button & GCAdapter::PAD_TRIGGER_L) { + params.Set("button", GCAdapter::PAD_TRIGGER_L); break; } - if (pad.button & PAD_TRIGGER_R) { - params.Set("button", PAD_TRIGGER_R); + if (pad.button & GCAdapter::PAD_TRIGGER_R) { + params.Set("button", GCAdapter::PAD_TRIGGER_R); break; } - if (pad.button & PAD_TRIGGER_Z) { - params.Set("button", PAD_TRIGGER_Z); + if (pad.button & GCAdapter::PAD_TRIGGER_Z) { + params.Set("button", GCAdapter::PAD_TRIGGER_Z); break; } - if (pad.button & PAD_BUTTON_START) { - params.Set("button", PAD_BUTTON_START); + if (pad.button & GCAdapter::PAD_BUTTON_START) { + params.Set("button", GCAdapter::PAD_BUTTON_START); break; } // For Axis button implementation - if (pad.axis_which != 255) { - params.Set("axis", pad.axis_which); - params.Set("button", PAD_STICK); + if (pad.axis != GCAdapter::PadAxes::Undefined) { + params.Set("axis", static_cast(pad.axis)); + params.Set("button", GCAdapter::PAD_STICK); if (pad.axis_value > 128) { params.Set("direction", "+"); params.Set("threshold", "0.5"); @@ -164,30 +164,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { void GCButtonFactory::BeginConfiguration() { polling = true; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::BeginConfiguration(); + adapter->BeginConfiguration(); } void GCButtonFactory::EndConfiguration() { polling = false; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::EndConfiguration(); + adapter->EndConfiguration(); } class GCAnalog final : public Input::AnalogDevice { public: - GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) - : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {} + GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) + : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} float GetAxis(int axis) const { std::lock_guard lock{mutex}; // division is not by a perfect 128 to account for some variance in center location // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range // [20-230] - return (state[port].axes.at(axis) - 128.0f) / 95.0f; + return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; } std::tuple GetAnalog(int axis_x, int axis_y) const { @@ -238,10 +238,13 @@ private: const int axis_y; const float deadzone; mutable std::mutex mutex; + GCAdapter::Adapter* gcadapter; }; /// An analog device factory that creates analog devices from GC Adapter -GCAnalogFactory::GCAnalogFactory(){}; +GCAnalogFactory::GCAnalogFactory() { + adapter = GCAdapter::Adapter::GetInstance(); +}; /** * Creates analog device from joystick axes @@ -257,35 +260,36 @@ std::unique_ptr GCAnalogFactory::Create(const Common::Param const int axis_y = params.Get("axis_y", 1); const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); - return std::make_unique(port, axis_x, axis_y, deadzone); + return std::make_unique(port, axis_x, axis_y, deadzone, adapter); } void GCAnalogFactory::BeginConfiguration() { polling = true; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::BeginConfiguration(); + adapter->BeginConfiguration(); } void GCAnalogFactory::EndConfiguration() { polling = false; for (int i = 0; i < 4; i++) { - pad_queue[i].Clear(); + adapter->GetPadQueue()[i].Clear(); } - GCAdapter::EndConfiguration(); + adapter->EndConfiguration(); } Common::ParamPackage GCAnalogFactory::GetNextInput() { - GCPadStatus pad; + GCAdapter::GCPadStatus pad; for (int i = 0; i < 4; i++) { - while (pad_queue[i].Pop(pad)) { - if (pad.axis_which == 255 || std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { + while (adapter->GetPadQueue()[i].Pop(pad)) { + if (pad.axis == GCAdapter::PadAxes::Undefined || + std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { 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. - const int axis = pad.axis_which; + const u8 axis = static_cast(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; controller_number = i; @@ -307,4 +311,5 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { } return params; } + } // namespace InputCommon -- cgit v1.2.3 From 968d631aa59a0a4e51e219eaa143d2b95593c3e7 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 21:15:58 -0400 Subject: std::arrays where appropriate, clear q in adapter class, other touch ups --- src/input_common/gcadapter/gc_poller.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 0e591baca..ac4126cb6 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -56,9 +56,7 @@ GCButtonFactory::GCButtonFactory() { adapter = GCAdapter::Adapter::GetInstance(); } -GCButton::~GCButton() { - // GCAdapter::Shutdown(); -} +GCButton::~GCButton() = default; std::unique_ptr GCButtonFactory::Create(const Common::ParamPackage& params) { int button_id = params.Get("button", 0); @@ -163,17 +161,11 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { void GCButtonFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) { - adapter->GetPadQueue()[i].Clear(); - } adapter->BeginConfiguration(); } void GCButtonFactory::EndConfiguration() { polling = false; - for (int i = 0; i < 4; i++) { - adapter->GetPadQueue()[i].Clear(); - } adapter->EndConfiguration(); } @@ -265,17 +257,11 @@ std::unique_ptr GCAnalogFactory::Create(const Common::Param void GCAnalogFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) { - adapter->GetPadQueue()[i].Clear(); - } adapter->BeginConfiguration(); } void GCAnalogFactory::EndConfiguration() { polling = false; - for (int i = 0; i < 4; i++) { - adapter->GetPadQueue()[i].Clear(); - } adapter->EndConfiguration(); } -- cgit v1.2.3 From 46b4461fbb0514dd50c096ef896b1752d81079d0 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 21:50:58 -0400 Subject: shared_ptr for the GC adapter class, constexpr constants --- src/input_common/gcadapter/gc_poller.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index ac4126cb6..ad8b4b431 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -14,7 +14,8 @@ namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_, GCAdapter::Adapter* adapter) + explicit GCButton(int port_, int button_, int axis_, + std::shared_ptr adapter) : port(port_), button(button_), gcadapter(adapter) {} ~GCButton() override; @@ -26,13 +27,13 @@ public: private: const int port; const int button; - GCAdapter::Adapter* gcadapter; + std::shared_ptr gcadapter; }; class GCAxisButton final : public Input::ButtonDevice { public: explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, - GCAdapter::Adapter* adapter) + std::shared_ptr adapter) : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), gcadapter(adapter) {} @@ -49,12 +50,11 @@ private: const int axis; float threshold; bool trigger_if_greater; - GCAdapter::Adapter* gcadapter; + std::shared_ptr gcadapter; }; -GCButtonFactory::GCButtonFactory() { - adapter = GCAdapter::Adapter::GetInstance(); -} +GCButtonFactory::GCButtonFactory(std::shared_ptr adapter_) + : adapter(adapter_) {} GCButton::~GCButton() = default; @@ -171,7 +171,8 @@ void GCButtonFactory::EndConfiguration() { class GCAnalog final : public Input::AnalogDevice { public: - GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) + GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, + std::shared_ptr adapter) : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} float GetAxis(int axis) const { @@ -230,13 +231,12 @@ private: const int axis_y; const float deadzone; mutable std::mutex mutex; - GCAdapter::Adapter* gcadapter; + std::shared_ptr gcadapter; }; /// An analog device factory that creates analog devices from GC Adapter -GCAnalogFactory::GCAnalogFactory() { - adapter = GCAdapter::Adapter::GetInstance(); -}; +GCAnalogFactory::GCAnalogFactory(std::shared_ptr adapter_) + : adapter(adapter_) {} /** * Creates analog device from joystick axes -- cgit v1.2.3 From 28046ae3a9cd5e32c7cae1cf64aa005502bf1749 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 23:56:56 -0400 Subject: Tidy up the pointers, use pair over tuple where appropriate --- src/input_common/gcadapter/gc_poller.cpp | 36 +++++++++++++++----------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') 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 { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_, - std::shared_ptr adapter) + explicit GCButton(int port_, int button_, int axis_, GCAdapter::Adapter* adapter) : port(port_), button(button_), gcadapter(adapter) {} ~GCButton() override; @@ -27,13 +26,13 @@ public: private: const int port; const int button; - std::shared_ptr gcadapter; + GCAdapter::Adapter* gcadapter; }; class GCAxisButton final : public Input::ButtonDevice { public: explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, - std::shared_ptr adapter) + GCAdapter::Adapter* adapter) : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), gcadapter(adapter) {} @@ -50,11 +49,11 @@ private: const int axis; float threshold; bool trigger_if_greater; - std::shared_ptr gcadapter; + GCAdapter::Adapter* gcadapter; }; GCButtonFactory::GCButtonFactory(std::shared_ptr adapter_) - : adapter(adapter_) {} + : adapter(std::move(adapter_)) {} GCButton::~GCButton() = default; @@ -75,11 +74,12 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param trigger_if_greater = true; LOG_ERROR(Input, "Unknown direction {}", direction_name); } - return std::make_unique(port, axis, threshold, trigger_if_greater, adapter); + return std::make_unique(port, axis, threshold, trigger_if_greater, + adapter.get()); } std::unique_ptr button = - std::make_unique(port, button_id, params.Get("axis", 0), adapter); + std::make_unique(port, button_id, params.Get("axis", 0), adapter.get()); return std::move(button); } @@ -171,8 +171,7 @@ void GCButtonFactory::EndConfiguration() { class GCAnalog final : public Input::AnalogDevice { public: - GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, - std::shared_ptr adapter) + GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} float GetAxis(int axis) const { @@ -183,7 +182,7 @@ public: return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; } - std::tuple GetAnalog(int axis_x, int axis_y) const { + std::pair GetAnalog(int axis_x, int axis_y) const { float x = GetAxis(axis_x); float y = GetAxis(axis_y); @@ -196,17 +195,17 @@ public: y /= r; } - return std::make_tuple(x, y); + return {x, y}; } std::tuple GetStatus() const override { const auto [x, y] = GetAnalog(axis_x, axis_y); const float r = std::sqrt((x * x) + (y * y)); if (r > deadzone) { - return std::make_tuple(x / r * (r - deadzone) / (1 - deadzone), - y / r * (r - deadzone) / (1 - deadzone)); + return {x / r * (r - deadzone) / (1 - deadzone), + y / r * (r - deadzone) / (1 - deadzone)}; } - return std::make_tuple(0.0f, 0.0f); + return {0.0f, 0.0f}; } bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { @@ -231,12 +230,12 @@ private: const int axis_y; const float deadzone; mutable std::mutex mutex; - std::shared_ptr gcadapter; + GCAdapter::Adapter* gcadapter; }; /// An analog device factory that creates analog devices from GC Adapter GCAnalogFactory::GCAnalogFactory(std::shared_ptr adapter_) - : adapter(adapter_) {} + : adapter(std::move(adapter_)) {} /** * Creates analog device from joystick axes @@ -246,13 +245,12 @@ GCAnalogFactory::GCAnalogFactory(std::shared_ptr adapter_) * - "axis_y": the index of the axis to be bind as y-axis */ std::unique_ptr GCAnalogFactory::Create(const Common::ParamPackage& params) { - const std::string guid = params.Get("guid", "0"); const int port = params.Get("port", 0); const int axis_x = params.Get("axis_x", 0); const int axis_y = params.Get("axis_y", 1); const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); - return std::make_unique(port, axis_x, axis_y, deadzone, adapter); + return std::make_unique(port, axis_x, axis_y, deadzone, adapter.get()); } void GCAnalogFactory::BeginConfiguration() { -- cgit v1.2.3 From 743e1f02a06187164d55f4208b8e85742abd4498 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 23 Jun 2020 17:37:15 -0400 Subject: cleanup check access, read, and factory GetNextInput funcs. Use size rather than magic number --- src/input_common/gcadapter/gc_poller.cpp | 74 ++++++++------------------------ 1 file changed, 18 insertions(+), 56 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index be7c600a2..977261884 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -58,8 +58,8 @@ GCButtonFactory::GCButtonFactory(std::shared_ptr adapter_) GCButton::~GCButton() = default; std::unique_ptr GCButtonFactory::Create(const Common::ParamPackage& params) { - int button_id = params.Get("button", 0); - int port = params.Get("port", 0); + const int button_id = params.Get("button", 0); + const int port = params.Get("port", 0); // For Axis buttons, used by the binary sticks. if (params.Has("axis")) { const int axis = params.Get("axis", 0); @@ -86,61 +86,22 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param Common::ParamPackage GCButtonFactory::GetNextInput() { Common::ParamPackage params; GCAdapter::GCPadStatus pad; - for (int i = 0; i < 4; i++) { - while (adapter->GetPadQueue()[i].Pop(pad)) { + auto& queue = adapter->GetPadQueue(); + for (int port = 0; port < queue.size(); port++) { + while (queue[port].Pop(pad)) { // This while loop will break on the earliest detected button params.Set("engine", "gcpad"); - params.Set("port", i); + params.Set("port", port); // I was debating whether to keep these verbose for ease of reading // or to use a while loop shifting the bits to test and set the value. - if (pad.button & GCAdapter::PAD_BUTTON_A) { - params.Set("button", GCAdapter::PAD_BUTTON_A); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_B) { - params.Set("button", GCAdapter::PAD_BUTTON_B); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_X) { - params.Set("button", GCAdapter::PAD_BUTTON_X); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_Y) { - params.Set("button", GCAdapter::PAD_BUTTON_Y); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_DOWN) { - params.Set("button", GCAdapter::PAD_BUTTON_DOWN); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_LEFT) { - params.Set("button", GCAdapter::PAD_BUTTON_LEFT); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_RIGHT) { - params.Set("button", GCAdapter::PAD_BUTTON_RIGHT); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_UP) { - params.Set("button", GCAdapter::PAD_BUTTON_UP); - break; - } - if (pad.button & GCAdapter::PAD_TRIGGER_L) { - params.Set("button", GCAdapter::PAD_TRIGGER_L); - break; - } - if (pad.button & GCAdapter::PAD_TRIGGER_R) { - params.Set("button", GCAdapter::PAD_TRIGGER_R); - break; - } - if (pad.button & GCAdapter::PAD_TRIGGER_Z) { - params.Set("button", GCAdapter::PAD_TRIGGER_Z); - break; - } - if (pad.button & GCAdapter::PAD_BUTTON_START) { - params.Set("button", GCAdapter::PAD_BUTTON_START); - break; + + for (auto button : GCAdapter::PadButtonArray) { + if (pad.button & button) { + params.Set("button", button); + break; + } } + // For Axis button implementation if (pad.axis != GCAdapter::PadAxes::Undefined) { params.Set("axis", static_cast(pad.axis)); @@ -265,8 +226,9 @@ void GCAnalogFactory::EndConfiguration() { Common::ParamPackage GCAnalogFactory::GetNextInput() { GCAdapter::GCPadStatus pad; - for (int i = 0; i < 4; i++) { - while (adapter->GetPadQueue()[i].Pop(pad)) { + auto& queue = adapter->GetPadQueue(); + for (int port = 0; port < queue.size(); port++) { + while (queue[port].Pop(pad)) { if (pad.axis == GCAdapter::PadAxes::Undefined || std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { continue; @@ -276,8 +238,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { const u8 axis = static_cast(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; - controller_number = i; - } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == i) { + controller_number = port; + } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { analog_y_axis = axis; } } -- cgit v1.2.3 From c18dc9c707235d7ba6fe230cb3045f2c13d04e62 Mon Sep 17 00:00:00 2001 From: Ameer Date: Wed, 24 Jun 2020 11:39:30 -0400 Subject: padbutton enum class and struct initiailization --- src/input_common/gcadapter/gc_poller.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 977261884..06e16880f 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -96,8 +96,9 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { // or to use a while loop shifting the bits to test and set the value. for (auto button : GCAdapter::PadButtonArray) { - if (pad.button & button) { - params.Set("button", button); + u16 button_value = static_cast(button); + if (pad.button & button_value) { + params.Set("button", button_value); break; } } @@ -105,7 +106,7 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { // For Axis button implementation if (pad.axis != GCAdapter::PadAxes::Undefined) { params.Set("axis", static_cast(pad.axis)); - params.Set("button", GCAdapter::PAD_STICK); + params.Set("button", static_cast(GCAdapter::PadButton::PAD_STICK)); if (pad.axis_value > 128) { params.Set("direction", "+"); params.Set("threshold", "0.5"); -- cgit v1.2.3 From a76e11e7f0c97222388bede03325aa71f1434510 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 30 Jun 2020 17:28:02 -0400 Subject: Address feedback regarding increments, const vars, and general cleanup --- src/input_common/gcadapter/gc_poller.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 06e16880f..a9de9fedf 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -39,9 +39,9 @@ public: bool GetStatus() const override { const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; if (trigger_if_greater) { - return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. + return axis_value > threshold; // TODO(ameerj) : Fix threshold. } - return axis_value < -0.10f; + return axis_value < -threshold; } private: @@ -87,16 +87,13 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { Common::ParamPackage params; GCAdapter::GCPadStatus pad; auto& queue = adapter->GetPadQueue(); - for (int port = 0; port < queue.size(); port++) { + for (std::size_t port = 0; port < queue.size(); ++port) { while (queue[port].Pop(pad)) { // This while loop will break on the earliest detected button params.Set("engine", "gcpad"); - params.Set("port", port); - // I was debating whether to keep these verbose for ease of reading - // or to use a while loop shifting the bits to test and set the value. - - for (auto button : GCAdapter::PadButtonArray) { - u16 button_value = static_cast(button); + params.Set("port", static_cast(port)); + for (const auto& button : GCAdapter::PadButtonArray) { + const u16 button_value = static_cast(button); if (pad.button & button_value) { params.Set("button", button_value); break; @@ -228,7 +225,7 @@ void GCAnalogFactory::EndConfiguration() { Common::ParamPackage GCAnalogFactory::GetNextInput() { GCAdapter::GCPadStatus pad; auto& queue = adapter->GetPadQueue(); - for (int port = 0; port < queue.size(); port++) { + for (std::size_t port = 0; port < queue.size(); ++port) { while (queue[port].Pop(pad)) { if (pad.axis == GCAdapter::PadAxes::Undefined || std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { -- cgit v1.2.3 From 6b7c8e469b2d7943cd7771648659bc362e5d1ddd Mon Sep 17 00:00:00 2001 From: Ameer Date: Thu, 2 Jul 2020 15:54:44 -0400 Subject: Add LR triggers as axes, half press to initiate a press, add GC axis id in config, clarify some code blocks for better readability --- src/input_common/gcadapter/gc_poller.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') 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 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(GCAdapter::PadButton::PAD_STICK); + + // button is not an axis/stick button + if (button_id != PAD_STICK_ID) { + std::unique_ptr button = + std::make_unique(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 GCButtonFactory::Create(const Common::Param return std::make_unique(port, axis, threshold, trigger_if_greater, adapter.get()); } - - std::unique_ptr button = - std::make_unique(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(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(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; -- cgit v1.2.3 From e69d715e3d42aaa5e99ebe8e578e64242d049a8c Mon Sep 17 00:00:00 2001 From: Ameer Date: Fri, 3 Jul 2020 11:52:07 -0400 Subject: Address lioncash feedback: Log formatting, extern const PadButtonArray, little touch ups --- src/input_common/gcadapter/gc_poller.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/input_common/gcadapter/gc_poller.cpp') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index a04c507b8..385ce8430 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -14,7 +14,7 @@ namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_, GCAdapter::Adapter* adapter) + explicit GCButton(int port_, int button_, GCAdapter::Adapter* adapter) : port(port_), button(button_), gcadapter(adapter) {} ~GCButton() override; @@ -45,7 +45,9 @@ public: bool GetStatus() const override { const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; if (trigger_if_greater) { - return axis_value > threshold; // TODO(ameerj) : Fix threshold. + // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently + // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick + return axis_value > threshold; } return axis_value < -threshold; } @@ -71,8 +73,7 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param // button is not an axis/stick button if (button_id != PAD_STICK_ID) { - std::unique_ptr button = - std::make_unique(port, button_id, params.Get("axis", 0), adapter.get()); + auto button = std::make_unique(port, button_id, adapter.get()); return std::move(button); } -- cgit v1.2.3