(xdk_joypad.c) Cleanups

This commit is contained in:
twinaphex 2018-01-21 01:43:19 +01:00
parent f884e5b0c8
commit 49c399217d

View File

@ -21,16 +21,13 @@
typedef struct
{
HANDLE handle;
XINPUT_STATE xstate;
bool connected;
} xinput_joypad_state;
static xinput_joypad_state g_xinput_states[MAX_PADS];
#ifdef _XBOX1
static HANDLE gamepads[MAX_PADS];
#endif
static const char* const XBOX_CONTROLLER_NAMES[4] =
{
"XInput Controller (User 1)",
@ -252,10 +249,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].handle)
XInputClose(g_xinput_states[port].handle);
gamepads[port] = 0;
g_xinput_states[port].handle = 0;
input_autoconfigure_disconnect(port, xdk_joypad.ident);
}
@ -269,20 +266,20 @@ static void xdk_joypad_poll(void)
m_pollingParameters.bInputInterval = 8;
m_pollingParameters.bOutputInterval = 8;
gamepads[port] = XInputOpen(
g_xinput_states[port].handle = XInputOpen(
XDEVICE_TYPE_GAMEPAD, port,
XDEVICE_NO_SLOT, &m_pollingParameters);
xdk_joypad_autodetect_add(port);
}
if (!gamepads[port])
if (!g_xinput_states[port].handle)
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].handle) != ERROR_SUCCESS)
continue;
#endif
@ -291,7 +288,7 @@ static void xdk_joypad_poll(void)
g_xinput_states[port].connected = !
(XInputGetState(
#ifdef _XBOX1
gamepads[port]
g_xinput_states[port].handle
#else
port
#endif
@ -312,9 +309,9 @@ static void xdk_joypad_destroy(void)
{
memset(&g_xinput_states[i], 0, sizeof(xinput_joypad_state));
#if defined(_XBOX1)
if (gamepads[i])
XInputClose(gamepads[i]);
gamepads[i] = 0;
if (g_xinput_states[i].handle)
XInputClose(g_xinput_states[i].handle);
g_x_input_states[i].handle = 0;
#endif
}
}