Skip to content

Commit

Permalink
Add init after config load as loading defaults is only necessary if t…
Browse files Browse the repository at this point in the history
…he user didn't supply some, which will happen most of the time.
  • Loading branch information
JadingTsunami committed Nov 10, 2023
1 parent 0d65a05 commit d496bee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
5 changes: 2 additions & 3 deletions prboom2/src/c_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,8 +1533,6 @@ void C_LoadSettings()
FILE* bindfile = NULL;
char* linebuffer = malloc(sizeof(char)*CONSOLE_CONFIG_LINE_MAX);

C_CvarInit();

bindfile = M_fopen(C_GetConsoleSettingsFile(), "r");
if (bindfile) {
while (!feof(bindfile)) {
Expand All @@ -1558,10 +1556,11 @@ void C_LoadSettings()
C_printcmd(linebuffer);
}

C_CvarInit();

free(linebuffer);
}


/* Complete a partial command with the nearest match
* If successful, returns the string match
* Returns NULL if no match was found.
Expand Down
32 changes: 26 additions & 6 deletions prboom2/src/c_cvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const char* cvarstatus_error_strings[] =
"Invalid CVAR type",
"Invalid CVAR value",
"Wrong CVAR type supplied",
"CVAR already exists",
"CVAR not found",
NULL
};
Expand All @@ -97,12 +98,12 @@ void C_CvarInit()

if (!initialized) {
initialized = true;
C_CvarCreateOrOverwrite("allmap_always", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreateOrOverwrite("plat_skip", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreateOrOverwrite("regenerate", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreateOrOverwrite("hudadd_showfps", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreateOrOverwrite("showfps", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreateOrOverwrite("r_drawplayersprites", "1", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreate("allmap_always", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreate("plat_skip", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreate("regenerate", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreate("hudadd_showfps", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreate("showfps", "0", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
C_CvarCreate("r_drawplayersprites", "1", CVAR_TYPE_INT, CVAR_FLAG_ARCHIVE);
}
}

Expand Down Expand Up @@ -266,6 +267,25 @@ cvarstatus_t C_CvarCreateOrOverwrite(const char* key, const char* value, cvartyp
return CVAR_STATUS_OK;
}

cvarstatus_t C_CvarCreate(const char* key, const char* value, cvartype_t type, cvarflags_t flags)
{
cvarstatus_t status;
cvar_t* cvar;
uint8_t hash;
char c;

if (key)
for (c = *key; c; c++)
c = tolower(c);

cvar = C_CvarFind(key, &status);

if (cvar)
return CVAR_STATUS_ALREADY_EXISTS;
else
return C_CvarCreateOrOverwrite(key, value, type, flags);
}

cvarstatus_t C_CvarDelete(const char* key)
{
cvarstatus_t status;
Expand Down
4 changes: 4 additions & 0 deletions prboom2/src/c_cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef enum cvarstatus_e {
CVAR_STATUS_INVALID_VALUE,
CVAR_STATUS_WRONG_TYPE,
CVAR_STATUS_KEY_NOT_FOUND,
CVAR_STATUS_ALREADY_EXISTS,
CVAR_STATUS_MAX
} cvarstatus_t;

Expand Down Expand Up @@ -74,6 +75,9 @@ char* C_CvarGetAsString(const char* key, cvarstatus_t* status);

/* type is changed if it's something else */
cvarstatus_t C_CvarCreateOrOverwrite(const char* key, const char* value, cvartype_t type, cvarflags_t flags);

/* does NOT overwrite if exists; returns failure status */
cvarstatus_t C_CvarCreate(const char* key, const char* value, cvartype_t type, cvarflags_t flags);
cvarstatus_t C_CvarDelete(const char* key);

const char* C_CvarComplete(const char* partial);
Expand Down

0 comments on commit d496bee

Please sign in to comment.