From e5a6103f74c34c09cde3889d7dab383b4d0630d1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 7 May 2021 20:39:46 +1000 Subject: [PATCH] ControllerInterface: Move axes/constants to derived class --- src/frontend-common/controller_interface.h | 2 -- src/frontend-common/sdl_controller_interface.cpp | 4 ++-- src/frontend-common/sdl_controller_interface.h | 10 ++++++++-- src/frontend-common/xinput_controller_interface.cpp | 8 ++++---- src/frontend-common/xinput_controller_interface.h | 10 +++++----- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/frontend-common/controller_interface.h b/src/frontend-common/controller_interface.h index f97d0f6cd..dd73a8ac7 100644 --- a/src/frontend-common/controller_interface.h +++ b/src/frontend-common/controller_interface.h @@ -36,8 +36,6 @@ public: enum : int { - MAX_NUM_AXISES = 7, - MAX_NUM_BUTTONS = 15, NUM_HAT_DIRECTIONS = 4, HAT_DIRECTION_UP = 0, HAT_DIRECTION_DOWN = 1, diff --git a/src/frontend-common/sdl_controller_interface.cpp b/src/frontend-common/sdl_controller_interface.cpp index 1ccf93676..07122ab18 100644 --- a/src/frontend-common/sdl_controller_interface.cpp +++ b/src/frontend-common/sdl_controller_interface.cpp @@ -543,7 +543,7 @@ bool SDLControllerInterface::BindControllerAxis(int controller_index, int axis_n if (it == m_controllers.end()) return false; - if (axis_number < 0 || axis_number >= MAX_NUM_AXISES) + if (axis_number < 0 || axis_number >= MAX_NUM_AXES) return false; it->axis_mapping[axis_number][axis_side] = std::move(callback); @@ -570,7 +570,7 @@ bool SDLControllerInterface::BindControllerAxisToButton(int controller_index, in if (it == m_controllers.end()) return false; - if (axis_number < 0 || axis_number >= MAX_NUM_AXISES) + if (axis_number < 0 || axis_number >= MAX_NUM_AXES) return false; it->axis_button_mapping[axis_number][BoolToUInt8(direction)] = std::move(callback); diff --git a/src/frontend-common/sdl_controller_interface.h b/src/frontend-common/sdl_controller_interface.h index 3d39edfcc..06963a5c8 100644 --- a/src/frontend-common/sdl_controller_interface.h +++ b/src/frontend-common/sdl_controller_interface.h @@ -43,6 +43,12 @@ public: bool ProcessSDLEvent(const union SDL_Event* event); private: + enum : int + { + MAX_NUM_AXES = 7, + MAX_NUM_BUTTONS = 16, + }; + struct ControllerData { void* haptic; @@ -56,9 +62,9 @@ private: // TODO: Turn to vectors to support arbitrary amounts of buttons and axes (for Joysticks) // Preferably implement a simple "flat map", an ordered view over a vector - std::array, MAX_NUM_AXISES> axis_mapping; + std::array, MAX_NUM_AXES> axis_mapping; std::array button_mapping; - std::array, MAX_NUM_AXISES> axis_button_mapping; + std::array, MAX_NUM_AXES> axis_button_mapping; std::array button_axis_mapping; std::vector> hat_button_mapping; diff --git a/src/frontend-common/xinput_controller_interface.cpp b/src/frontend-common/xinput_controller_interface.cpp index e62230c70..1f57bc583 100644 --- a/src/frontend-common/xinput_controller_interface.cpp +++ b/src/frontend-common/xinput_controller_interface.cpp @@ -173,7 +173,7 @@ bool XInputControllerInterface::BindControllerAxis(int controller_index, int axi if (static_cast(controller_index) >= m_controllers.size() || !m_controllers[controller_index].connected) return false; - if (axis_number < 0 || axis_number >= NUM_AXISES) + if (axis_number < 0 || axis_number >= NUM_AXES) return false; m_controllers[controller_index].axis_mapping[axis_number][axis_side] = std::move(callback); @@ -198,7 +198,7 @@ bool XInputControllerInterface::BindControllerAxisToButton(int controller_index, if (static_cast(controller_index) >= m_controllers.size() || !m_controllers[controller_index].connected) return false; - if (axis_number < 0 || axis_number >= MAX_NUM_AXISES) + if (axis_number < 0 || axis_number >= NUM_AXES) return false; m_controllers[controller_index].axis_button_mapping[axis_number][BoolToUInt8(direction)] = std::move(callback); @@ -218,7 +218,7 @@ bool XInputControllerInterface::BindControllerButtonToAxis(int controller_index, if (static_cast(controller_index) >= m_controllers.size() || !m_controllers[controller_index].connected) return false; - if (button_number < 0 || button_number >= MAX_NUM_BUTTONS) + if (button_number < 0 || button_number >= NUM_BUTTONS) return false; m_controllers[controller_index].button_axis_mapping[button_number] = std::move(callback); @@ -279,7 +279,7 @@ bool XInputControllerInterface::HandleButtonEvent(u32 index, u32 button, bool pr Log_DevPrintf("controller %u button %u %s", index, button, pressed ? "pressed" : "released"); DebugAssert(index < XUSER_MAX_COUNT); - static constexpr std::array nav_button_mapping = {{ + static constexpr std::array nav_button_mapping = {{ FrontendCommon::ControllerNavigationButton::Activate, // XINPUT_GAMEPAD_A FrontendCommon::ControllerNavigationButton::Cancel, // XINPUT_GAMEPAD_B FrontendCommon::ControllerNavigationButton::Count, // XINPUT_GAMEPAD_X diff --git a/src/frontend-common/xinput_controller_interface.h b/src/frontend-common/xinput_controller_interface.h index 8927ca3bf..5c549c44d 100644 --- a/src/frontend-common/xinput_controller_interface.h +++ b/src/frontend-common/xinput_controller_interface.h @@ -42,7 +42,7 @@ public: private: enum : u32 { - NUM_AXISES = 6, + NUM_AXES = 6, NUM_BUTTONS = 15, NUM_RUMBLE_MOTORS = 2 }; @@ -63,10 +63,10 @@ private: float deadzone = 0.25f; - std::array, MAX_NUM_AXISES> axis_mapping; - std::array button_mapping; - std::array, MAX_NUM_AXISES> axis_button_mapping; - std::array button_axis_mapping; + std::array, NUM_AXES> axis_mapping; + std::array button_mapping; + std::array, NUM_AXES> axis_button_mapping; + std::array button_axis_mapping; }; using ControllerDataArray = std::array;