diff --git a/input/drivers_joypad/xinput_hybrid_joypad.c b/input/drivers_joypad/xinput_hybrid_joypad.c index 57b78138a4..00db0956d0 100644 --- a/input/drivers_joypad/xinput_hybrid_joypad.c +++ b/input/drivers_joypad/xinput_hybrid_joypad.c @@ -220,15 +220,9 @@ static bool dinput_joypad_get_vidpid_from_xinput_index( /* Found XInput pad? */ if (index == g_xinput_pad_indexes[i]) { - if (vid) - *vid = g_pads[i].vid; - - if (pid) - *pid = g_pads[i].pid; - - if (dinput_index) - *dinput_index = i; - + *vid = g_pads[i].vid; + *pid = g_pads[i].pid; + *dinput_index = i; return true; } } @@ -520,23 +514,25 @@ static void xinput_joypad_destroy(void) static int16_t xinput_joypad_button(unsigned port, uint16_t joykey) { - int xuser = PAD_INDEX_TO_XUSER_INDEX(port); - uint16_t btn_word = 0; + int xuser = PAD_INDEX_TO_XUSER_INDEX(port); + xinput_joypad_state *state = &g_xinput_states[xuser]; + uint16_t btn_word = 0; if (xuser == -1) return dinput_joypad_button(port, joykey); - if (!(g_xinput_states[xuser].connected)) + if (!state->connected) 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); } static int16_t xinput_joypad_axis(unsigned port, uint32_t joyaxis) { - int xuser = PAD_INDEX_TO_XUSER_INDEX(port); - XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad); + int xuser = PAD_INDEX_TO_XUSER_INDEX(port); + xinput_joypad_state *state = &g_xinput_states[xuser]; + XINPUT_GAMEPAD *pad = &state->xstate.Gamepad; if (xuser == -1) return dinput_joypad_axis(port, joyaxis); - if (!(g_xinput_states[xuser].connected)) + if (!state->connected) return 0; return xinput_joypad_axis_state(pad, port, joyaxis); } @@ -548,15 +544,16 @@ static int16_t xinput_joypad_state_func( { unsigned i; uint16_t btn_word; - int16_t ret = 0; - uint16_t port_idx = joypad_info->joy_idx; - int xuser = PAD_INDEX_TO_XUSER_INDEX(port_idx); - XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad); + int16_t ret = 0; + uint16_t port_idx = joypad_info->joy_idx; + int xuser = PAD_INDEX_TO_XUSER_INDEX(port_idx); + xinput_joypad_state *state = &g_xinput_states[xuser]; + XINPUT_GAMEPAD *pad = &state->xstate.Gamepad; if (xuser == -1) return dinput_joypad_state(joypad_info, binds, port_idx); - if (!(g_xinput_states[xuser].connected)) + if (!state->connected) 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++) { @@ -585,12 +582,13 @@ static void xinput_joypad_poll(void) for (i = 0; i < 4; ++i) { - DWORD status = g_XInputGetStateEx(i, &(g_xinput_states[i].xstate)); - bool success = status == ERROR_SUCCESS; - bool new_connected = status != ERROR_DEVICE_NOT_CONNECTED; - if (new_connected != g_xinput_states[i].connected) + xinput_joypad_state *state = &g_xinput_states[i]; + DWORD status = g_XInputGetStateEx(i, &state->xstate); + bool success = (status == ERROR_SUCCESS); + 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) input_autoconfigure_disconnect(i, xinput_joypad_name(i)); } @@ -602,9 +600,7 @@ static void xinput_joypad_poll(void) HRESULT ret; struct dinput_joypad_data *pad = &g_pads[i]; bool polled = g_xinput_pad_indexes[i] < 0; - if (!polled) - continue; - if (!pad || !pad->joypad) + if (!polled || !pad || !pad->joypad) continue; pad->joy_state.lX = 0; diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index 969d748065..6eb55a8ad2 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -269,19 +269,21 @@ static void xinput_joypad_destroy(void) static int16_t xinput_joypad_button(unsigned port, uint16_t joykey) { - int xuser = pad_index_to_xuser_index(port); - uint16_t btn_word = 0; - if (!(g_xinput_states[xuser].connected)) + int xuser = pad_index_to_xuser_index(port); + uint16_t btn_word = 0; + xinput_joypad_state *state = &g_xinput_states[xuser]; + if (!state->connected) 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); } static int16_t xinput_joypad_axis(unsigned port, uint32_t joyaxis) { - int xuser = pad_index_to_xuser_index(port); - XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad); - if (!(g_xinput_states[xuser].connected)) + int xuser = pad_index_to_xuser_index(port); + xinput_joypad_state *state = &g_xinput_states[xuser]; + XINPUT_GAMEPAD *pad = &(state->xstate.Gamepad); + if (!state->connected) return 0; return xinput_joypad_axis_state(pad, port, joyaxis); } @@ -293,13 +295,14 @@ static int16_t xinput_joypad_state_func( { unsigned i; uint16_t btn_word; - int16_t ret = 0; - uint16_t port_idx = joypad_info->joy_idx; - int xuser = pad_index_to_xuser_index(port_idx); - XINPUT_GAMEPAD *pad = &(g_xinput_states[xuser].xstate.Gamepad); - if (!(g_xinput_states[xuser].connected)) + int16_t ret = 0; + uint16_t port_idx = joypad_info->joy_idx; + int xuser = pad_index_to_xuser_index(port_idx); + xinput_joypad_state *state = &g_xinput_states[xuser]; + XINPUT_GAMEPAD *pad = &state->xstate.Gamepad; + if (!state->connected) 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++) { @@ -328,10 +331,12 @@ static void xinput_joypad_poll(void) 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 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 * since dinput is not available on UWP we have to do it ourselves */ @@ -346,7 +351,7 @@ static void xinput_joypad_poll(void) return; } - g_xinput_states[i].connected = new_connected; + state->connected = new_connected; if (!success) input_autoconfigure_disconnect(i, xinput_joypad_name(i)); }