Merge branch '2122-execversion' into '2122-version'

EXECVERSION adjustments (config updater)

See merge request STJr/SRB2!408
This commit is contained in:
Digiku 2018-12-20 18:01:48 -05:00
commit edbf9073c6
4 changed files with 40 additions and 13 deletions

View file

@ -49,6 +49,7 @@ static void COM_Wait_f(void);
static void COM_Help_f(void);
static void COM_Toggle_f(void);
static void CV_EnforceExecVersion(void);
static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr);
static boolean CV_Command(void);
static consvar_t *CV_FindVar(const char *name);
@ -63,10 +64,11 @@ 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
// Filter consvars by EXECVERSION
// 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",0,CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL};
static boolean execversion_enabled = false;
consvar_t cv_execversion = {"execversion","25",CV_CALL,CV_Unsigned, CV_EnforceExecVersion, 0, NULL, NULL, 0, 0, NULL};
// for default joyaxis detection
static boolean joyaxis_default = false;
@ -1586,10 +1588,21 @@ void CV_InitFilterVar(void)
joyaxis_count = joyaxis2_count = 0;
}
void CV_ToggleExecVersion(boolean enable)
{
execversion_enabled = enable;
}
static void CV_EnforceExecVersion(void)
{
if (!execversion_enabled)
CV_StealthSetValue(&cv_execversion, EXECVERSION);
}
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)
// EXECVERSION < 26 (2.1.21)
if (joyaxis_default)
{
@ -1737,8 +1750,7 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr)
if (!(v->flags & CV_SAVE))
return true;
// We go by MODVERSION here
if (cv_execversion.value < 26) // 26 = 2.1.21
if (GETMAJOREXECVERSION(cv_execversion.value) < 26) // 26 = 2.1.21
{
// MOUSE SETTINGS
// alwaysfreelook split between first and third person (chasefreelook)

View file

@ -130,6 +130,7 @@ extern CV_PossibleValue_t CV_Natural[];
extern consvar_t cv_execversion;
void CV_InitFilterVar(void);
void CV_ToggleExecVersion(boolean enable);
// register a variable for use at the console
void CV_RegisterVar(consvar_t *variable);

View file

@ -216,6 +216,20 @@ extern FILE *logstream;
// Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1".
#define MODVERSION 27
// To version config.cfg, MAJOREXECVERSION is set equal to MODVERSION automatically.
// Increment MINOREXECVERSION whenever a config change is needed that does not correspond
// to an increment in MODVERSION. This might never happen in practice.
// If MODVERSION increases, set MINOREXECVERSION to 0.
#define MAJOREXECVERSION MODVERSION
#define MINOREXECVERSION 0
// (It would have been nice to use VERSION and SUBVERSION but those are zero'd out for DEVELOP builds)
// Macros
#define GETMAJOREXECVERSION(v) (v & 0xFFFF)
#define GETMINOREXECVERSION(v) (v >> 16)
#define GETEXECVERSION(major,minor) (major + (minor << 16))
#define EXECVERSION GETEXECVERSION(MAJOREXECVERSION, MINOREXECVERSION)
// =========================================================================
// The maximum number of players, multiplayer/networking.

View file

@ -443,7 +443,7 @@ void Command_LoadConfig_f(void)
FIL_ForceExtension(configfile, ".cfg");
// temporarily reset execversion to default
cv_execversion.flags &= ~CV_HIDEN;
CV_ToggleExecVersion(true);
COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue));
CV_InitFilterVar();
@ -451,8 +451,8 @@ void Command_LoadConfig_f(void)
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;
COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION));
CV_ToggleExecVersion(false);
}
/** Saves the current configuration and loads another.
@ -494,7 +494,7 @@ void M_FirstLoadConfig(void)
// temporarily reset execversion to default
// we shouldn't need to do this, but JUST in case...
cv_execversion.flags &= ~CV_HIDEN;
CV_ToggleExecVersion(true);
COM_BufInsertText(va("%s \"%s\"\n", cv_execversion.name, cv_execversion.defaultvalue));
CV_InitFilterVar();
@ -503,8 +503,8 @@ void M_FirstLoadConfig(void)
// 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;
COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION));
CV_ToggleExecVersion(false);
// make sure I_Quit() will write back the correct config
// (do not write back the config if it crash before)
@ -562,8 +562,8 @@ void M_SaveConfig(const char *filename)
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);
// always print current EXECVERSION
fprintf(f, "%s \"%d\"\n", cv_execversion.name, EXECVERSION);
// FIXME: save key aliases if ever implemented..