(Xinput) This variable doesn't need to be set at every button call

This commit is contained in:
twinaphex 2019-07-23 14:32:46 +02:00
parent 02876aecae
commit e0672e46a5

View File

@ -129,7 +129,8 @@ typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*);
static XInputSetState_t g_XInputSetState;
/* Guide button may or may not be available */
static bool g_xinput_guide_button_supported;
static bool g_xinput_guide_button_supported = false;
static unsigned g_xinput_num_buttons = 0;
typedef struct
{
@ -229,7 +230,7 @@ static bool xinput_joypad_init(void *data)
#if defined(HAVE_DYNAMIC) && !defined(__WINRT__)
if (!g_xinput_dll)
if (!load_xinput_dll())
return false;
goto error;
/* If we get here then an xinput DLL is correctly loaded.
* First try to load ordinal 100 (XInputGetStateEx).
@ -264,7 +265,7 @@ static bool xinput_joypad_init(void *data)
dylib_close(g_xinput_dll);
#endif
/* DLL was loaded but did not contain the correct function. */
return false;
goto error;
}
RARCH_WARN("[XInput]: No guide button support.\n");
}
@ -281,7 +282,7 @@ static bool xinput_joypad_init(void *data)
#if defined(HAVE_DYNAMIC) && !defined(__WINRT__)
dylib_close(g_xinput_dll);
#endif
return false; /* DLL was loaded but did not contain the correct function. */
goto error; /* DLL was loaded but did not contain the correct function. */
}
/* Zero out the states. */
@ -301,9 +302,9 @@ static bool xinput_joypad_init(void *data)
(!g_xinput_states[2].connected) &&
(!g_xinput_states[3].connected))
#ifdef __WINRT__
return true;
goto succeeded;
#else
return false;
goto error;
#endif
RARCH_LOG("[XInput]: Pads connected: %d\n",
@ -320,7 +321,7 @@ static bool xinput_joypad_init(void *data)
if (!dinput_joypad.init(data))
{
g_xinput_block_pads = false;
return false;
goto error;
}
#endif
@ -355,7 +356,17 @@ static bool xinput_joypad_init(void *data)
}
}
#ifdef __WINRT__
succeeded:
#endif
/* non-hat button. */
g_xinput_num_buttons = g_xinput_guide_button_supported ? 11 : 10;
return true;
error:
/* non-hat button. */
g_xinput_num_buttons = g_xinput_guide_button_supported ? 11 : 10;
return false;
}
static bool xinput_joypad_query_pad(unsigned pad)
@ -413,7 +424,6 @@ static const uint16_t button_index_to_bitmap_code[] = {
static bool xinput_joypad_button(unsigned port_num, uint16_t joykey)
{
uint16_t btn_word = 0;
unsigned num_buttons = 0;
unsigned hat_dir = 0;
int xuser = pad_index_to_xuser_index(port_num);
@ -445,10 +455,7 @@ static bool xinput_joypad_button(unsigned port_num, uint16_t joykey)
return false; /* hat requested and no hat button down. */
}
/* non-hat button. */
num_buttons = g_xinput_guide_button_supported ? 11 : 10;
if (joykey < num_buttons)
if (joykey < g_xinput_num_buttons)
return btn_word & button_index_to_bitmap_code[joykey];
return false;