From 968d631aa59a0a4e51e219eaa143d2b95593c3e7 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 21:15:58 -0400 Subject: [PATCH] std::arrays where appropriate, clear q in adapter class, other touch ups --- src/input_common/gcadapter/gc_adapter.cpp | 16 +++++++++------- src/input_common/gcadapter/gc_adapter.h | 5 +++-- src/input_common/gcadapter/gc_poller.cpp | 16 +--------------- src/input_common/gcadapter/gc_poller.h | 4 ++-- src/input_common/main.cpp | 1 - 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 0696a96c7..498bd0d6e 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -134,7 +134,7 @@ void Adapter::Read() { payload_size = payload_size_in; } - GCPadStatus pad[4]; + std::array pad; if (payload_size != sizeof(controller_payload_copy) || controller_payload_copy[0] != LIBUSB_DT_HID) { LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size, @@ -224,9 +224,7 @@ void Adapter::Setup() { current_status = NO_ADAPTER_DETECTED; } - for (int i = 0; i < 4; i++) { - adapter_controllers_status[i] = ControllerTypes::None; - } + adapter_controllers_status.fill(ControllerTypes::None); libusb_device** devs; // pointer to list of connected usb devices @@ -332,9 +330,7 @@ void Adapter::Reset() { adapter_input_thread.join(); } - for (int i = 0; i < 4; i++) { - adapter_controllers_status[i] = ControllerTypes::None; - } + adapter_controllers_status.fill(ControllerTypes::None); current_status = NO_ADAPTER_DETECTED; @@ -354,10 +350,16 @@ void Adapter::ResetDeviceType(int port) { } void Adapter::BeginConfiguration() { + for (auto& pq : pad_queue) { + pq.Clear(); + } configuring = true; } void Adapter::EndConfiguration() { + for (auto& pq : pad_queue) { + pq.Clear(); + } configuring = false; } diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index a32ca0464..cb0dd0ab1 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -96,6 +96,8 @@ public: std::array, 4>& GetPadQueue(); std::array& GetPadState(); + std::array, 4>& GetPadQueue() const; + std::array& GetPadState() const; private: /// Singleton instance. @@ -139,8 +141,7 @@ private: int current_status = NO_ADAPTER_DETECTED; libusb_device_handle* usb_adapter_handle = nullptr; - ControllerTypes adapter_controllers_status[4] = {ControllerTypes::None, ControllerTypes::None, - ControllerTypes::None, ControllerTypes::None}; + std::array adapter_controllers_status{}; std::mutex s_mutex; 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(); } diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index 29b8c0b7c..31ff1c123 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h @@ -30,7 +30,7 @@ public: void BeginConfiguration(); void EndConfiguration(); - bool IsPolling() { + bool IsPolling() const { return polling; } @@ -50,7 +50,7 @@ public: void BeginConfiguration(); void EndConfiguration(); - bool IsPolling() { + bool IsPolling() const { return polling; } diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 536e5c80a..89dddf7cf 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include #include #include #include