ControllerInterface: Move axes/constants to derived class
This commit is contained in:
parent
9ff1f153be
commit
e5a6103f74
|
@ -36,8 +36,6 @@ public:
|
||||||
|
|
||||||
enum : int
|
enum : int
|
||||||
{
|
{
|
||||||
MAX_NUM_AXISES = 7,
|
|
||||||
MAX_NUM_BUTTONS = 15,
|
|
||||||
NUM_HAT_DIRECTIONS = 4,
|
NUM_HAT_DIRECTIONS = 4,
|
||||||
HAT_DIRECTION_UP = 0,
|
HAT_DIRECTION_UP = 0,
|
||||||
HAT_DIRECTION_DOWN = 1,
|
HAT_DIRECTION_DOWN = 1,
|
||||||
|
|
|
@ -543,7 +543,7 @@ bool SDLControllerInterface::BindControllerAxis(int controller_index, int axis_n
|
||||||
if (it == m_controllers.end())
|
if (it == m_controllers.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (axis_number < 0 || axis_number >= MAX_NUM_AXISES)
|
if (axis_number < 0 || axis_number >= MAX_NUM_AXES)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
it->axis_mapping[axis_number][axis_side] = std::move(callback);
|
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())
|
if (it == m_controllers.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (axis_number < 0 || axis_number >= MAX_NUM_AXISES)
|
if (axis_number < 0 || axis_number >= MAX_NUM_AXES)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
it->axis_button_mapping[axis_number][BoolToUInt8(direction)] = std::move(callback);
|
it->axis_button_mapping[axis_number][BoolToUInt8(direction)] = std::move(callback);
|
||||||
|
|
|
@ -43,6 +43,12 @@ public:
|
||||||
bool ProcessSDLEvent(const union SDL_Event* event);
|
bool ProcessSDLEvent(const union SDL_Event* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum : int
|
||||||
|
{
|
||||||
|
MAX_NUM_AXES = 7,
|
||||||
|
MAX_NUM_BUTTONS = 16,
|
||||||
|
};
|
||||||
|
|
||||||
struct ControllerData
|
struct ControllerData
|
||||||
{
|
{
|
||||||
void* haptic;
|
void* haptic;
|
||||||
|
@ -56,9 +62,9 @@ private:
|
||||||
|
|
||||||
// TODO: Turn to vectors to support arbitrary amounts of buttons and axes (for Joysticks)
|
// 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
|
// 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<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::array<AxisCallback, MAX_NUM_BUTTONS> button_axis_mapping;
|
||||||
std::vector<std::array<ButtonCallback, 4>> hat_button_mapping;
|
std::vector<std::array<ButtonCallback, 4>> hat_button_mapping;
|
||||||
|
|
||||||
|
|
|
@ -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)
|
if (static_cast<u32>(controller_index) >= m_controllers.size() || !m_controllers[controller_index].connected)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (axis_number < 0 || axis_number >= NUM_AXISES)
|
if (axis_number < 0 || axis_number >= NUM_AXES)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_controllers[controller_index].axis_mapping[axis_number][axis_side] = std::move(callback);
|
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)
|
if (static_cast<u32>(controller_index) >= m_controllers.size() || !m_controllers[controller_index].connected)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (axis_number < 0 || axis_number >= MAX_NUM_AXISES)
|
if (axis_number < 0 || axis_number >= NUM_AXES)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_controllers[controller_index].axis_button_mapping[axis_number][BoolToUInt8(direction)] = std::move(callback);
|
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)
|
if (static_cast<u32>(controller_index) >= m_controllers.size() || !m_controllers[controller_index].connected)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (button_number < 0 || button_number >= MAX_NUM_BUTTONS)
|
if (button_number < 0 || button_number >= NUM_BUTTONS)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_controllers[controller_index].button_axis_mapping[button_number] = std::move(callback);
|
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");
|
Log_DevPrintf("controller %u button %u %s", index, button, pressed ? "pressed" : "released");
|
||||||
DebugAssert(index < XUSER_MAX_COUNT);
|
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::Activate, // XINPUT_GAMEPAD_A
|
||||||
FrontendCommon::ControllerNavigationButton::Cancel, // XINPUT_GAMEPAD_B
|
FrontendCommon::ControllerNavigationButton::Cancel, // XINPUT_GAMEPAD_B
|
||||||
FrontendCommon::ControllerNavigationButton::Count, // XINPUT_GAMEPAD_X
|
FrontendCommon::ControllerNavigationButton::Count, // XINPUT_GAMEPAD_X
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
private:
|
private:
|
||||||
enum : u32
|
enum : u32
|
||||||
{
|
{
|
||||||
NUM_AXISES = 6,
|
NUM_AXES = 6,
|
||||||
NUM_BUTTONS = 15,
|
NUM_BUTTONS = 15,
|
||||||
NUM_RUMBLE_MOTORS = 2
|
NUM_RUMBLE_MOTORS = 2
|
||||||
};
|
};
|
||||||
|
@ -63,10 +63,10 @@ private:
|
||||||
|
|
||||||
float deadzone = 0.25f;
|
float deadzone = 0.25f;
|
||||||
|
|
||||||
std::array<std::array<AxisCallback, 3>, MAX_NUM_AXISES> axis_mapping;
|
std::array<std::array<AxisCallback, 3>, NUM_AXES> axis_mapping;
|
||||||
std::array<ButtonCallback, MAX_NUM_BUTTONS> button_mapping;
|
std::array<ButtonCallback, NUM_BUTTONS> button_mapping;
|
||||||
std::array<std::array<ButtonCallback, 2>, MAX_NUM_AXISES> axis_button_mapping;
|
std::array<std::array<ButtonCallback, 2>, NUM_AXES> axis_button_mapping;
|
||||||
std::array<AxisCallback, MAX_NUM_BUTTONS> button_axis_mapping;
|
std::array<AxisCallback, NUM_BUTTONS> button_axis_mapping;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ControllerDataArray = std::array<ControllerData, XUSER_MAX_COUNT>;
|
using ControllerDataArray = std::array<ControllerData, XUSER_MAX_COUNT>;
|
||||||
|
|
Loading…
Reference in New Issue