(XInput) Cleanups
This commit is contained in:
parent
bbb4d12881
commit
a15a033e72
|
@ -220,15 +220,9 @@ static bool dinput_joypad_get_vidpid_from_xinput_index(
|
||||||
/* Found XInput pad? */
|
/* Found XInput pad? */
|
||||||
if (index == g_xinput_pad_indexes[i])
|
if (index == g_xinput_pad_indexes[i])
|
||||||
{
|
{
|
||||||
if (vid)
|
*vid = g_pads[i].vid;
|
||||||
*vid = g_pads[i].vid;
|
*pid = g_pads[i].pid;
|
||||||
|
*dinput_index = i;
|
||||||
if (pid)
|
|
||||||
*pid = g_pads[i].pid;
|
|
||||||
|
|
||||||
if (dinput_index)
|
|
||||||
*dinput_index = i;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,23 +514,25 @@ static void xinput_joypad_destroy(void)
|
||||||
|
|
||||||
static int16_t xinput_joypad_button(unsigned port, uint16_t joykey)
|
static int16_t xinput_joypad_button(unsigned port, uint16_t joykey)
|
||||||
{
|
{
|
||||||
int xuser = PAD_INDEX_TO_XUSER_INDEX(port);
|
int xuser = PAD_INDEX_TO_XUSER_INDEX(port);
|
||||||
uint16_t btn_word = 0;
|
xinput_joypad_state *state = &g_xinput_states[xuser];
|
||||||
|
uint16_t btn_word = 0;
|
||||||
if (xuser == -1)
|
if (xuser == -1)
|
||||||
return dinput_joypad_button(port, joykey);
|
return dinput_joypad_button(port, joykey);
|
||||||
if (!(g_xinput_states[xuser].connected))
|
if (!state->connected)
|
||||||
return 0;
|
return 0;
|
||||||
btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons;
|
btn_word = state->xstate.Gamepad.wButtons;
|
||||||
return xinput_joypad_button_state(xuser, btn_word, port, joykey);
|
return xinput_joypad_button_state(xuser, btn_word, port, joykey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t xinput_joypad_axis(unsigned port, uint32_t joyaxis)
|
static int16_t xinput_joypad_axis(unsigned port, uint32_t joyaxis)
|
||||||
{
|
{
|
||||||
int xuser = PAD_INDEX_TO_XUSER_INDEX(port);
|
int xuser = PAD_INDEX_TO_XUSER_INDEX(port);
|
||||||
XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad);
|
xinput_joypad_state *state = &g_xinput_states[xuser];
|
||||||
|
XINPUT_GAMEPAD *pad = &state->xstate.Gamepad;
|
||||||
if (xuser == -1)
|
if (xuser == -1)
|
||||||
return dinput_joypad_axis(port, joyaxis);
|
return dinput_joypad_axis(port, joyaxis);
|
||||||
if (!(g_xinput_states[xuser].connected))
|
if (!state->connected)
|
||||||
return 0;
|
return 0;
|
||||||
return xinput_joypad_axis_state(pad, port, joyaxis);
|
return xinput_joypad_axis_state(pad, port, joyaxis);
|
||||||
}
|
}
|
||||||
|
@ -548,15 +544,16 @@ static int16_t xinput_joypad_state_func(
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
uint16_t btn_word;
|
uint16_t btn_word;
|
||||||
int16_t ret = 0;
|
int16_t ret = 0;
|
||||||
uint16_t port_idx = joypad_info->joy_idx;
|
uint16_t port_idx = joypad_info->joy_idx;
|
||||||
int xuser = PAD_INDEX_TO_XUSER_INDEX(port_idx);
|
int xuser = PAD_INDEX_TO_XUSER_INDEX(port_idx);
|
||||||
XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad);
|
xinput_joypad_state *state = &g_xinput_states[xuser];
|
||||||
|
XINPUT_GAMEPAD *pad = &state->xstate.Gamepad;
|
||||||
if (xuser == -1)
|
if (xuser == -1)
|
||||||
return dinput_joypad_state(joypad_info, binds, port_idx);
|
return dinput_joypad_state(joypad_info, binds, port_idx);
|
||||||
if (!(g_xinput_states[xuser].connected))
|
if (!state->connected)
|
||||||
return 0;
|
return 0;
|
||||||
btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons;
|
btn_word = state->xstate.Gamepad.wButtons;
|
||||||
|
|
||||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||||
{
|
{
|
||||||
|
@ -585,12 +582,13 @@ static void xinput_joypad_poll(void)
|
||||||
|
|
||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
DWORD status = g_XInputGetStateEx(i, &(g_xinput_states[i].xstate));
|
xinput_joypad_state *state = &g_xinput_states[i];
|
||||||
bool success = status == ERROR_SUCCESS;
|
DWORD status = g_XInputGetStateEx(i, &state->xstate);
|
||||||
bool new_connected = status != ERROR_DEVICE_NOT_CONNECTED;
|
bool success = (status == ERROR_SUCCESS);
|
||||||
if (new_connected != g_xinput_states[i].connected)
|
bool new_connected = (status != ERROR_DEVICE_NOT_CONNECTED);
|
||||||
|
if (new_connected != state->connected)
|
||||||
{
|
{
|
||||||
g_xinput_states[i].connected = new_connected;
|
state->connected = new_connected;
|
||||||
if (!success)
|
if (!success)
|
||||||
input_autoconfigure_disconnect(i, xinput_joypad_name(i));
|
input_autoconfigure_disconnect(i, xinput_joypad_name(i));
|
||||||
}
|
}
|
||||||
|
@ -602,9 +600,7 @@ static void xinput_joypad_poll(void)
|
||||||
HRESULT ret;
|
HRESULT ret;
|
||||||
struct dinput_joypad_data *pad = &g_pads[i];
|
struct dinput_joypad_data *pad = &g_pads[i];
|
||||||
bool polled = g_xinput_pad_indexes[i] < 0;
|
bool polled = g_xinput_pad_indexes[i] < 0;
|
||||||
if (!polled)
|
if (!polled || !pad || !pad->joypad)
|
||||||
continue;
|
|
||||||
if (!pad || !pad->joypad)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pad->joy_state.lX = 0;
|
pad->joy_state.lX = 0;
|
||||||
|
|
|
@ -269,19 +269,21 @@ static void xinput_joypad_destroy(void)
|
||||||
|
|
||||||
static int16_t xinput_joypad_button(unsigned port, uint16_t joykey)
|
static int16_t xinput_joypad_button(unsigned port, uint16_t joykey)
|
||||||
{
|
{
|
||||||
int xuser = pad_index_to_xuser_index(port);
|
int xuser = pad_index_to_xuser_index(port);
|
||||||
uint16_t btn_word = 0;
|
uint16_t btn_word = 0;
|
||||||
if (!(g_xinput_states[xuser].connected))
|
xinput_joypad_state *state = &g_xinput_states[xuser];
|
||||||
|
if (!state->connected)
|
||||||
return 0;
|
return 0;
|
||||||
btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons;
|
btn_word = state->xstate.Gamepad.wButtons;
|
||||||
return xinput_joypad_button_state(xuser, btn_word, port, joykey);
|
return xinput_joypad_button_state(xuser, btn_word, port, joykey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t xinput_joypad_axis(unsigned port, uint32_t joyaxis)
|
static int16_t xinput_joypad_axis(unsigned port, uint32_t joyaxis)
|
||||||
{
|
{
|
||||||
int xuser = pad_index_to_xuser_index(port);
|
int xuser = pad_index_to_xuser_index(port);
|
||||||
XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad);
|
xinput_joypad_state *state = &g_xinput_states[xuser];
|
||||||
if (!(g_xinput_states[xuser].connected))
|
XINPUT_GAMEPAD *pad = &(state->xstate.Gamepad);
|
||||||
|
if (!state->connected)
|
||||||
return 0;
|
return 0;
|
||||||
return xinput_joypad_axis_state(pad, port, joyaxis);
|
return xinput_joypad_axis_state(pad, port, joyaxis);
|
||||||
}
|
}
|
||||||
|
@ -293,13 +295,14 @@ static int16_t xinput_joypad_state_func(
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
uint16_t btn_word;
|
uint16_t btn_word;
|
||||||
int16_t ret = 0;
|
int16_t ret = 0;
|
||||||
uint16_t port_idx = joypad_info->joy_idx;
|
uint16_t port_idx = joypad_info->joy_idx;
|
||||||
int xuser = pad_index_to_xuser_index(port_idx);
|
int xuser = pad_index_to_xuser_index(port_idx);
|
||||||
XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad);
|
xinput_joypad_state *state = &g_xinput_states[xuser];
|
||||||
if (!(g_xinput_states[xuser].connected))
|
XINPUT_GAMEPAD *pad = &state->xstate.Gamepad;
|
||||||
|
if (!state->connected)
|
||||||
return 0;
|
return 0;
|
||||||
btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons;
|
btn_word = state->xstate.Gamepad.wButtons;
|
||||||
|
|
||||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||||
{
|
{
|
||||||
|
@ -328,10 +331,12 @@ static void xinput_joypad_poll(void)
|
||||||
|
|
||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
DWORD status = g_XInputGetStateEx(i, &(g_xinput_states[i].xstate));
|
xinput_joypad_state
|
||||||
|
*state = &g_xinput_states[i];
|
||||||
|
DWORD status = g_XInputGetStateEx(i, &state->xstate);
|
||||||
bool success = status == ERROR_SUCCESS;
|
bool success = status == ERROR_SUCCESS;
|
||||||
bool new_connected = status != ERROR_DEVICE_NOT_CONNECTED;
|
bool new_connected = status != ERROR_DEVICE_NOT_CONNECTED;
|
||||||
if (new_connected != g_xinput_states[i].connected)
|
if (new_connected != state->connected)
|
||||||
{
|
{
|
||||||
/* Normally, dinput handles device insertion/removal for us, but
|
/* Normally, dinput handles device insertion/removal for us, but
|
||||||
* since dinput is not available on UWP we have to do it ourselves */
|
* since dinput is not available on UWP we have to do it ourselves */
|
||||||
|
@ -346,7 +351,7 @@ static void xinput_joypad_poll(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_xinput_states[i].connected = new_connected;
|
state->connected = new_connected;
|
||||||
if (!success)
|
if (!success)
|
||||||
input_autoconfigure_disconnect(i, xinput_joypad_name(i));
|
input_autoconfigure_disconnect(i, xinput_joypad_name(i));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue