From 5b3a1e0c55604fcf588cce5b7e4e40a81e921f46 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 06:28:34 -0500 Subject: [PATCH 01/21] Implement EXECVERSION consvar to invalidate previous versions' default config values --- src/command.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++- src/command.h | 6 ++ src/m_misc.c | 26 +++++++ 3 files changed, 242 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index 5d028d36..454bc76d 100644 --- a/src/command.c +++ b/src/command.c @@ -49,6 +49,7 @@ static void COM_Wait_f(void); static void COM_Help_f(void); static void COM_Toggle_f(void); +static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr); static boolean CV_Command(void); static consvar_t *CV_FindVar(const char *name); static const char *CV_StringValue(const char *var_name); @@ -62,6 +63,17 @@ CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}}; CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}}; CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; +// Filter consvars by MODVERSION +// First implementation is 26 (2.1.21), so earlier configs default at 25 (2.1.20) +// Also set CV_HIDEN during runtime, after config is loaded +consvar_t cv_execversion = {"execversion","25",CV_SAVE,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; + +// for default joyaxis detection +static boolean joyaxis_default = false; +static boolean joyaxis2_default = false; +static INT32 joyaxis_count = 0; +static INT32 joyaxis2_count = 0; + #define COM_BUF_SIZE 8192 // command buffer size #define MAX_ALIAS_RECURSION 100 // max recursion allowed for aliases @@ -1568,6 +1580,199 @@ void CV_AddValue(consvar_t *var, INT32 increment) var->changed = 1; // user has changed it now } +void CV_InitFilterVar(void) +{ + joyaxis_default = joyaxis2_default = true; + joyaxis_count = joyaxis2_count = 0; +} + +static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr) +{ + // If ALL axis settings are previous defaults, set them to the new defaults + // MODVERSION < 26 (2.1.21) + + if (joyaxis_default) + { +#if !defined (_WII) && !defined (WMINPUT) + if (!stricmp(v->name, "joyaxis_turn")) + { + if (joyaxis_count > 6) return false; + // we're currently setting the new defaults, don't interfere + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "X-Axis")) joyaxis_count++; + else joyaxis_default = false; + } +#if !defined (PSP) + if (!stricmp(v->name, "joyaxis_move")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "Y-Axis")) joyaxis_count++; + else joyaxis_default = false; + } +#endif +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (PSP) + if (!stricmp(v->name, "joyaxis_side")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "Z-Axis")) joyaxis_count++; + else joyaxis_default = false; + } +#endif +#if !defined (_XBOX) && !defined (PSP) + if (!stricmp(v->name, "joyaxis_look")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis_count++; + else joyaxis_default = false; + } +#endif + if (!stricmp(v->name, "joyaxis_fire") + || !stricmp(v->name, "joyaxis_firenormal")) + { + if (joyaxis_count > 6) return false; + else if (joyaxis_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis_count++; + else joyaxis_default = false; + } +#endif + // reset all axis settings to defaults + if (joyaxis_count == 6) + { + COM_BufInsertText(va("%s \"%s\"\n", cv_turnaxis.name, cv_turnaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_moveaxis.name, cv_moveaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_sideaxis.name, cv_sideaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_lookaxis.name, cv_lookaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_fireaxis.name, cv_fireaxis.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_firenaxis.name, cv_firenaxis.defaultvalue)); + joyaxis_count++; + return false; + } + } + + if (joyaxis2_default) + { +#if !defined (_WII) && !defined (WMINPUT) + if (!stricmp(v->name, "joyaxis2_turn")) + { + if (joyaxis2_count > 6) return false; + // we're currently setting the new defaults, don't interfere + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "X-Axis")) joyaxis2_count++; + else joyaxis2_default = false; + } +// #if !defined (PSP) + if (!stricmp(v->name, "joyaxis2_move")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "Y-Axis")) joyaxis2_count++; + else joyaxis2_default = false; + } +// #endif +#if !defined (_arch_dreamcast) && !defined (_XBOX) && !defined (PSP) + if (!stricmp(v->name, "joyaxis2_side")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "Z-Axis")) joyaxis2_count++; + else joyaxis2_default = false; + } +#endif +#if !defined (_XBOX) // && !defined (PSP) + if (!stricmp(v->name, "joyaxis2_look")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis2_count++; + else joyaxis2_default = false; + } +#endif + if (!stricmp(v->name, "joyaxis2_fire") + || !stricmp(v->name, "joyaxis2_firenormal")) + { + if (joyaxis2_count > 6) return false; + else if (joyaxis2_count == 6) return true; + + if (!stricmp(valstr, "None")) joyaxis2_count++; + else joyaxis2_default = false; + } +#endif + + // reset all axis settings to defaults + if (joyaxis2_count == 6) + { + COM_BufInsertText(va("%s \"%s\"\n", cv_turnaxis2.name, cv_turnaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_moveaxis2.name, cv_moveaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_sideaxis2.name, cv_sideaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_lookaxis2.name, cv_lookaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_fireaxis2.name, cv_fireaxis2.defaultvalue)); + COM_BufInsertText(va("%s \"%s\"\n", cv_firenaxis2.name, cv_firenaxis2.defaultvalue)); + joyaxis2_count++; + return false; + } + } + + // we haven't reached our counts yet, or we're not default + return true; +} + +static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) +{ + // True means allow the CV change, False means block it + + // We only care about CV_SAVE because this filters the user's config files + // We do this same check in CV_Command + if (!(v->flags & CV_SAVE)) + return true; + + // We go by MODVERSION here + if (cv_execversion.value < 26) // 26 = 2.1.21 + { + // MOUSE SETTINGS + // alwaysfreelook split between first and third person (chasefreelook) + // mousemove was on by default, which invalidates the current approach + if (!stricmp(v->name, "alwaysfreelook")) + return false; + if (!stricmp(v->name, "mousemove")) + return false; + + // mousesens was changed from 35 to 20 due to oversensitivity + if ((!stricmp(v->name, "mousesens") + || !stricmp(v->name, "mousesens2") + || !stricmp(v->name, "mouseysens") + || !stricmp(v->name, "mouseysens2")) + && atoi(valstr) == 35) + return false; + + // JOYSTICK DEFAULTS + // use_joystick was changed from 0 to 1 to automatically use a joystick if available +#if defined(HAVE_SDL) || defined(_WINDOWS) + if ((!stricmp(v->name, "use_joystick") + || !stricmp(v->name, "use_joystick2")) + && atoi(valstr) == 0) + return false; +#endif + + // axis defaults were changed to be friendly to 360 controllers + // if ALL axis settings are defaults, then change them to new values + if (!CV_FilterJoyAxisVars(v, valstr)) + return false; + } + return true; +} + /** Displays or changes a variable from the console. * Since the user is presumed to have been directly responsible * for this change, the variable is marked as changed this game. @@ -1592,8 +1797,11 @@ static boolean CV_Command(void) return true; } - CV_Set(v, COM_Argv(1)); - v->changed = 1; // now it's been changed by (presumably) the user + if (!(v->flags & CV_SAVE) || CV_FilterVarByVersion(v, COM_Argv(1))) + { + CV_Set(v, COM_Argv(1)); + v->changed = 1; // now it's been changed by (presumably) the user + } return true; } diff --git a/src/command.h b/src/command.h index 7420c210..8dee1174 100644 --- a/src/command.h +++ b/src/command.h @@ -125,6 +125,12 @@ extern CV_PossibleValue_t CV_OnOff[]; extern CV_PossibleValue_t CV_YesNo[]; extern CV_PossibleValue_t CV_Unsigned[]; extern CV_PossibleValue_t CV_Natural[]; + +// Filter consvars by version +extern consvar_t cv_execversion; + +void CV_InitFilterVar(void); + // register a variable for use at the console void CV_RegisterVar(consvar_t *variable); diff --git a/src/m_misc.c b/src/m_misc.c index f8014104..760894a6 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -37,6 +37,7 @@ #include "d_main.h" #include "m_argv.h" #include "i_system.h" +#include "command.h" // cv_execversion #include "m_anigif.h" @@ -440,7 +441,18 @@ void Command_LoadConfig_f(void) strcpy(configfile, COM_Argv(1)); FIL_ForceExtension(configfile, ".cfg"); + + // temporarily reset execversion to default + cv_execversion.flags &= ~CV_HIDEN; + COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue)); + CV_InitFilterVar(); + + // exec the config COM_BufInsertText(va("exec \"%s\"\n", configfile)); + + // don't filter anymore vars and don't let this convsvar be changed + COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, MODVERSION)); + cv_execversion.flags |= CV_HIDEN; } /** Saves the current configuration and loads another. @@ -477,10 +489,20 @@ void M_FirstLoadConfig(void) // load default control G_Controldefault(); + // temporarily reset execversion to default + // we shouldn't need to do this, but JUST in case... + cv_execversion.flags &= ~CV_HIDEN; + COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue)); + CV_InitFilterVar(); + // load config, make sure those commands doesnt require the screen... COM_BufInsertText(va("exec \"%s\"\n", configfile)); // no COM_BufExecute() needed; that does it right away + // don't filter anymore vars and don't let this convsvar be changed + COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, MODVERSION)); + cv_execversion.flags |= CV_HIDEN; + // make sure I_Quit() will write back the correct config // (do not write back the config if it crash before) gameconfig_loaded = true; @@ -536,6 +558,10 @@ void M_SaveConfig(const char *filename) // header message fprintf(f, "// SRB2 configuration file.\n"); + // print execversion FIRST, because subsequent consvars need to be filtered + // always print current MODVERSION + fprintf(f, "%s \"%d\"\n", cv_execversion.name, MODVERSION); + // FIXME: save key aliases if ever implemented.. CV_SaveVariables(f); From 70aa4ce18e9c52dd7ef8627abd66dea0a5f640ee Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 11:59:34 -0500 Subject: [PATCH 02/21] Add alwaysfreelook2 and mousemove2 to config versioning * Change alwaysfreelook2 to be consistent with alwaysfreelook (the only one that wasn't the same) --- src/command.c | 7 +++++-- src/g_game.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index 454bc76d..cc208e94 100644 --- a/src/command.c +++ b/src/command.c @@ -1743,9 +1743,12 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) // MOUSE SETTINGS // alwaysfreelook split between first and third person (chasefreelook) // mousemove was on by default, which invalidates the current approach - if (!stricmp(v->name, "alwaysfreelook")) + if (!stricmp(v->name, "alwaysfreelook") + || !stricmp(v->name, "alwaysfreelook2") + || !stricmp(v->name, "mousemove") + || !stricmp(v->name, "mousemove2")) return false; - if (!stricmp(v->name, "mousemove")) + if () return false; // mousesens was changed from 35 to 20 due to oversensitivity diff --git a/src/g_game.c b/src/g_game.c index 67f482e3..1b782a68 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -352,7 +352,7 @@ consvar_t cv_crosshair2 = {"crosshair2", "Cross", CV_SAVE, crosshair_cons_t, NUL consvar_t cv_invertmouse = {"invertmouse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_invertmouse2 = {"invertmouse2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_alwaysfreelook = {"alwaysmlook", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_alwaysfreelook2 = {"alwaysmlook2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_alwaysfreelook2 = {"alwaysmlook2", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_chasefreelook = {"chasemlook", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_chasefreelook2 = {"chasemlook2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_mousemove = {"mousemove", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; From a5eb62b73e0adaf5fb2475ce4a2f33ce9ba3d4d7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 12:02:45 -0500 Subject: [PATCH 03/21] alwaysfreelook -> alwaysmlook string --- src/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index cc208e94..1acde820 100644 --- a/src/command.c +++ b/src/command.c @@ -1743,8 +1743,8 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) // MOUSE SETTINGS // alwaysfreelook split between first and third person (chasefreelook) // mousemove was on by default, which invalidates the current approach - if (!stricmp(v->name, "alwaysfreelook") - || !stricmp(v->name, "alwaysfreelook2") + if (!stricmp(v->name, "alwaysmlook") + || !stricmp(v->name, "alwaysmlook2") || !stricmp(v->name, "mousemove") || !stricmp(v->name, "mousemove2")) return false; From 0be61e8830913bea46525e2ccf34468080f47278 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 12:03:53 -0500 Subject: [PATCH 04/21] a stray if block --- src/command.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/command.c b/src/command.c index 1acde820..c3f5140f 100644 --- a/src/command.c +++ b/src/command.c @@ -1748,8 +1748,6 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) || !stricmp(v->name, "mousemove") || !stricmp(v->name, "mousemove2")) return false; - if () - return false; // mousesens was changed from 35 to 20 due to oversensitivity if ((!stricmp(v->name, "mousesens") From 3ceeb6a20582315efb37bd05b916bc3b943841ef Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 12:28:30 -0500 Subject: [PATCH 05/21] Register execversion and remove CV_SAVE because we write manually --- src/command.c | 2 +- src/m_misc.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index c3f5140f..47c6d2e5 100644 --- a/src/command.c +++ b/src/command.c @@ -66,7 +66,7 @@ CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; // Filter consvars by MODVERSION // First implementation is 26 (2.1.21), so earlier configs default at 25 (2.1.20) // Also set CV_HIDEN during runtime, after config is loaded -consvar_t cv_execversion = {"execversion","25",CV_SAVE,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_execversion = {"execversion","25",0,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; // for default joyaxis detection static boolean joyaxis_default = false; diff --git a/src/m_misc.c b/src/m_misc.c index 760894a6..1ab5f1fe 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -489,6 +489,9 @@ void M_FirstLoadConfig(void) // load default control G_Controldefault(); + // register execversion here before we load any configs + CV_RegisterVar(&cv_execversion); + // temporarily reset execversion to default // we shouldn't need to do this, but JUST in case... cv_execversion.flags &= ~CV_HIDEN; From 60afce5771bc9b50ce039c9bca6c4ca284768c8c Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 14:03:46 -0500 Subject: [PATCH 06/21] Disable XINPUT before initing the joy subsystem --- src/sdl/i_system.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b18ea957..ae462c52 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1380,13 +1380,12 @@ void I_InitJoystick(void) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { CONS_Printf("Initing joy system\n"); + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); return; } - else - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); } if (strcmp(cv_usejoystick.string, "0") && joy_open(cv_usejoystick.string) != -1) @@ -1412,13 +1411,12 @@ void I_InitJoystick2(void) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { CONS_Printf("Initing joy system\n"); + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); return; } - else - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); } if (strcmp(cv_usejoystick2.string, "0") && joy_open2(cv_usejoystick2.string) != -1) From ba60989c00b85b785a2298be109bb0758b41d4c0 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 15:39:19 -0500 Subject: [PATCH 07/21] Adjust version strings --- src/d_netcmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 434675a7..6c6f65b4 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3435,9 +3435,9 @@ static void Command_Version_f(void) // OS // Would be nice to use SDL_GetPlatform for this -#if defined(_WIN32) +#if defined(_WINDOWS) CONS_Printf("Windows "); -#elif defined(LINUX) +#elif defined(__linux__) CONS_Printf("Linux "); #elif defined(MACOSX) CONS_Printf("macOS" ); From df89781623d20bbc07815e770c48bfae7248fb50 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 15:42:58 -0500 Subject: [PATCH 08/21] Windows string adjustment --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 6c6f65b4..8abfb870 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3435,7 +3435,7 @@ static void Command_Version_f(void) // OS // Would be nice to use SDL_GetPlatform for this -#if defined(_WINDOWS) +#if defined (_WIN32) || defined (_WIN64) CONS_Printf("Windows "); #elif defined(__linux__) CONS_Printf("Linux "); From bcd747c1cd24bc50b95857f5d995c4612917f467 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Dec 2018 22:26:13 -0500 Subject: [PATCH 09/21] Adjust SDL_JOYDEVICEREMOVED handler by checking the player's joy device explicitly --- src/sdl/i_video.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 835ba166..82f26d23 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -116,9 +116,6 @@ static INT32 firstEntry = 0; // Total mouse motion X/Y offsets static INT32 mousemovex = 0, mousemovey = 0; -// Keep track of joy unplugged count -static INT32 joyunplugcount = 0; - // SDL vars static SDL_Surface *vidSurface = NULL; static SDL_Surface *bufSurface = NULL; @@ -897,25 +894,21 @@ void I_GetEvent(void) M_SetupJoystickMenu(0); break; case SDL_JOYDEVICEREMOVED: + if (JoyInfo.dev && !SDL_JoystickGetAttached(JoyInfo.dev)) { - // every time a device is unplugged, the "which" index increments by 1? - INT32 deviceIdx = evt.jdevice.which - joyunplugcount++; - - CONS_Printf("Joy device %d removed%s\n", deviceIdx, - (JoyInfo.oldjoy-1 == deviceIdx) ? " was first joystick" : - (JoyInfo2.oldjoy-1 == deviceIdx) ? " was second joystick" : ""); - - // I_ShutdownJoystick doesn't shut down the subsystem - // It just fires neutral joy events to clean up the unplugged joy - if (JoyInfo.oldjoy-1 == deviceIdx) - I_ShutdownJoystick(); - if (JoyInfo2.oldjoy-1 == deviceIdx) - I_ShutdownJoystick2(); - - // update the menu - if (currentMenu == &OP_JoystickSetDef) - M_SetupJoystickMenu(0); + CONS_Printf("Joy device %d removed, was first joystick\n", JoyInfo.oldjoy); + I_ShutdownJoystick(); } + + if (JoyInfo2.dev && !SDL_JoystickGetAttached(JoyInfo2.dev)) + { + CONS_Printf("Joy device %d removed, was second joystick\n", JoyInfo2.oldjoy); + I_ShutdownJoystick2(); + } + + // update the menu + if (currentMenu == &OP_JoystickSetDef) + M_SetupJoystickMenu(0); break; case SDL_QUIT: I_Quit(); From e81f05c496c9a7bb24c8bbdbf054b9116eecfadf Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Dec 2018 23:09:05 -0500 Subject: [PATCH 10/21] Handle unstable device index when hotplugging controller --- src/sdl/i_system.c | 72 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index ae462c52..e4880783 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1021,6 +1021,7 @@ void I_GetJoystickEvents(void) */ static int joy_open(const char *fname) { + SDL_Joystick *newdev = NULL; int joyindex = atoi(fname); int num_joy = 0; int i; @@ -1062,7 +1063,28 @@ static int joy_open(const char *fname) } } - JoyInfo.dev = SDL_JoystickOpen(joyindex-1); + newdev = SDL_JoystickOpen(joyindex-1); + + // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging + // This indexing is SDL's responsibility and there's not much we can do about it. + // + // Example: + // 1. Plug Controller A -> Index 0 opened + // 2. Plug Controller B -> Index 1 opened + // 3. Unplug Controller A -> Index 0 closed, Index 1 active + // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed + // 5. Plug Controller B -> Index 0 opened + // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B + if (JoyInfo.dev) + { + if (JoyInfo.dev == newdev // same device, nothing to do + || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo.dev))) // we failed, but already have a working device + return JoyInfo.axises; + // Else, we're changing devices, so send neutral joy events + I_ShutdownJoystick(); + } + + JoyInfo.dev = newdev; if (JoyInfo.dev == NULL) { @@ -1075,7 +1097,7 @@ static int joy_open(const char *fname) JoyInfo.axises = SDL_JoystickNumAxes(JoyInfo.dev); if (JoyInfo.axises > JOYAXISSET*2) JoyInfo.axises = JOYAXISSET*2; -/* if (joyaxes<2) + /* if (joyaxes<2) { I_OutputMsg("Not enought axes?\n"); return 0; @@ -1292,6 +1314,7 @@ void I_GetJoystick2Events(void) */ static int joy_open2(const char *fname) { + SDL_Joystick *newdev = NULL; int joyindex = atoi(fname); int num_joy = 0; int i; @@ -1333,7 +1356,28 @@ static int joy_open2(const char *fname) } } - JoyInfo2.dev = SDL_JoystickOpen(joyindex-1); + newdev = SDL_JoystickOpen(joyindex-1); + + // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging + // This indexing is SDL's responsibility and there's not much we can do about it. + // + // Example: + // 1. Plug Controller A -> Index 0 opened + // 2. Plug Controller B -> Index 1 opened + // 3. Unplug Controller A -> Index 0 closed, Index 1 active + // 4. Unplug Controller B -> Index 0 inactive, Index 1 closed + // 5. Plug Controller B -> Index 0 opened + // 6. Plug Controller A -> Index 0 REPLACED, opened as Controller A; Index 1 is now Controller B + if (JoyInfo2.dev) + { + if (JoyInfo2.dev == newdev // same device, nothing to do + || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo2.dev))) // we failed, but already have a working device + return JoyInfo.axises; + // Else, we're changing devices, so send neutral joy events + I_ShutdownJoystick2(); + } + + JoyInfo2.dev = newdev; if (JoyInfo2.dev == NULL) { @@ -1390,7 +1434,16 @@ void I_InitJoystick(void) if (strcmp(cv_usejoystick.string, "0") && joy_open(cv_usejoystick.string) != -1) { - JoyInfo.oldjoy = atoi(cv_usejoystick.string); + // JoyInfo.oldjoy may already be filled because we attempted to hotplug + // a device and the device index has changed + // So in this case, get the new device index + // + // For now, it does not actually matter if the JoyInfo.oldjoy value is inaccurate. We don't use its + // exact value; we just use it like a boolean. + if (JoyInfo.oldjoy <= 0) + JoyInfo.oldjoy = atoi(cv_usejoystick.string); + else + JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; joystick_started = 1; } else @@ -1421,7 +1474,16 @@ void I_InitJoystick2(void) if (strcmp(cv_usejoystick2.string, "0") && joy_open2(cv_usejoystick2.string) != -1) { - JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); + // JoyInfo.oldjoy may already be filled because we attempted to hotplug + // a device and the device index has changed + // So in this case, get the new device index + // + // For now, it does not actually matter if the JoyInfo2.oldjoy value is inaccurate. We don't use its + // exact value; we just use it like a boolean. + if (JoyInfo2.oldjoy <= 0) + JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); + else + JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; joystick2_started = 1; } else From 14cde2d227520bff464773442d11935e4bbfdedc Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Dec 2018 23:26:07 -0500 Subject: [PATCH 11/21] Change joystick log messages to DBG_GAMELOGIC --- src/sdl/i_system.c | 16 ++++++++++++---- src/sdl/i_video.c | 14 ++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e4880783..7a943979 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1088,12 +1088,12 @@ static int joy_open(const char *fname) if (JoyInfo.dev == NULL) { - CONS_Printf(M_GetText("Couldn't open joystick: %s\n"), SDL_GetError()); + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: Couldn't open device - %s\n"), SDL_GetError()); return -1; } else { - CONS_Printf(M_GetText("Joystick: %s\n"), SDL_JoystickName(JoyInfo.dev)); + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: %s\n"), SDL_JoystickName(JoyInfo.dev)); JoyInfo.axises = SDL_JoystickNumAxes(JoyInfo.dev); if (JoyInfo.axises > JOYAXISSET*2) JoyInfo.axises = JOYAXISSET*2; @@ -1381,12 +1381,12 @@ static int joy_open2(const char *fname) if (JoyInfo2.dev == NULL) { - CONS_Printf(M_GetText("Couldn't open joystick2: %s\n"), SDL_GetError()); + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick2: couldn't open device - %s\n"), SDL_GetError()); return -1; } else { - CONS_Printf(M_GetText("Joystick2: %s\n"), SDL_JoystickName(JoyInfo2.dev)); + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick2: %s\n"), SDL_JoystickName(JoyInfo2.dev)); JoyInfo2.axises = SDL_JoystickNumAxes(JoyInfo2.dev); if (JoyInfo2.axises > JOYAXISSET*2) JoyInfo2.axises = JOYAXISSET*2; @@ -1443,7 +1443,11 @@ void I_InitJoystick(void) if (JoyInfo.oldjoy <= 0) JoyInfo.oldjoy = atoi(cv_usejoystick.string); else + { + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index has changed: was %d, now %d\n", + JoyInfo.oldjoy, SDL_JoystickInstanceID(JoyInfo.dev) + 1); JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; + } joystick_started = 1; } else @@ -1483,7 +1487,11 @@ void I_InitJoystick2(void) if (JoyInfo2.oldjoy <= 0) JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); else + { + CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index has changed: was %d, now %d\n", + JoyInfo2.oldjoy, SDL_JoystickInstanceID(JoyInfo2.dev) + 1); JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; + } joystick2_started = 1; } else diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 82f26d23..51da55cb 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -883,12 +883,15 @@ void I_GetEvent(void) Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type); break; case SDL_JOYDEVICEADDED: - CONS_Printf("Joy device %d added\n", evt.jdevice.which); + CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); - // recounts hotplugged joysticks + // recount hotplugged joysticks I_InitJoystick(); I_InitJoystick2(); + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); + CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); + // update the menu if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); @@ -896,16 +899,19 @@ void I_GetEvent(void) case SDL_JOYDEVICEREMOVED: if (JoyInfo.dev && !SDL_JoystickGetAttached(JoyInfo.dev)) { - CONS_Printf("Joy device %d removed, was first joystick\n", JoyInfo.oldjoy); + CONS_Debug(DBG_GAMELOGIC, "Joystick1 removed, device index: %d\n", JoyInfo.oldjoy); I_ShutdownJoystick(); } if (JoyInfo2.dev && !SDL_JoystickGetAttached(JoyInfo2.dev)) { - CONS_Printf("Joy device %d removed, was second joystick\n", JoyInfo2.oldjoy); + CONS_Debug(DBG_GAMELOGIC, "Joystick2 removed, device index: %d\n", JoyInfo2.oldjoy); I_ShutdownJoystick2(); } + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); + CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); + // update the menu if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); From 216e710b8705dc3b26d5d09aa026064c68e7c8e2 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 13 Dec 2018 23:50:36 -0500 Subject: [PATCH 12/21] Improve hotplug edge case with changing device indexes; return proper joy_open output on error --- src/sdl/i_system.c | 90 +++++++--------------------------------------- 1 file changed, 12 insertions(+), 78 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7a943979..d1ce041a 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1024,7 +1024,6 @@ static int joy_open(const char *fname) SDL_Joystick *newdev = NULL; int joyindex = atoi(fname); int num_joy = 0; - int i; if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { @@ -1032,35 +1031,15 @@ static int joy_open(const char *fname) return -1; } - JoyReset(&JoyInfo); - if (joyindex <= 0) - return 0; + return -1; num_joy = SDL_NumJoysticks(); - if (num_joy == 0 || JoyInfo.oldjoy == joyindex) + if (num_joy == 0) { -// I_OutputMsg("Unable to use that joystick #(%s), non-number\n",fname); - if (num_joy != 0) - { - CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy); - for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); - - if (num_joy < joyindex) - { - CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname); - for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); - return 0; - } - } - else - { - CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); - return 0; - } + CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + return -1; } newdev = SDL_JoystickOpen(joyindex-1); @@ -1081,6 +1060,7 @@ static int joy_open(const char *fname) || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo.dev))) // we failed, but already have a working device return JoyInfo.axises; // Else, we're changing devices, so send neutral joy events + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device is changing; resetting events...\n"); I_ShutdownJoystick(); } @@ -1317,7 +1297,6 @@ static int joy_open2(const char *fname) SDL_Joystick *newdev = NULL; int joyindex = atoi(fname); int num_joy = 0; - int i; if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { @@ -1325,35 +1304,15 @@ static int joy_open2(const char *fname) return -1; } - JoyReset(&JoyInfo2); - if (joyindex <= 0) - return 0; + return -1; num_joy = SDL_NumJoysticks(); - if (num_joy == 0 || JoyInfo2.oldjoy == joyindex) + if (num_joy == 0) { -// I_OutputMsg("Unable to use that joystick #(%s), non-number\n",fname); - if (num_joy != 0) - { - CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy); - for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); - - if (num_joy < joyindex) - { - CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname); - for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); - return 0; - } - } - else - { - CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); - return 0; - } + CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + return -1; } newdev = SDL_JoystickOpen(joyindex-1); @@ -1374,6 +1333,7 @@ static int joy_open2(const char *fname) || (newdev == NULL && SDL_JoystickGetAttached(JoyInfo2.dev))) // we failed, but already have a working device return JoyInfo.axises; // Else, we're changing devices, so send neutral joy events + CONS_Debug(DBG_GAMELOGIC, "Joystick2 device is changing; resetting events...\n"); I_ShutdownJoystick2(); } @@ -1434,20 +1394,7 @@ void I_InitJoystick(void) if (strcmp(cv_usejoystick.string, "0") && joy_open(cv_usejoystick.string) != -1) { - // JoyInfo.oldjoy may already be filled because we attempted to hotplug - // a device and the device index has changed - // So in this case, get the new device index - // - // For now, it does not actually matter if the JoyInfo.oldjoy value is inaccurate. We don't use its - // exact value; we just use it like a boolean. - if (JoyInfo.oldjoy <= 0) - JoyInfo.oldjoy = atoi(cv_usejoystick.string); - else - { - CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index has changed: was %d, now %d\n", - JoyInfo.oldjoy, SDL_JoystickInstanceID(JoyInfo.dev) + 1); - JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; - } + JoyInfo.oldjoy = atoi(cv_usejoystick.string); joystick_started = 1; } else @@ -1478,20 +1425,7 @@ void I_InitJoystick2(void) if (strcmp(cv_usejoystick2.string, "0") && joy_open2(cv_usejoystick2.string) != -1) { - // JoyInfo.oldjoy may already be filled because we attempted to hotplug - // a device and the device index has changed - // So in this case, get the new device index - // - // For now, it does not actually matter if the JoyInfo2.oldjoy value is inaccurate. We don't use its - // exact value; we just use it like a boolean. - if (JoyInfo2.oldjoy <= 0) - JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); - else - { - CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index has changed: was %d, now %d\n", - JoyInfo2.oldjoy, SDL_JoystickInstanceID(JoyInfo2.dev) + 1); - JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; - } + JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); joystick2_started = 1; } else From 44d6a1d2368157f03bbc0620504ed25a6cf68a92 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 00:22:25 -0500 Subject: [PATCH 13/21] Attempt to handle unstable device IDs --- src/sdl/i_system.c | 22 ++++++++++++---------- src/sdl/i_video.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index d1ce041a..6ac41de1 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1019,10 +1019,9 @@ void I_GetJoystickEvents(void) */ -static int joy_open(const char *fname) +static int joy_open(int joyindex) { SDL_Joystick *newdev = NULL; - int joyindex = atoi(fname); int num_joy = 0; if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) @@ -1292,10 +1291,9 @@ void I_GetJoystick2Events(void) */ -static int joy_open2(const char *fname) +static int joy_open2(int joyindex) { SDL_Joystick *newdev = NULL; - int joyindex = atoi(fname); int num_joy = 0; if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) @@ -1392,16 +1390,18 @@ void I_InitJoystick(void) } } - if (strcmp(cv_usejoystick.string, "0") && joy_open(cv_usejoystick.string) != -1) + if (cv_usejoystick.value && joy_open(cv_usejoystick.value) != -1) { - JoyInfo.oldjoy = atoi(cv_usejoystick.string); + // SDL's device indexes are unstable, so cv_usejoystick may not match + // the actual device index. So let's cheat a bit and use the instance ID. + // oldjoy's exact value doesn't matter, because we use it like a boolean + JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; joystick_started = 1; } else { if (JoyInfo.oldjoy) I_ShutdownJoystick(); - cv_usejoystick.value = 0; joystick_started = 0; } } @@ -1423,16 +1423,18 @@ void I_InitJoystick2(void) } } - if (strcmp(cv_usejoystick2.string, "0") && joy_open2(cv_usejoystick2.string) != -1) + if (cv_usejoystick2.value && joy_open2(cv_usejoystick2.value) != -1) { - JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); + // SDL's device indexes are unstable, so cv_usejoystick2 may not match + // the actual device index. So let's cheat a bit and use the instance ID. + // oldjoy's exact value doesn't matter, because we use it like a boolean + JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; joystick2_started = 1; } else { if (JoyInfo2.oldjoy) I_ShutdownJoystick2(); - cv_usejoystick2.value = 0; joystick2_started = 0; } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 51da55cb..6fc8f577 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -885,7 +885,27 @@ void I_GetEvent(void) case SDL_JOYDEVICEADDED: CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); - // recount hotplugged joysticks + // Because SDL's device index is unstable, we're going to cheat here a bit: + // For the first joystick setting that is NOT active: + // Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) + // Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed + if (!JoyInfo.dev || !SDL_JoystickGetAttached(JoyInfo.dev)) + { + cv_usejoystick.value = evt.jdevice.which + 1; + + if (JoyInfo2.dev) + cv_usejoystick2.value = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; + } + else if (!JoyInfo2.dev || !SDL_JoystickGetAttached(JoyInfo2.dev)) + { + cv_usejoystick2.value = evt.jdevice.which + 1; + + if (JoyInfo.dev) + cv_usejoystick.value = SDL_JoystickInstanceID(JoyInfo.dev) + 1; + } + + // If an active joystick's index has changed, these will just + // change the corresponding JoyInfo.oldjoy I_InitJoystick(); I_InitJoystick2(); @@ -909,6 +929,13 @@ void I_GetEvent(void) I_ShutdownJoystick2(); } + // Update the device indexes, because they likely changed + if (JoyInfo.dev) + JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; + + if (JoyInfo2.dev) + JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); From 6b9fe87b60de3da7ef2f2b4e3553fb34b1b557ad Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 01:45:18 -0500 Subject: [PATCH 14/21] Properly handle unstable device indexes for hotplug --- src/sdl/i_system.c | 27 +++++++++++++++++++++------ src/sdl/i_video.c | 36 ++++++++++++++++++++++++++++++++---- src/sdl/sdlmain.h | 3 +++ 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 6ac41de1..7cbaf6d3 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -828,6 +828,23 @@ void I_JoyScale2(void) JoyInfo2.scale = Joystick2.bGamepadStyle?1:cv_joyscale2.value; } +// Cheat to get the device index for a joystick handle +INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev) +{ + INT32 i, count = SDL_NumJoysticks(); + + for (i = 0; dev && i < count; i++) + { + SDL_Joystick *test = SDL_JoystickOpen(i); + if (test && test == dev) + return i; + else if (JoyInfo.dev != test && JoyInfo2.dev != test) + SDL_JoystickClose(test); + } + + return -1; +} + /** \brief Joystick 1 buttons states */ static UINT64 lastjoybuttons = 0; @@ -1393,9 +1410,8 @@ void I_InitJoystick(void) if (cv_usejoystick.value && joy_open(cv_usejoystick.value) != -1) { // SDL's device indexes are unstable, so cv_usejoystick may not match - // the actual device index. So let's cheat a bit and use the instance ID. - // oldjoy's exact value doesn't matter, because we use it like a boolean - JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; + // the actual device index. So let's cheat a bit and find the device's current index. + JoyInfo.oldjoy = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; joystick_started = 1; } else @@ -1426,9 +1442,8 @@ void I_InitJoystick2(void) if (cv_usejoystick2.value && joy_open2(cv_usejoystick2.value) != -1) { // SDL's device indexes are unstable, so cv_usejoystick2 may not match - // the actual device index. So let's cheat a bit and use the instance ID. - // oldjoy's exact value doesn't matter, because we use it like a boolean - JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; + // the actual device index. So let's cheat a bit and find the device's current index. + JoyInfo2.oldjoy = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; joystick2_started = 1; } else diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6fc8f577..f6f19303 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -889,19 +889,33 @@ void I_GetEvent(void) // For the first joystick setting that is NOT active: // Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) // Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed + // If device doesn't exist, switch cv_usejoystick back to default value (.string) + // BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! if (!JoyInfo.dev || !SDL_JoystickGetAttached(JoyInfo.dev)) { cv_usejoystick.value = evt.jdevice.which + 1; if (JoyInfo2.dev) - cv_usejoystick2.value = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; + cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy) + cv_usejoystick2.value = atoi(cv_usejoystick2.string); + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy) + cv_usejoystick2.value = atoi(cv_usejoystick.string); + else // we tried... + cv_usejoystick2.value = 0; } else if (!JoyInfo2.dev || !SDL_JoystickGetAttached(JoyInfo2.dev)) { cv_usejoystick2.value = evt.jdevice.which + 1; if (JoyInfo.dev) - cv_usejoystick.value = SDL_JoystickInstanceID(JoyInfo.dev) + 1; + cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; + else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy) + cv_usejoystick.value = atoi(cv_usejoystick.string); + else if (atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy) + cv_usejoystick.value = atoi(cv_usejoystick2.string); + else // we tried... + cv_usejoystick.value = 0; } // If an active joystick's index has changed, these will just @@ -930,11 +944,25 @@ void I_GetEvent(void) } // Update the device indexes, because they likely changed + // If device doesn't exist, switch cv_usejoystick back to default value (.string) + // BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! if (JoyInfo.dev) - JoyInfo.oldjoy = SDL_JoystickInstanceID(JoyInfo.dev) + 1; + cv_usejoystick.value = JoyInfo.oldjoy = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; + else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy) + cv_usejoystick.value = atoi(cv_usejoystick.string); + else if (atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy) + cv_usejoystick.value = atoi(cv_usejoystick2.string); + else // we tried... + cv_usejoystick.value = 0; if (JoyInfo2.dev) - JoyInfo2.oldjoy = SDL_JoystickInstanceID(JoyInfo2.dev) + 1; + cv_usejoystick2.value = JoyInfo2.oldjoy = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy) + cv_usejoystick2.value = atoi(cv_usejoystick2.string); + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy) + cv_usejoystick2.value = atoi(cv_usejoystick.string); + else // we tried... + cv_usejoystick2.value = 0; CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 4acbce20..b858e1f6 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -71,6 +71,9 @@ extern SDLJoyInfo_t JoyInfo2; void I_ShutdownJoystick(void); void I_ShutdownJoystick2(void); +// Cheat to get the device index for a joystick handle +INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev); + void I_GetConsoleEvents(void); void SDLforceUngrabMouse(void); From 3b6de810e11ea90177ab65e21184766172111fea Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 03:58:07 -0500 Subject: [PATCH 15/21] Lots of changes to better support hotplugging and unstable device indexes * Don't save cv_usejoystick/2 because hotplugging changes can be made invalid by next run * Properly set cv_usejoystick/2 for menu toggling * Force-disable a player's joystick if setting another player's joystick to the same device * Properly set cv_usejoystick/2 value of BOTH target player AND other players when hotplugging and unplugging --- src/d_netcmd.c | 24 +++++++++++++++++---- src/m_menu.c | 29 ++++++++++++++++++++++++++ src/sdl/i_system.c | 18 ++++++++++++++++ src/sdl/i_video.c | 52 +++++++++++++++++++++++++++++++++++----------- src/sdl/sdlmain.h | 3 +++ 5 files changed, 110 insertions(+), 16 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 8abfb870..16c08309 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -46,6 +46,13 @@ #include "m_cond.h" #include "m_anigif.h" +#if defined(HAVE_SDL) +#include "SDL.h" +#if SDL_VERSION_ATLEAST(2,0,0) +#include "sdl/sdlmain.h" // JOYSTICK_HOTPLUG +#endif +#endif + #ifdef NETGAME_DEVMODE #define CV_RESTRICT CV_NETVAR #else @@ -243,10 +250,19 @@ consvar_t cv_usemouse = {"use_mouse", "On", CV_SAVE|CV_CALL,usemouse_cons_t, I_S consvar_t cv_usemouse2 = {"use_mouse2", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse2, 0, NULL, NULL, 0, 0, NULL}; #if defined (DC) || defined (_XBOX) || defined (WMINPUT) || defined (_WII) || defined(HAVE_SDL) || defined(_WINDOWS) //joystick 1 and 2 -consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, - I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_usejoystick2 = {"use_joystick2", "2", CV_SAVE|CV_CALL, usejoystick_cons_t, - I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; +// JOYSTICK_HOTPLUG is set by sdlmain.h (SDL2) +// because SDL joystick indexes are unstable, and hotplugging can change a device's index. +// So let's not save any index changes to the config +consvar_t cv_usejoystick = {"use_joystick", "1", CV_CALL +#ifndef JOYSTICK_HOTPLUG + |CV_SAVE +#endif + , usejoystick_cons_t, I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usejoystick2 = {"use_joystick2", "2", CV_CALL +#ifndef JOYSTICK_HOTPLUG + |CV_SAVE +#endif + , usejoystick_cons_t, I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; #elif defined (PSP) || defined (GP2X) || defined (_NDS) //only one joystick consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/m_menu.c b/src/m_menu.c index a4c62c0f..7bac5fa2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -62,6 +62,13 @@ // And just some randomness for the exits. #include "m_random.h" +#if defined(HAVE_SDL) +#include "SDL.h" +#if SDL_VERSION_ATLEAST(2,0,0) +#include "sdl/sdlmain.h" // JOYSTICK_HOTPLUG +#endif +#endif + #ifdef PC_DOS #include // for snprintf int snprintf(char *str, size_t n, const char *fmt, ...); @@ -6770,12 +6777,34 @@ void M_SetupJoystickMenu(INT32 choice) strcpy(joystickInfo[i], "None"); +#ifdef JOYSTICK_HOTPLUG + if (0 == cv_usejoystick.value) + CV_SetValue(&cv_usejoystick, 0); + if (0 == cv_usejoystick2.value) + CV_SetValue(&cv_usejoystick2, 0); +#endif + for (i = 1; i < 8; i++) { if (i <= n && (I_GetJoyName(i)) != NULL) strncpy(joystickInfo[i], I_GetJoyName(i), 28); else strcpy(joystickInfo[i], joyNA); + +#ifdef JOYSTICK_HOTPLUG + // We use cv_usejoystick.string as the USER-SET var + // and cv_usejoystick.value as the INTERNAL var + // + // In practice, if cv_usejoystick.string == 0, this overrides + // cv_usejoystick.value and always disables + // + // Update cv_usejoystick.string here so that the user can + // properly change this value. + if (i == cv_usejoystick.value) + CV_SetValue(&cv_usejoystick, i); + if (i == cv_usejoystick2.value) + CV_SetValue(&cv_usejoystick2, i); +#endif } M_SetupNextMenu(&OP_JoystickSetDef); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7cbaf6d3..e6c1b0b5 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1413,11 +1413,20 @@ void I_InitJoystick(void) // the actual device index. So let's cheat a bit and find the device's current index. JoyInfo.oldjoy = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; joystick_started = 1; + + // If another joystick occupied this device, deactivate that joystick + if (JoyInfo2.dev == JoyInfo.dev) + { + CONS_Debug(DBG_GAMELOGIC, "Joystick2 was set to the same device; disabling...\n"); + cv_usejoystick2.value = 0; + I_InitJoystick2(); + } } else { if (JoyInfo.oldjoy) I_ShutdownJoystick(); + cv_usejoystick.value = 0; joystick_started = 0; } } @@ -1445,11 +1454,20 @@ void I_InitJoystick2(void) // the actual device index. So let's cheat a bit and find the device's current index. JoyInfo2.oldjoy = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; joystick2_started = 1; + + // If another joystick occupied this device, deactivate that joystick + if (JoyInfo.dev == JoyInfo2.dev) + { + CONS_Debug(DBG_GAMELOGIC, "Joystick1 was set to the same device; disabling...\n"); + cv_usejoystick.value = 0; + I_InitJoystick(); + } } else { if (JoyInfo2.oldjoy) I_ShutdownJoystick2(); + cv_usejoystick2.value = 0; joystick2_started = 0; } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f6f19303..24228aa8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -887,19 +887,21 @@ void I_GetEvent(void) // Because SDL's device index is unstable, we're going to cheat here a bit: // For the first joystick setting that is NOT active: - // Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) - // Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed - // If device doesn't exist, switch cv_usejoystick back to default value (.string) - // BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! + // 1. Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) + // 2. Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed + // * If device doesn't exist, switch cv_usejoystick back to default value (.string) + // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! if (!JoyInfo.dev || !SDL_JoystickGetAttached(JoyInfo.dev)) { cv_usejoystick.value = evt.jdevice.which + 1; if (JoyInfo2.dev) cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; - else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy) + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value) cv_usejoystick2.value = atoi(cv_usejoystick2.string); - else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy) + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value) cv_usejoystick2.value = atoi(cv_usejoystick.string); else // we tried... cv_usejoystick2.value = 0; @@ -910,16 +912,31 @@ void I_GetEvent(void) if (JoyInfo.dev) cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; - else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy) + else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value) cv_usejoystick.value = atoi(cv_usejoystick.string); - else if (atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy) + else if (atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value) cv_usejoystick.value = atoi(cv_usejoystick2.string); else // we tried... cv_usejoystick.value = 0; } - // If an active joystick's index has changed, these will just - // change the corresponding JoyInfo.oldjoy + // Was cv_usejoystick disabled in settings? + if (!strcmp(cv_usejoystick.string, "0") || !cv_usejoystick.value) + cv_usejoystick.value = 0; + else if (cv_usejoystick.value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick, cv_usejoystick.value); + + if (!strcmp(cv_usejoystick2.string, "0") || !cv_usejoystick2.value) + cv_usejoystick2.value = 0; + else if (cv_usejoystick2.value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); + + // Update all joysticks' init states + // This is a little wasteful since cv_usejoystick already calls this, but + // we need to do this in case CV_SetValue did nothing because the string was already same. + // if the device is already active, this should do nothing, effectively. I_InitJoystick(); I_InitJoystick2(); @@ -944,8 +961,8 @@ void I_GetEvent(void) } // Update the device indexes, because they likely changed - // If device doesn't exist, switch cv_usejoystick back to default value (.string) - // BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! + // * If device doesn't exist, switch cv_usejoystick back to default value (.string) + // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! if (JoyInfo.dev) cv_usejoystick.value = JoyInfo.oldjoy = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy) @@ -964,6 +981,17 @@ void I_GetEvent(void) else // we tried... cv_usejoystick2.value = 0; + // Was cv_usejoystick disabled in settings? + if (!strcmp(cv_usejoystick.string, "0")) + cv_usejoystick.value = 0; + else if (cv_usejoystick.value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick, cv_usejoystick.value); + + if (!strcmp(cv_usejoystick2.string, "0")) + cv_usejoystick2.value = 0; + else if (cv_usejoystick2.value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index b858e1f6..810c7dce 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -31,6 +31,9 @@ extern SDL_bool framebuffer; #define SDL2STUB() CONS_Printf("SDL2: stubbed: %s:%d\n", __func__, __LINE__) #endif +// So m_menu knows whether to store cv_usejoystick value or string +#define JOYSTICK_HOTPLUG + /** \brief The JoyInfo_s struct info about joystick From e548f6f139a69cfd65bb19ac0d7b8db17983bcb6 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 05:02:41 -0500 Subject: [PATCH 16/21] Don't override an already-active controller * Menu improvements to tell the user that they can't set a controller if it's already active --- src/m_menu.c | 54 +++++++++++++++++++- src/sdl/i_system.c | 41 ++++++++------- src/sdl/i_video.c | 125 ++++++++++++++++++++++++--------------------- 3 files changed, 142 insertions(+), 78 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 7bac5fa2..21d7d25f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6777,7 +6777,9 @@ void M_SetupJoystickMenu(INT32 choice) strcpy(joystickInfo[i], "None"); -#ifdef JOYSTICK_HOTPLUG + // Hotplugging breaks if this block is run + // Because the cvar is set to 0, which disables controllers for that player +#if 0 // #ifdef JOYSTICK_HOTPLUG if (0 == cv_usejoystick.value) CV_SetValue(&cv_usejoystick, 0); if (0 == cv_usejoystick2.value) @@ -6826,10 +6828,60 @@ static void M_Setup2PJoystickMenu(INT32 choice) static void M_AssignJoystick(INT32 choice) { +#ifdef JOYSTICK_HOTPLUG + INT32 oldchoice; + + if (choice > I_NumJoys()) + return; + + if (setupcontrols_secondaryplayer) + { + oldchoice = cv_usejoystick2.value; + CV_SetValue(&cv_usejoystick2, choice); + + // Just in case last-minute changes were made to cv_usejoystick.value, + // update the string too + CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); + + if (oldchoice != choice) + { + if (choice && oldchoice > I_NumJoys()) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick2, oldchoice); + + if (oldchoice == cv_usejoystick2.value) + M_StartMessage("This joystick is used by another\n" + "player. Reset the joystick\n" + "for that player first.\n\n" + "(Press a key)\n", NULL, MM_NOTHING); + } + } + else + { + oldchoice = cv_usejoystick.value; + CV_SetValue(&cv_usejoystick, choice); + + // Just in case last-minute changes were made to cv_usejoystick.value, + // update the string too + CV_SetValue(&cv_usejoystick, cv_usejoystick.value); + + if (oldchoice != choice) + { + if (choice && oldchoice > I_NumJoys()) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick, oldchoice); + + if (oldchoice == cv_usejoystick.value) + M_StartMessage("This joystick is used by another\n" + "player. Reset the joystick\n" + "for that player first.\n\n" + "(Press a key)\n", NULL, MM_NOTHING); + } + } +#else if (setupcontrols_secondaryplayer) CV_SetValue(&cv_usejoystick2, choice); else CV_SetValue(&cv_usejoystick, choice); +#endif } // ============= diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e6c1b0b5..bf8fdbcf 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1392,6 +1392,8 @@ static int joy_open2(int joyindex) // void I_InitJoystick(void) { + SDL_Joystick *newjoy = NULL; + //I_ShutdownJoystick(); if (M_CheckParm("-nojoy")) return; @@ -1407,20 +1409,17 @@ void I_InitJoystick(void) } } - if (cv_usejoystick.value && joy_open(cv_usejoystick.value) != -1) + if (cv_usejoystick.value) + newjoy = SDL_JoystickOpen(cv_usejoystick.value-1); + + if (newjoy && JoyInfo2.dev == newjoy) // don't override an active device + cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; + else if (newjoy && joy_open(cv_usejoystick.value) != -1) { // SDL's device indexes are unstable, so cv_usejoystick may not match // the actual device index. So let's cheat a bit and find the device's current index. JoyInfo.oldjoy = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; joystick_started = 1; - - // If another joystick occupied this device, deactivate that joystick - if (JoyInfo2.dev == JoyInfo.dev) - { - CONS_Debug(DBG_GAMELOGIC, "Joystick2 was set to the same device; disabling...\n"); - cv_usejoystick2.value = 0; - I_InitJoystick2(); - } } else { @@ -1429,10 +1428,15 @@ void I_InitJoystick(void) cv_usejoystick.value = 0; joystick_started = 0; } + + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + SDL_JoystickClose(newjoy); } void I_InitJoystick2(void) { + SDL_Joystick *newjoy = NULL; + //I_ShutdownJoystick2(); if (M_CheckParm("-nojoy")) return; @@ -1448,20 +1452,17 @@ void I_InitJoystick2(void) } } - if (cv_usejoystick2.value && joy_open2(cv_usejoystick2.value) != -1) + if (cv_usejoystick2.value) + newjoy = SDL_JoystickOpen(cv_usejoystick2.value-1); + + if (newjoy && JoyInfo.dev == newjoy) // don't override an active device + cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; + else if (newjoy && joy_open2(cv_usejoystick2.value) != -1) { - // SDL's device indexes are unstable, so cv_usejoystick2 may not match + // SDL's device indexes are unstable, so cv_usejoystick may not match // the actual device index. So let's cheat a bit and find the device's current index. JoyInfo2.oldjoy = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; joystick2_started = 1; - - // If another joystick occupied this device, deactivate that joystick - if (JoyInfo.dev == JoyInfo2.dev) - { - CONS_Debug(DBG_GAMELOGIC, "Joystick1 was set to the same device; disabling...\n"); - cv_usejoystick.value = 0; - I_InitJoystick(); - } } else { @@ -1471,6 +1472,8 @@ void I_InitJoystick2(void) joystick2_started = 0; } + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + SDL_JoystickClose(newjoy); } static void I_ShutdownInput(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 24228aa8..318777f1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -883,69 +883,78 @@ void I_GetEvent(void) Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type); break; case SDL_JOYDEVICEADDED: - CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); - - // Because SDL's device index is unstable, we're going to cheat here a bit: - // For the first joystick setting that is NOT active: - // 1. Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) - // 2. Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed - // * If device doesn't exist, switch cv_usejoystick back to default value (.string) - // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! - if (!JoyInfo.dev || !SDL_JoystickGetAttached(JoyInfo.dev)) { - cv_usejoystick.value = evt.jdevice.which + 1; + SDL_Joystick *newjoy = SDL_JoystickOpen(evt.jdevice.which); - if (JoyInfo2.dev) - cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; - else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick.value) - cv_usejoystick2.value = atoi(cv_usejoystick2.string); - else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick.value) - cv_usejoystick2.value = atoi(cv_usejoystick.string); - else // we tried... - cv_usejoystick2.value = 0; - } - else if (!JoyInfo2.dev || !SDL_JoystickGetAttached(JoyInfo2.dev)) - { - cv_usejoystick2.value = evt.jdevice.which + 1; + CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); - if (JoyInfo.dev) - cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; - else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick.string) != cv_usejoystick2.value) - cv_usejoystick.value = atoi(cv_usejoystick.string); - else if (atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy - && atoi(cv_usejoystick2.string) != cv_usejoystick2.value) - cv_usejoystick.value = atoi(cv_usejoystick2.string); - else // we tried... + // Because SDL's device index is unstable, we're going to cheat here a bit: + // For the first joystick setting that is NOT active: + // 1. Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) + // 2. Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed + // * If device doesn't exist, switch cv_usejoystick back to default value (.string) + // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! + if (newjoy && (!JoyInfo.dev || !SDL_JoystickGetAttached(JoyInfo.dev)) + && JoyInfo2.dev != newjoy) // don't override a currently active device + { + cv_usejoystick.value = evt.jdevice.which + 1; + + if (JoyInfo2.dev) + cv_usejoystick2.value = I_GetJoystickDeviceIndex(JoyInfo2.dev) + 1; + else if (atoi(cv_usejoystick2.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick.value) + cv_usejoystick2.value = atoi(cv_usejoystick2.string); + else if (atoi(cv_usejoystick.string) != JoyInfo.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick.value) + cv_usejoystick2.value = atoi(cv_usejoystick.string); + else // we tried... + cv_usejoystick2.value = 0; + } + else if (newjoy && (!JoyInfo2.dev || !SDL_JoystickGetAttached(JoyInfo2.dev)) + && JoyInfo.dev != newjoy) // don't override a currently active device + { + cv_usejoystick2.value = evt.jdevice.which + 1; + + if (JoyInfo.dev) + cv_usejoystick.value = I_GetJoystickDeviceIndex(JoyInfo.dev) + 1; + else if (atoi(cv_usejoystick.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick.string) != cv_usejoystick2.value) + cv_usejoystick.value = atoi(cv_usejoystick.string); + else if (atoi(cv_usejoystick2.string) != JoyInfo2.oldjoy + && atoi(cv_usejoystick2.string) != cv_usejoystick2.value) + cv_usejoystick.value = atoi(cv_usejoystick2.string); + else // we tried... + cv_usejoystick.value = 0; + } + + // Was cv_usejoystick disabled in settings? + if (!strcmp(cv_usejoystick.string, "0") || !cv_usejoystick.value) cv_usejoystick.value = 0; + else if (cv_usejoystick.value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick, cv_usejoystick.value); + + if (!strcmp(cv_usejoystick2.string, "0") || !cv_usejoystick2.value) + cv_usejoystick2.value = 0; + else if (cv_usejoystick2.value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); + + // Update all joysticks' init states + // This is a little wasteful since cv_usejoystick already calls this, but + // we need to do this in case CV_SetValue did nothing because the string was already same. + // if the device is already active, this should do nothing, effectively. + I_InitJoystick(); + I_InitJoystick2(); + + CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); + CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); + + // update the menu + if (currentMenu == &OP_JoystickSetDef) + M_SetupJoystickMenu(0); + + if (JoyInfo.dev != newjoy && JoyInfo2.dev != newjoy) + SDL_JoystickClose(newjoy); } - - // Was cv_usejoystick disabled in settings? - if (!strcmp(cv_usejoystick.string, "0") || !cv_usejoystick.value) - cv_usejoystick.value = 0; - else if (cv_usejoystick.value) // update the cvar ONLY if a device exists - CV_SetValue(&cv_usejoystick, cv_usejoystick.value); - - if (!strcmp(cv_usejoystick2.string, "0") || !cv_usejoystick2.value) - cv_usejoystick2.value = 0; - else if (cv_usejoystick2.value) // update the cvar ONLY if a device exists - CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); - - // Update all joysticks' init states - // This is a little wasteful since cv_usejoystick already calls this, but - // we need to do this in case CV_SetValue did nothing because the string was already same. - // if the device is already active, this should do nothing, effectively. - I_InitJoystick(); - I_InitJoystick2(); - - CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); - CONS_Debug(DBG_GAMELOGIC, "Joystick2 device index: %d\n", JoyInfo2.oldjoy); - - // update the menu - if (currentMenu == &OP_JoystickSetDef) - M_SetupJoystickMenu(0); break; case SDL_JOYDEVICEREMOVED: if (JoyInfo.dev && !SDL_JoystickGetAttached(JoyInfo.dev)) From b2c02838c4a3ab2641ab1ca69b6d987c4330dd13 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 05:31:47 -0500 Subject: [PATCH 17/21] Display "joystick used" prompt correctly if setting use_joystick from an old value > I_NumJoys() --- src/m_menu.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 21d7d25f..7b440d46 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6751,7 +6751,7 @@ static void M_ScreenshotOptions(INT32 choice) static void M_DrawJoystick(void) { - INT32 i; + INT32 i, compareval2, compareval; M_DrawGenericMenu(); @@ -6760,8 +6760,23 @@ static void M_DrawJoystick(void) M_DrawTextBox(OP_JoystickSetDef.x-8, OP_JoystickSetDef.y+LINEHEIGHT*i-12, 28, 1); //M_DrawSaveLoadBorder(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i); - if ((setupcontrols_secondaryplayer && (i == cv_usejoystick2.value)) - || (!setupcontrols_secondaryplayer && (i == cv_usejoystick.value))) +#ifdef JOYSTICK_HOTPLUG + if (atoi(cv_usejoystick2.string) > I_NumJoys()) + compareval2 = atoi(cv_usejoystick2.string); + else + compareval2 = cv_usejoystick2.value; + + if (atoi(cv_usejoystick.string) > I_NumJoys()) + compareval = atoi(cv_usejoystick.string); + else + compareval = cv_usejoystick.value; +#else + compareval2 = cv_usejoystick2.value; + compareval = cv_usejoystick.value +#endif + + if ((setupcontrols_secondaryplayer && (i == compareval2)) + || (!setupcontrols_secondaryplayer && (i == compareval))) V_DrawString(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i-4,V_GREENMAP,joystickInfo[i]); else V_DrawString(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i-4,0,joystickInfo[i]); @@ -6836,7 +6851,7 @@ static void M_AssignJoystick(INT32 choice) if (setupcontrols_secondaryplayer) { - oldchoice = cv_usejoystick2.value; + oldchoice = atoi(cv_usejoystick2.string) > I_NumJoys() ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value; CV_SetValue(&cv_usejoystick2, choice); // Just in case last-minute changes were made to cv_usejoystick.value, @@ -6848,7 +6863,8 @@ static void M_AssignJoystick(INT32 choice) if (choice && oldchoice > I_NumJoys()) // if we did not select "None", we likely selected a used device CV_SetValue(&cv_usejoystick2, oldchoice); - if (oldchoice == cv_usejoystick2.value) + if (oldchoice == + (atoi(cv_usejoystick2.string) > I_NumJoys() ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value)) M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" "for that player first.\n\n" @@ -6857,7 +6873,7 @@ static void M_AssignJoystick(INT32 choice) } else { - oldchoice = cv_usejoystick.value; + oldchoice = atoi(cv_usejoystick.string) > I_NumJoys() ? atoi(cv_usejoystick.string) : cv_usejoystick.value; CV_SetValue(&cv_usejoystick, choice); // Just in case last-minute changes were made to cv_usejoystick.value, @@ -6869,7 +6885,8 @@ static void M_AssignJoystick(INT32 choice) if (choice && oldchoice > I_NumJoys()) // if we did not select "None", we likely selected a used device CV_SetValue(&cv_usejoystick, oldchoice); - if (oldchoice == cv_usejoystick.value) + if (oldchoice == + (atoi(cv_usejoystick.string) > I_NumJoys() ? atoi(cv_usejoystick.string) : cv_usejoystick.value)) M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" "for that player first.\n\n" From 70d6845d6cb8d542709d5818432f2cc833224e6f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 05:57:10 -0500 Subject: [PATCH 18/21] Fix menu where cv_usejoystick.value > I_JoyNum and selecting an unused controller and the "used!" prompt pops up erroneously --- src/m_menu.c | 77 +++++++++++++++++++++++++---------------------- src/sdl/i_video.c | 12 +++++--- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 7b440d46..a0712381 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6792,15 +6792,6 @@ void M_SetupJoystickMenu(INT32 choice) strcpy(joystickInfo[i], "None"); - // Hotplugging breaks if this block is run - // Because the cvar is set to 0, which disables controllers for that player -#if 0 // #ifdef JOYSTICK_HOTPLUG - if (0 == cv_usejoystick.value) - CV_SetValue(&cv_usejoystick, 0); - if (0 == cv_usejoystick2.value) - CV_SetValue(&cv_usejoystick2, 0); -#endif - for (i = 1; i < 8; i++) { if (i <= n && (I_GetJoyName(i)) != NULL) @@ -6845,52 +6836,66 @@ static void M_AssignJoystick(INT32 choice) { #ifdef JOYSTICK_HOTPLUG INT32 oldchoice; - - if (choice > I_NumJoys()) - return; + INT32 numjoys = I_NumJoys(); if (setupcontrols_secondaryplayer) { - oldchoice = atoi(cv_usejoystick2.string) > I_NumJoys() ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value; + oldchoice = atoi(cv_usejoystick2.string) > numjoys ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value; CV_SetValue(&cv_usejoystick2, choice); // Just in case last-minute changes were made to cv_usejoystick.value, // update the string too - CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); - - if (oldchoice != choice) + // But don't do this if we're intentionally setting higher than numjoys + if (choice <= numjoys) { - if (choice && oldchoice > I_NumJoys()) // if we did not select "None", we likely selected a used device - CV_SetValue(&cv_usejoystick2, oldchoice); + CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); - if (oldchoice == - (atoi(cv_usejoystick2.string) > I_NumJoys() ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value)) - M_StartMessage("This joystick is used by another\n" - "player. Reset the joystick\n" - "for that player first.\n\n" - "(Press a key)\n", NULL, MM_NOTHING); + // reset this so the comparison is valid + if (oldchoice > numjoys) + oldchoice = cv_usejoystick2.value; + + if (oldchoice != choice) + { + if (choice && oldchoice > numjoys) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick2, oldchoice); + + if (oldchoice == + (atoi(cv_usejoystick2.string) > numjoys ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value)) + M_StartMessage("This joystick is used by another\n" + "player. Reset the joystick\n" + "for that player first.\n\n" + "(Press a key)\n", NULL, MM_NOTHING); + } } } else { - oldchoice = atoi(cv_usejoystick.string) > I_NumJoys() ? atoi(cv_usejoystick.string) : cv_usejoystick.value; + oldchoice = atoi(cv_usejoystick.string) > numjoys ? atoi(cv_usejoystick.string) : cv_usejoystick.value; CV_SetValue(&cv_usejoystick, choice); // Just in case last-minute changes were made to cv_usejoystick.value, // update the string too - CV_SetValue(&cv_usejoystick, cv_usejoystick.value); - - if (oldchoice != choice) + // But don't do this if we're intentionally setting higher than numjoys + if (choice <= numjoys) { - if (choice && oldchoice > I_NumJoys()) // if we did not select "None", we likely selected a used device - CV_SetValue(&cv_usejoystick, oldchoice); + CV_SetValue(&cv_usejoystick, cv_usejoystick.value); - if (oldchoice == - (atoi(cv_usejoystick.string) > I_NumJoys() ? atoi(cv_usejoystick.string) : cv_usejoystick.value)) - M_StartMessage("This joystick is used by another\n" - "player. Reset the joystick\n" - "for that player first.\n\n" - "(Press a key)\n", NULL, MM_NOTHING); + // reset this so the comparison is valid + if (oldchoice > numjoys) + oldchoice = cv_usejoystick.value; + + if (oldchoice != choice) + { + if (choice && oldchoice > numjoys) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick, oldchoice); + + if (oldchoice == + (atoi(cv_usejoystick.string) > numjoys ? atoi(cv_usejoystick.string) : cv_usejoystick.value)) + M_StartMessage("This joystick is used by another\n" + "player. Reset the joystick\n" + "for that player first.\n\n" + "(Press a key)\n", NULL, MM_NOTHING); + } } } #else diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 318777f1..4419284e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -930,12 +930,14 @@ void I_GetEvent(void) // Was cv_usejoystick disabled in settings? if (!strcmp(cv_usejoystick.string, "0") || !cv_usejoystick.value) cv_usejoystick.value = 0; - else if (cv_usejoystick.value) // update the cvar ONLY if a device exists + else if (atoi(cv_usejoystick.string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys + && cv_usejoystick.value) // update the cvar ONLY if a device exists CV_SetValue(&cv_usejoystick, cv_usejoystick.value); if (!strcmp(cv_usejoystick2.string, "0") || !cv_usejoystick2.value) cv_usejoystick2.value = 0; - else if (cv_usejoystick2.value) // update the cvar ONLY if a device exists + else if (atoi(cv_usejoystick2.string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys + && cv_usejoystick2.value) // update the cvar ONLY if a device exists CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); // Update all joysticks' init states @@ -993,12 +995,14 @@ void I_GetEvent(void) // Was cv_usejoystick disabled in settings? if (!strcmp(cv_usejoystick.string, "0")) cv_usejoystick.value = 0; - else if (cv_usejoystick.value) // update the cvar ONLY if a device exists + else if (atoi(cv_usejoystick.string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys + && cv_usejoystick.value) // update the cvar ONLY if a device exists CV_SetValue(&cv_usejoystick, cv_usejoystick.value); if (!strcmp(cv_usejoystick2.string, "0")) cv_usejoystick2.value = 0; - else if (cv_usejoystick2.value) // update the cvar ONLY if a device exists + else if (atoi(cv_usejoystick2.string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys + && cv_usejoystick2.value) // update the cvar ONLY if a device exists CV_SetValue(&cv_usejoystick2, cv_usejoystick2.value); CONS_Debug(DBG_GAMELOGIC, "Joystick1 device index: %d\n", JoyInfo.oldjoy); From fa63ddda86fac929a4e6dea92eb0c627e8d6f090 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 06:05:31 -0500 Subject: [PATCH 19/21] Fix cv_usejoystick being reset to None when cv_usejoystick was > NumJoys and changing to already-used joystick --- src/m_menu.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index a0712381..9b5e1098 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6835,12 +6835,12 @@ static void M_Setup2PJoystickMenu(INT32 choice) static void M_AssignJoystick(INT32 choice) { #ifdef JOYSTICK_HOTPLUG - INT32 oldchoice; + INT32 oldchoice, oldstringchoice; INT32 numjoys = I_NumJoys(); if (setupcontrols_secondaryplayer) { - oldchoice = atoi(cv_usejoystick2.string) > numjoys ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value; + oldchoice = oldstringchoice = atoi(cv_usejoystick2.string) > numjoys ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value; CV_SetValue(&cv_usejoystick2, choice); // Just in case last-minute changes were made to cv_usejoystick.value, @@ -6856,10 +6856,10 @@ static void M_AssignJoystick(INT32 choice) if (oldchoice != choice) { - if (choice && oldchoice > numjoys) // if we did not select "None", we likely selected a used device - CV_SetValue(&cv_usejoystick2, oldchoice); + if (choice && oldstringchoice > numjoys) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick2, (oldstringchoice > numjoys ? oldstringchoice : oldchoice)); - if (oldchoice == + if (oldstringchoice == (atoi(cv_usejoystick2.string) > numjoys ? atoi(cv_usejoystick2.string) : cv_usejoystick2.value)) M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" @@ -6870,7 +6870,7 @@ static void M_AssignJoystick(INT32 choice) } else { - oldchoice = atoi(cv_usejoystick.string) > numjoys ? atoi(cv_usejoystick.string) : cv_usejoystick.value; + oldchoice = oldstringchoice = atoi(cv_usejoystick.string) > numjoys ? atoi(cv_usejoystick.string) : cv_usejoystick.value; CV_SetValue(&cv_usejoystick, choice); // Just in case last-minute changes were made to cv_usejoystick.value, @@ -6886,10 +6886,10 @@ static void M_AssignJoystick(INT32 choice) if (oldchoice != choice) { - if (choice && oldchoice > numjoys) // if we did not select "None", we likely selected a used device - CV_SetValue(&cv_usejoystick, oldchoice); + if (choice && oldstringchoice > numjoys) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick, (oldstringchoice > numjoys ? oldstringchoice : oldchoice)); - if (oldchoice == + if (oldstringchoice == (atoi(cv_usejoystick.string) > numjoys ? atoi(cv_usejoystick.string) : cv_usejoystick.value)) M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" From d094a70ec3872276b1bd2fb8cfddf15b59bcc7e9 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 06:06:37 -0500 Subject: [PATCH 20/21] Allow use_joystick/2 to be saved once again --- src/d_netcmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 16c08309..8abfb870 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -46,13 +46,6 @@ #include "m_cond.h" #include "m_anigif.h" -#if defined(HAVE_SDL) -#include "SDL.h" -#if SDL_VERSION_ATLEAST(2,0,0) -#include "sdl/sdlmain.h" // JOYSTICK_HOTPLUG -#endif -#endif - #ifdef NETGAME_DEVMODE #define CV_RESTRICT CV_NETVAR #else @@ -250,19 +243,10 @@ consvar_t cv_usemouse = {"use_mouse", "On", CV_SAVE|CV_CALL,usemouse_cons_t, I_S consvar_t cv_usemouse2 = {"use_mouse2", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse2, 0, NULL, NULL, 0, 0, NULL}; #if defined (DC) || defined (_XBOX) || defined (WMINPUT) || defined (_WII) || defined(HAVE_SDL) || defined(_WINDOWS) //joystick 1 and 2 -// JOYSTICK_HOTPLUG is set by sdlmain.h (SDL2) -// because SDL joystick indexes are unstable, and hotplugging can change a device's index. -// So let's not save any index changes to the config -consvar_t cv_usejoystick = {"use_joystick", "1", CV_CALL -#ifndef JOYSTICK_HOTPLUG - |CV_SAVE -#endif - , usejoystick_cons_t, I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_usejoystick2 = {"use_joystick2", "2", CV_CALL -#ifndef JOYSTICK_HOTPLUG - |CV_SAVE -#endif - , usejoystick_cons_t, I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_usejoystick2 = {"use_joystick2", "2", CV_SAVE|CV_CALL, usejoystick_cons_t, + I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}; #elif defined (PSP) || defined (GP2X) || defined (_NDS) //only one joystick consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; From c49a5ed8d2947ed4d14dc1626c161f6f55333ccf Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Dec 2018 06:14:21 -0500 Subject: [PATCH 21/21] Better I_InitJoystick log message --- src/sdl/i_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index bf8fdbcf..c152346c 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1400,7 +1400,7 @@ void I_InitJoystick(void) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { - CONS_Printf("Initing joy system\n"); + CONS_Printf("I_InitJoystick()...\n"); SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { @@ -1443,7 +1443,7 @@ void I_InitJoystick2(void) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { - CONS_Printf("Initing joy system\n"); + CONS_Printf("I_InitJoystick2()...\n"); SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) {