(drivers_joypad) Cleanups to wiiu_joypad and xdk_joypad

This commit is contained in:
twinaphex 2020-09-11 15:58:44 +02:00
parent 99cff42988
commit b4bbad494a
2 changed files with 25 additions and 25 deletions
input/drivers_joypad

@ -21,8 +21,8 @@
extern pad_connection_listener_t wiiu_pad_connection_listener;
/* TODO/FIXME - static globals */
static input_device_driver_t *pad_drivers[MAX_USERS];
static bool ready = false;
static input_device_driver_t *wiiu_pad_drivers[MAX_USERS];
static bool wiiu_joypad_ready = false;
static bool wiiu_joypad_init(void* data)
{
@ -36,7 +36,7 @@ static bool wiiu_joypad_init(void* data)
hidpad_driver.init(data);
#endif
ready = true;
wiiu_joypad_ready = true;
(void)data;
return true;
@ -44,15 +44,15 @@ static bool wiiu_joypad_init(void* data)
static bool wiiu_joypad_query_pad(unsigned pad)
{
return ready &&
return wiiu_joypad_ready &&
pad < MAX_USERS &&
pad_drivers[pad] &&
pad_drivers[pad]->query_pad(pad);
wiiu_pad_drivers[pad] &&
wiiu_pad_drivers[pad]->query_pad(pad);
}
static void wiiu_joypad_destroy(void)
{
ready = false;
wiiu_joypad_ready = false;
wpad_driver.destroy();
kpad_driver.destroy();
@ -67,21 +67,21 @@ static int16_t wiiu_joypad_button(unsigned port, uint16_t joykey)
return 0;
if (port >= DEFAULT_MAX_PADS)
return 0;
return (pad_drivers[port]->button(port, joykey));
return (wiiu_pad_drivers[port]->button(port, joykey));
}
static void wiiu_joypad_get_buttons(unsigned port, input_bits_t *state)
{
if (!wiiu_joypad_query_pad(port))
return;
pad_drivers[port]->get_buttons(port, state);
wiiu_pad_drivers[port]->get_buttons(port, state);
}
static int16_t wiiu_joypad_axis(unsigned port, uint32_t joyaxis)
{
if (!wiiu_joypad_query_pad(port))
return 0;
return pad_drivers[port]->axis(port, joyaxis);
return wiiu_pad_drivers[port]->axis(port, joyaxis);
}
static int16_t wiiu_joypad_state(
@ -107,11 +107,11 @@ static int16_t wiiu_joypad_state(
? binds[i].joyaxis : joypad_info->auto_binds[i].joyaxis;
if (
(uint16_t)joykey != NO_BTN
&& (pad_drivers[port]->button(port_idx, (uint16_t)joykey))
&& (wiiu_pad_drivers[port]->button(port_idx, (uint16_t)joykey))
)
ret |= ( 1 << i);
else if (joyaxis != AXIS_NONE &&
((float)abs(pad_drivers[port]->axis(port_idx, joyaxis))
((float)abs(wiiu_pad_drivers[port]->axis(port_idx, joyaxis))
/ 0x8000) > joypad_info->axis_threshold)
ret |= (1 << i);
}
@ -133,14 +133,14 @@ static const char* wiiu_joypad_name(unsigned pad)
if (!wiiu_joypad_query_pad(pad))
return "N/A";
return pad_drivers[pad]->name(pad);
return wiiu_pad_drivers[pad]->name(pad);
}
static void wiiu_joypad_connection_listener(unsigned pad,
input_device_driver_t *driver)
{
if (pad < MAX_USERS)
pad_drivers[pad] = driver;
wiiu_pad_drivers[pad] = driver;
}
input_device_driver_t wiiu_joypad =

@ -23,13 +23,13 @@
typedef struct
{
HANDLE id;
XINPUT_STATE xstate;
bool connected;
} xinput_joypad_state;
/* TODO/FIXME - static globals */
static xinput_joypad_state g_xinput_states[DEFAULT_MAX_PADS];
static HANDLE gamepads[DEFAULT_MAX_PADS];
static const char *xdk_joypad_name(unsigned pad)
{
@ -255,10 +255,10 @@ static void xdk_joypad_poll(void)
/* if the controller was removed after
* XGetDeviceChanges but before
* XInputOpen, the device handle will be NULL. */
if (gamepads[port])
XInputClose(gamepads[port]);
if (g_xinput_states[port].id)
XInputClose(g_xinput_states[port].id);
gamepads[port] = 0;
g_xinput_states[port].id = 0;
input_autoconfigure_disconnect(port, xdk_joypad.ident);
}
@ -272,27 +272,27 @@ static void xdk_joypad_poll(void)
m_pollingParameters.bInputInterval = 8;
m_pollingParameters.bOutputInterval = 8;
gamepads[port] = XInputOpen(
g_xinput_states[port].id = XInputOpen(
XDEVICE_TYPE_GAMEPAD, port,
XDEVICE_NO_SLOT, &m_pollingParameters);
xdk_joypad_autodetect_add(port);
}
if (!gamepads[port])
if (!g_xinput_states[port].id)
continue;
/* if the controller is removed after
* XGetDeviceChanges but before XInputOpen,
* the device handle will be NULL. */
if (XInputPoll(gamepads[port]) != ERROR_SUCCESS)
if (XInputPoll(g_xinput_states[port].id) != ERROR_SUCCESS)
continue;
memset(&g_xinput_states[port], 0, sizeof(xinput_joypad_state));
g_xinput_states[port].connected = !
(XInputGetState(
gamepads[port]
g_xinput_states[port].id
, &g_xinput_states[port].xstate) == ERROR_DEVICE_NOT_CONNECTED);
}
}
@ -309,9 +309,9 @@ static void xdk_joypad_destroy(void)
for (i = 0; i < DEFAULT_MAX_PADS; i++)
{
memset(&g_xinput_states[i], 0, sizeof(xinput_joypad_state));
if (gamepads[i])
XInputClose(gamepads[i]);
gamepads[i] = 0;
if (g_xinput_states[i].id)
XInputClose(g_xinput_states[i].id);
g_xinput_states[i].id = 0;
}
}