Fix bugs with unbound mouse and joystick controls not saving properly.

git-svn-id: https://svn.eduke32.com/eduke32@7943 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2019-08-10 23:29:20 +00:00 committed by Christoph Oelckers
parent 47d8541cf3
commit 87c31bbdf5
3 changed files with 14 additions and 21 deletions

View file

@ -53,10 +53,10 @@ int32_t CONFIG_FunctionNameToNum(const char *func)
} }
char *CONFIG_FunctionNumToName(int32_t func) static char const * CONFIG_FunctionNumToName(int32_t func)
{ {
if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS) if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
return NULL; return "";
return gamefunctions[func]; return gamefunctions[func];
} }
@ -78,7 +78,7 @@ int32_t CONFIG_AnalogNameToNum(const char *func)
} }
const char *CONFIG_AnalogNumToName(int32_t func) static char const * CONFIG_AnalogNumToName(int32_t func)
{ {
switch (func) switch (func)
{ {
@ -92,7 +92,7 @@ const char *CONFIG_AnalogNumToName(int32_t func)
return "analog_lookingupanddown"; return "analog_lookingupanddown";
} }
return NULL; return "";
} }
@ -441,20 +441,17 @@ void CONFIG_SetupMouse(void)
Bsprintf(str,"MouseAnalogAxes%d",i); Bsprintf(str,"MouseAnalogAxes%d",i);
temp[0] = 0; temp[0] = 0;
if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp)) if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1)) ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
Bsprintf(str,"MouseDigitalAxes%d_0",i); Bsprintf(str,"MouseDigitalAxes%d_0",i);
temp[0] = 0; temp[0] = 0;
if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp)) if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1)) ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
Bsprintf(str,"MouseDigitalAxes%d_1",i); Bsprintf(str,"MouseDigitalAxes%d_1",i);
temp[0] = 0; temp[0] = 0;
if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp)) if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1)) ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
Bsprintf(str,"MouseAnalogScale%d",i); Bsprintf(str,"MouseAnalogScale%d",i);
int32_t scale = ud.config.MouseAnalogueScale[i]; int32_t scale = ud.config.MouseAnalogueScale[i];
@ -505,20 +502,17 @@ void CONFIG_SetupJoystick(void)
Bsprintf(str,"JoystickAnalogAxes%d",i); Bsprintf(str,"JoystickAnalogAxes%d",i);
temp[0] = 0; temp[0] = 0;
if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp)) if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1)) ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
Bsprintf(str,"JoystickDigitalAxes%d_0",i); Bsprintf(str,"JoystickDigitalAxes%d_0",i);
temp[0] = 0; temp[0] = 0;
if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp)) if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1)) ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
Bsprintf(str,"JoystickDigitalAxes%d_1",i); Bsprintf(str,"JoystickDigitalAxes%d_1",i);
temp[0] = 0; temp[0] = 0;
if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp)) if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1)) ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
Bsprintf(str,"JoystickAnalogScale%d",i); Bsprintf(str,"JoystickAnalogScale%d",i);
scale = ud.config.JoystickAnalogueScale[i]; scale = ud.config.JoystickAnalogueScale[i];
@ -703,10 +697,11 @@ void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.
for (int i=0; i<NUMGAMEFUNCTIONS; ++i) for (int i=0; i<NUMGAMEFUNCTIONS; ++i)
{ {
if (CONFIG_FunctionNumToName(i) && (ud.config.KeyboardKeys[i][0] == 0xff || !ud.config.KeyboardKeys[i][0])) char const * name = CONFIG_FunctionNumToName(i);
if (name && name[0] != '\0' && (ud.config.KeyboardKeys[i][0] == 0xff || !ud.config.KeyboardKeys[i][0]))
{ {
buildvfs_fputstr(fp, "unbound "); buildvfs_fputstr(fp, "unbound ");
buildvfs_fputstrptr(fp, CONFIG_FunctionNumToName(i)); buildvfs_fputstrptr(fp, name);
buildvfs_fputstr(fp, "\n"); buildvfs_fputstr(fp, "\n");
} }
} }

View file

@ -36,10 +36,8 @@ int32_t CONFIG_GetMapBestTime(char const *mapname, uint8_t const *mapmd4);
int CONFIG_SetMapBestTime(uint8_t const *mapmd4, int32_t tm); int CONFIG_SetMapBestTime(uint8_t const *mapmd4, int32_t tm);
int32_t CONFIG_FunctionNameToNum(const char *func); int32_t CONFIG_FunctionNameToNum(const char *func);
char * CONFIG_FunctionNumToName(int32_t func);
int32_t CONFIG_AnalogNameToNum(const char *func); int32_t CONFIG_AnalogNameToNum(const char *func);
const char *CONFIG_AnalogNumToName(int32_t func);
void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2); void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2);

View file

@ -292,7 +292,7 @@ void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device)
{ {
controlaxismaptype *set; controlaxismaptype *set;
if ((unsigned)whichanalog >= (unsigned)analog_maxtype) if ((unsigned)whichanalog >= (unsigned)analog_maxtype && whichanalog != -1)
{ {
//Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.", //Error("CONTROL_MapAnalogAxis: analog function %d out of valid range for %d analog functions.",
// whichanalog, analog_maxtype); // whichanalog, analog_maxtype);