mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-26 05:16:18 +00:00
DInput/XInput fixups.
- Fix DInput if XInput failed to load and you're using an XInput device. - Try to load XInput 1.4 first. It's installed by default on Win8. - Don't bother checking "system directory" explicitly, it already does.
This commit is contained in:
parent
00495aa9dd
commit
bcac9ded78
@ -28,7 +28,7 @@ DECL_BTN(left, h0left) \
|
||||
DECL_BTN(right, h0right) \
|
||||
DECL_BTN(l, 4) \
|
||||
DECL_BTN(r, 5) \
|
||||
DECL_BTN(l3, 8 )\
|
||||
DECL_BTN(l3, 8) \
|
||||
DECL_BTN(r3, 9) \
|
||||
DECL_BTN(menu_toggle, 10) \
|
||||
DECL_AXIS(l2, +4) \
|
||||
|
@ -349,7 +349,8 @@ const input_driver_t input_dinput = {
|
||||
// Keep track of which pad indexes are 360 controllers
|
||||
// not static, will be read in winxinput_joypad.c
|
||||
// -1 = not xbox pad, otherwise 0..3
|
||||
int g_xbox_pad_indexes[MAX_PLAYERS];
|
||||
int g_xinput_pad_indexes[MAX_PLAYERS];
|
||||
bool g_xinput_block_pads;
|
||||
|
||||
static void dinput_joypad_destroy(void)
|
||||
{
|
||||
@ -421,7 +422,7 @@ static const char* const XINPUT_PAD_NAMES[] =
|
||||
NULL
|
||||
};
|
||||
|
||||
static bool name_is_360_pad(const char* name)
|
||||
static bool name_is_xinput_pad(const char* name)
|
||||
{
|
||||
for (unsigned i = 0; ; ++i)
|
||||
{
|
||||
@ -435,8 +436,7 @@ static bool name_is_360_pad(const char* name)
|
||||
|
||||
// Forward declaration
|
||||
static const char *dinput_joypad_name(unsigned pad);
|
||||
|
||||
static int g_last_xbox_pad_index;
|
||||
static unsigned g_last_xinput_pad_index;
|
||||
|
||||
static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
|
||||
{
|
||||
@ -456,14 +456,12 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
|
||||
g_pads[g_joypad_cnt].joy_name = strdup(inst->tszProductName);
|
||||
|
||||
#ifdef HAVE_WINXINPUT
|
||||
bool is_360_pad = name_is_360_pad(inst->tszProductName);
|
||||
bool is_xinput_pad = g_xinput_block_pads && name_is_xinput_pad(inst->tszProductName);
|
||||
|
||||
if (is_360_pad)
|
||||
if (is_xinput_pad)
|
||||
{
|
||||
if (g_last_xbox_pad_index < 4)
|
||||
g_xbox_pad_indexes[g_joypad_cnt] = g_last_xbox_pad_index;
|
||||
++g_last_xbox_pad_index;
|
||||
|
||||
if (g_last_xinput_pad_index < 4)
|
||||
g_xinput_pad_indexes[g_joypad_cnt] = g_last_xinput_pad_index++;
|
||||
goto enum_iteration_done;
|
||||
}
|
||||
#endif
|
||||
@ -476,7 +474,7 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
|
||||
*pad, DIDFT_ABSAXIS);
|
||||
|
||||
#ifdef HAVE_WINXINPUT
|
||||
if (!is_360_pad)
|
||||
if (!is_xinput_pad)
|
||||
#endif
|
||||
{
|
||||
strlcpy(g_settings.input.device_names[g_joypad_cnt], dinput_joypad_name(g_joypad_cnt), sizeof(g_settings.input.device_names[g_joypad_cnt]));
|
||||
@ -493,11 +491,11 @@ static bool dinput_joypad_init(void)
|
||||
if (!dinput_init_context())
|
||||
return false;
|
||||
|
||||
g_last_xbox_pad_index = 0;
|
||||
g_last_xinput_pad_index = 0;
|
||||
|
||||
for (unsigned i = 0; i < MAX_PLAYERS; ++i)
|
||||
{
|
||||
g_xbox_pad_indexes[i] = -1;
|
||||
g_xinput_pad_indexes[i] = -1;
|
||||
g_pads[i].joy_name = NULL;
|
||||
}
|
||||
|
||||
@ -607,7 +605,7 @@ static void dinput_joypad_poll(void)
|
||||
{
|
||||
struct dinput_joypad *pad = &g_pads[i];
|
||||
|
||||
if ((pad->joypad) && (g_xbox_pad_indexes[i] == -1))
|
||||
if (pad->joypad && g_xinput_pad_indexes[i] < 0)
|
||||
{
|
||||
memset(&pad->joy_state, 0, sizeof(pad->joy_state));
|
||||
|
||||
@ -638,8 +636,6 @@ static bool dinput_joypad_query_pad(unsigned pad)
|
||||
return pad < MAX_PLAYERS && g_pads[pad].joypad;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const char *dinput_joypad_name(unsigned pad)
|
||||
{
|
||||
if (pad < MAX_PLAYERS)
|
||||
|
@ -83,7 +83,8 @@ typedef struct
|
||||
// hack is required here. dinput_joypad_init will fill this.
|
||||
// For each pad index, the appropriate entry will be set to -1 if it is not
|
||||
// a 360 pad, or the correct XInput player number (0..3 inclusive) if it is.
|
||||
extern int g_xbox_pad_indexes[MAX_PLAYERS];
|
||||
extern int g_xinput_pad_indexes[MAX_PLAYERS];
|
||||
extern bool g_xinput_block_pads;
|
||||
|
||||
// For xinput1_3.dll
|
||||
static HINSTANCE g_winxinput_dll;
|
||||
@ -105,7 +106,7 @@ static winxinput_joypad_state g_winxinput_states[4];
|
||||
|
||||
static inline int pad_index_to_xplayer_index(unsigned pad)
|
||||
{
|
||||
return g_xbox_pad_indexes[pad];
|
||||
return g_xinput_pad_indexes[pad];
|
||||
}
|
||||
|
||||
// Generic "XInput" instead of "Xbox 360", because there are
|
||||
@ -144,25 +145,21 @@ static bool winxinput_joypad_init(void)
|
||||
// No need to check for existance as we will be checking LoadLibrary's
|
||||
// success anyway.
|
||||
|
||||
// Note: Windows 8 ships with 1.4 but there doesn't
|
||||
// seem to be any compelling reason to use it.
|
||||
const char* DLL_NAME = "xinput1_3.dll";
|
||||
g_winxinput_dll = LoadLibrary(DLL_NAME); // Using dylib_* complicates building joyconfig.
|
||||
const char *version = "1.4";
|
||||
g_winxinput_dll = LoadLibrary("xinput1_4.dll"); // Using dylib_* complicates building joyconfig.
|
||||
if (!g_winxinput_dll)
|
||||
{
|
||||
// Loading from working dir failed, try to load from system.
|
||||
char dll_path[MAX_PATH];
|
||||
GetSystemDirectory(dll_path, sizeof(dll_path));
|
||||
strlcat(dll_path, "\\", 1);
|
||||
strlcat(dll_path, DLL_NAME, sizeof(DLL_NAME));
|
||||
g_winxinput_dll = LoadLibrary(dll_path);
|
||||
|
||||
if (!g_winxinput_dll)
|
||||
{
|
||||
RARCH_ERR("Failed to load xinput1_3.dll, ensure DirectX and controller drivers are up to date.\n");
|
||||
return false; // DLL does not exist or is invalid
|
||||
}
|
||||
g_winxinput_dll = LoadLibrary("xinput1_3.dll");
|
||||
version = "1.3";
|
||||
}
|
||||
|
||||
if (!g_winxinput_dll)
|
||||
{
|
||||
RARCH_ERR("Failed to load xinput1_3.dll, ensure DirectX and controller drivers are up to date.\n");
|
||||
return false; // DLL does not exist or is invalid
|
||||
}
|
||||
|
||||
RARCH_LOG("Found XInput v%s.\n", version);
|
||||
|
||||
// If we get here then an xinput DLL is correctly loaded.
|
||||
// First try to load ordinal 100 (XInputGetStateEx).
|
||||
@ -201,11 +198,16 @@ static bool winxinput_joypad_init(void)
|
||||
(!g_winxinput_states[2].connected) &&
|
||||
(!g_winxinput_states[3].connected))
|
||||
return false;
|
||||
|
||||
g_xinput_block_pads = true;
|
||||
|
||||
// We're going to have to be buddies with dinput if we want to be able
|
||||
// to use XI and non-XI controllers together.
|
||||
if (!dinput_joypad.init())
|
||||
{
|
||||
g_xinput_block_pads = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned autoconf_pad = 0; autoconf_pad < MAX_PLAYERS; autoconf_pad++)
|
||||
{
|
||||
@ -239,6 +241,7 @@ static void winxinput_joypad_destroy(void)
|
||||
g_XInputGetStateEx = NULL;
|
||||
|
||||
dinput_joypad.destroy();
|
||||
g_xinput_block_pads = false;
|
||||
}
|
||||
|
||||
// Buttons are provided by XInput as bits of a uint16.
|
||||
|
Loading…
x
Reference in New Issue
Block a user