ControllerInterface: Move axes/constants to derived class

This commit is contained in:
Connor McLaughlin 2021-05-07 20:39:46 +10:00
parent 9ff1f153be
commit e5a6103f74
5 changed files with 19 additions and 15 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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<std::array<AxisCallback, 3>, MAX_NUM_AXISES> axis_mapping;
std::array<std::array<AxisCallback, 3>, MAX_NUM_AXES> axis_mapping;
std::array<ButtonCallback, MAX_NUM_BUTTONS> button_mapping;
std::array<std::array<ButtonCallback, 2>, MAX_NUM_AXISES> axis_button_mapping;
std::array<std::array<ButtonCallback, 2>, MAX_NUM_AXES> axis_button_mapping;
std::array<AxisCallback, MAX_NUM_BUTTONS> button_axis_mapping;
std::vector<std::array<ButtonCallback, 4>> hat_button_mapping;

View File

@ -173,7 +173,7 @@ bool XInputControllerInterface::BindControllerAxis(int controller_index, int axi
if (static_cast<u32>(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<u32>(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<u32>(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<FrontendCommon::ControllerNavigationButton, MAX_NUM_BUTTONS> nav_button_mapping = {{
static constexpr std::array<FrontendCommon::ControllerNavigationButton, NUM_BUTTONS> nav_button_mapping = {{
FrontendCommon::ControllerNavigationButton::Activate, // XINPUT_GAMEPAD_A
FrontendCommon::ControllerNavigationButton::Cancel, // XINPUT_GAMEPAD_B
FrontendCommon::ControllerNavigationButton::Count, // XINPUT_GAMEPAD_X

View File

@ -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<std::array<AxisCallback, 3>, MAX_NUM_AXISES> axis_mapping;
std::array<ButtonCallback, MAX_NUM_BUTTONS> button_mapping;
std::array<std::array<ButtonCallback, 2>, MAX_NUM_AXISES> axis_button_mapping;
std::array<AxisCallback, MAX_NUM_BUTTONS> button_axis_mapping;
std::array<std::array<AxisCallback, 3>, NUM_AXES> axis_mapping;
std::array<ButtonCallback, NUM_BUTTONS> button_mapping;
std::array<std::array<ButtonCallback, 2>, NUM_AXES> axis_button_mapping;
std::array<AxisCallback, NUM_BUTTONS> button_axis_mapping;
};
using ControllerDataArray = std::array<ControllerData, XUSER_MAX_COUNT>;