Skip to content

Commit

Permalink
Restore support for SDL <2.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
987123879113 committed Oct 12, 2024
1 parent 9a2b312 commit 1bd56ba
Showing 1 changed file with 56 additions and 16 deletions.
72 changes: 56 additions & 16 deletions src/osd/modules/input/input_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ namespace osd {

namespace {

char const *const CONTROLLER_AXIS_XBOX[]{
[[maybe_unused]] char const *const CONTROLLER_AXIS_XBOX[]{
"LSX",
"LSY",
"RSX",
"RSY",
"LT",
"RT" };

char const *const CONTROLLER_AXIS_PS[]{
[[maybe_unused]] char const *const CONTROLLER_AXIS_PS[]{
"LSX",
"LSY",
"RSX",
"RSY",
"L2",
"R2" };

char const *const CONTROLLER_AXIS_SWITCH[]{
[[maybe_unused]] char const *const CONTROLLER_AXIS_SWITCH[]{
"LSX",
"LSY",
"RSX",
"RSY",
"ZL",
"ZR" };

char const *const CONTROLLER_BUTTON_XBOX360[]{
[[maybe_unused]] char const *const CONTROLLER_BUTTON_XBOX360[]{
"A",
"B",
"X",
Expand All @@ -103,7 +103,7 @@ char const *const CONTROLLER_BUTTON_XBOX360[]{
"P4",
"Touchpad" };

char const *const CONTROLLER_BUTTON_XBOXONE[]{
[[maybe_unused]] char const *const CONTROLLER_BUTTON_XBOXONE[]{
"A",
"B",
"X",
Expand All @@ -126,7 +126,7 @@ char const *const CONTROLLER_BUTTON_XBOXONE[]{
"P4",
"Touchpad" };

char const *const CONTROLLER_BUTTON_PS3[]{
[[maybe_unused]] char const *const CONTROLLER_BUTTON_PS3[]{
"Cross",
"Circle",
"Square",
Expand All @@ -149,7 +149,7 @@ char const *const CONTROLLER_BUTTON_PS3[]{
"P4",
"Touchpad" };

char const *const CONTROLLER_BUTTON_PS4[]{
[[maybe_unused]] char const *const CONTROLLER_BUTTON_PS4[]{
"Cross",
"Circle",
"Square",
Expand All @@ -172,7 +172,7 @@ char const *const CONTROLLER_BUTTON_PS4[]{
"P4",
"Touchpad" };

char const *const CONTROLLER_BUTTON_PS5[]{
[[maybe_unused]] char const *const CONTROLLER_BUTTON_PS5[]{
"Cross",
"Circle",
"Square",
Expand All @@ -195,7 +195,7 @@ char const *const CONTROLLER_BUTTON_PS5[]{
"P4",
"Touchpad" };

char const *const CONTROLLER_BUTTON_SWITCH[]{
[[maybe_unused]] char const *const CONTROLLER_BUTTON_SWITCH[]{
"A",
"B",
"X",
Expand All @@ -218,7 +218,7 @@ char const *const CONTROLLER_BUTTON_SWITCH[]{
"LSR",
"Touchpad" };

[[maybe_unused]] char const *const CONTROLLER_BUTTON_STADIA[]{
[[maybe_unused]] [[maybe_unused]] char const *const CONTROLLER_BUTTON_STADIA[]{
"A",
"B",
"X",
Expand Down Expand Up @@ -1499,7 +1499,10 @@ class sdl_game_controller_device : public sdl_joystick_device_base
char const *const *axisnames = CONTROLLER_AXIS_XBOX;
char const *const *buttonnames = CONTROLLER_BUTTON_XBOX360;
bool digitaltriggers = false;
#if !defined(SDLMAME_DDRMINI)
bool avoidpaddles = false;
#endif
#if !defined(SDLMAME_DDRMINI)
auto const ctrltype = SDL_GameControllerGetType(m_ctrldevice);
switch (ctrltype)
{
Expand Down Expand Up @@ -1532,12 +1535,14 @@ class sdl_game_controller_device : public sdl_joystick_device_base
buttonnames = CONTROLLER_BUTTON_SWITCH;
digitaltriggers = true;
break;
#if !defined(SDLMAME_DDRMINI)
//case SDL_CONTROLLER_TYPE_VIRTUAL:
case SDL_CONTROLLER_TYPE_PS5:
osd_printf_verbose("Game Controller: ... PlayStation 5 type\n");
axisnames = CONTROLLER_AXIS_PS;
buttonnames = CONTROLLER_BUTTON_PS5;
break;
#endif
#if SDL_VERSION_ATLEAST(2, 0, 16)
//case SDL_CONTROLLER_TYPE_AMAZON_LUNA:
case SDL_CONTROLLER_TYPE_GOOGLE_STADIA:
Expand Down Expand Up @@ -1566,6 +1571,7 @@ class sdl_game_controller_device : public sdl_joystick_device_base
osd_printf_verbose("Game Controller: ... unrecognized type (%d)\n", int(ctrltype));
break;
}
#endif

// keep track of item numbers as we add controls
std::pair<input_item_id, input_item_id> axisitems[SDL_CONTROLLER_AXIS_MAX];
Expand Down Expand Up @@ -1595,7 +1601,9 @@ class sdl_game_controller_device : public sdl_joystick_device_base
for (auto [axis, item, buttontest] : axes)
{
bool avail = !buttontest || !digitaltriggers;
#if !defined(SDLMAME_DDRMINI)
avail = avail && SDL_GameControllerHasAxis(m_ctrldevice, axis);
#endif
if (avail)
{
auto const binding = SDL_GameControllerGetBindForAxis(m_ctrldevice, axis);
Expand Down Expand Up @@ -1635,13 +1643,17 @@ class sdl_game_controller_device : public sdl_joystick_device_base
{ SDL_CONTROLLER_BUTTON_INVALID, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, true },
{ SDL_CONTROLLER_BUTTON_LEFTSTICK, SDL_CONTROLLER_AXIS_INVALID, true },
{ SDL_CONTROLLER_BUTTON_RIGHTSTICK, SDL_CONTROLLER_AXIS_INVALID, true },
#if !defined(SDLMAME_DDRMINI)
{ SDL_CONTROLLER_BUTTON_PADDLE1, SDL_CONTROLLER_AXIS_INVALID, true },
{ SDL_CONTROLLER_BUTTON_PADDLE2, SDL_CONTROLLER_AXIS_INVALID, true },
{ SDL_CONTROLLER_BUTTON_PADDLE3, SDL_CONTROLLER_AXIS_INVALID, true },
{ SDL_CONTROLLER_BUTTON_PADDLE4, SDL_CONTROLLER_AXIS_INVALID, true },
#endif
{ SDL_CONTROLLER_BUTTON_GUIDE, SDL_CONTROLLER_AXIS_INVALID, false },
#if !defined(SDLMAME_DDRMINI)
{ SDL_CONTROLLER_BUTTON_MISC1, SDL_CONTROLLER_AXIS_INVALID, false },
{ SDL_CONTROLLER_BUTTON_TOUCHPAD, SDL_CONTROLLER_AXIS_INVALID, false },
#endif
};
input_item_id button_item = ITEM_ID_BUTTON1;
unsigned buttoncount = 0;
Expand All @@ -1651,7 +1663,9 @@ class sdl_game_controller_device : public sdl_joystick_device_base
input_item_id actual = ITEM_ID_INVALID;
if (SDL_CONTROLLER_BUTTON_INVALID != button)
{
#if !defined(SDLMAME_DDRMINI)
avail = SDL_GameControllerHasButton(m_ctrldevice, button);
#endif
if (avail)
{
auto const binding = SDL_GameControllerGetBindForButton(m_ctrldevice, button);
Expand All @@ -1678,7 +1692,9 @@ class sdl_game_controller_device : public sdl_joystick_device_base
}
else
{
#if !defined(SDLMAME_DDRMINI)
avail = SDL_GameControllerHasAxis(m_ctrldevice, axis);
#endif
if (avail)
{
auto const binding = SDL_GameControllerGetBindForAxis(m_ctrldevice, axis);
Expand Down Expand Up @@ -1728,7 +1744,9 @@ class sdl_game_controller_device : public sdl_joystick_device_base
for (auto [button, item] : fixedbuttons)
{
bool avail = true;
#if !defined(SDLMAME_DDRMINI)
avail = SDL_GameControllerHasButton(m_ctrldevice, button);
#endif
if (avail)
{
auto const binding = SDL_GameControllerGetBindForButton(m_ctrldevice, button);
Expand Down Expand Up @@ -1799,6 +1817,7 @@ class sdl_game_controller_device : public sdl_joystick_device_base
{
// took trigger buttons
}
#if !defined(SDLMAME_DDRMINI)
else if (add_axis_inc_dec_assignment(assignments, IPT_AD_STICK_Z, buttonitems[SDL_CONTROLLER_BUTTON_PADDLE1], buttonitems[SDL_CONTROLLER_BUTTON_PADDLE2]))
{
// took P1/P2
Expand All @@ -1807,6 +1826,7 @@ class sdl_game_controller_device : public sdl_joystick_device_base
{
// took P3/P4
}
#endif
}

// prefer trigger axes for pedals, otherwise take half axes and buttons
Expand Down Expand Up @@ -1892,18 +1912,22 @@ class sdl_game_controller_device : public sdl_joystick_device_base
{
// took digital triggers
}
#if !defined(SDLMAME_DDRMINI)
else if (!avoidpaddles && consume_button_pair(assignments, IPT_UI_PREV_GROUP, IPT_UI_NEXT_GROUP, buttonitems[SDL_CONTROLLER_BUTTON_PADDLE1], buttonitems[SDL_CONTROLLER_BUTTON_PADDLE2]))
{
// took upper paddles
}
#endif
else if (consume_trigger_pair(assignments, IPT_UI_PREV_GROUP, IPT_UI_NEXT_GROUP, axisitems[SDL_CONTROLLER_AXIS_TRIGGERLEFT].first, axisitems[SDL_CONTROLLER_AXIS_TRIGGERRIGHT].first))
{
// took analog triggers
}
#if !defined(SDLMAME_DDRMINI)
else if (!avoidpaddles && consume_button_pair(assignments, IPT_UI_PREV_GROUP, IPT_UI_NEXT_GROUP, buttonitems[SDL_CONTROLLER_BUTTON_PADDLE3], buttonitems[SDL_CONTROLLER_BUTTON_PADDLE4]))
{
// took lower paddles
}
#endif
else if (consume_axis_pair(assignments, IPT_UI_PREV_GROUP, IPT_UI_NEXT_GROUP, diraxis[1][1]))
{
// took secondary Y
Expand All @@ -1912,7 +1936,7 @@ class sdl_game_controller_device : public sdl_joystick_device_base
{
// took secondary X
}

#if !defined(SDLMAME_DDRMINI)
// try to get a matching pair of buttons for page up/down
if (!avoidpaddles && consume_button_pair(assignments, IPT_UI_PAGE_UP, IPT_UI_PAGE_DOWN, buttonitems[SDL_CONTROLLER_BUTTON_PADDLE1], buttonitems[SDL_CONTROLLER_BUTTON_PADDLE2]))
{
Expand All @@ -1923,6 +1947,7 @@ class sdl_game_controller_device : public sdl_joystick_device_base
// took lower paddles
}
else
#endif
if (consume_trigger_pair(assignments, IPT_UI_PAGE_UP, IPT_UI_PAGE_DOWN, axisitems[SDL_CONTROLLER_AXIS_TRIGGERLEFT].first, axisitems[SDL_CONTROLLER_AXIS_TRIGGERRIGHT].first))
{
// took analog triggers
Expand Down Expand Up @@ -2463,7 +2488,10 @@ class sdl_joystick_module_base : public sdl_input_module<sdl_joystick_device_bas
char guid_str[256];
guid_str[0] = '\0';
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str) - 1);
char const *const serial = SDL_JoystickGetSerial(joy);
char const *serial = nullptr;
#if !defined(SDLMAME_DDRMINI)
serial = SDL_JoystickGetSerial(joy);
#endif
std::string id(guid_str);
if (serial)
id.append(1, '-').append(serial);
Expand Down Expand Up @@ -2600,7 +2628,10 @@ class sdl_joystick_module : public sdl_joystick_module_base
else
{
SDL_JoystickGUID guid = SDL_JoystickGetGUID(joy);
char const *const serial = SDL_JoystickGetSerial(joy);
char const *serial = nullptr;
#if !defined(SDLMAME_DDRMINI)
serial = SDL_JoystickGetSerial(joy);
#endif
auto *const target_device = find_reconnect_match(guid, serial);
if (target_device)
{
Expand Down Expand Up @@ -2750,7 +2781,10 @@ class sdl_game_controller_module : public sdl_joystick_module_base
}

SDL_JoystickGUID guid = SDL_JoystickGetGUID(joy);
char const *const serial = SDL_JoystickGetSerial(joy);
char const *serial = nullptr;
#if !defined(SDLMAME_DDRMINI)
serial = SDL_JoystickGetSerial(joy);
#endif
auto *const target_device = find_reconnect_match(guid, serial);
if (target_device)
{
Expand Down Expand Up @@ -2780,7 +2814,10 @@ class sdl_game_controller_module : public sdl_joystick_module_base
}

SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(event.cdevice.which);
char const *const serial = SDL_GameControllerGetSerial(ctrl);
char const *serial = nullptr;
#if !defined(SDLMAME_DDRMINI)
serial = SDL_GameControllerGetSerial(ctrl);
#endif
auto *const target_device = find_reconnect_match(guid, serial);
if (target_device)
{
Expand Down Expand Up @@ -2812,7 +2849,10 @@ class sdl_game_controller_module : public sdl_joystick_module_base
char guid_str[256];
guid_str[0] = '\0';
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str) - 1);
char const *const serial = SDL_GameControllerGetSerial(ctrl);
char const *serial = nullptr;
#if !defined(SDLMAME_DDRMINI)
serial = SDL_GameControllerGetSerial(ctrl);
#endif
std::string id(guid_str);
if (serial)
id.append(1, '-').append(serial);
Expand Down

0 comments on commit 1bd56ba

Please sign in to comment.