Skip to content

Commit

Permalink
Only write modified CVARs to user's config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
JadingTsunami committed Nov 11, 2023
1 parent 8df39fd commit 68f1af6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions prboom2/src/c_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,8 @@ 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 @@ -1534,8 +1536,6 @@ void C_LoadSettings()
C_printcmd(linebuffer);
}

C_CvarInit();

free(linebuffer);
}

Expand Down
16 changes: 13 additions & 3 deletions prboom2/src/c_cvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ typedef struct cvar_s {
unsigned int flags;
/* fast access path for "evalutes true" */
dboolean is_set;
dboolean modified;
cvartype_t type;
cvarval_t numValue;
cvarval_t maxValue;
cvarval_t minValue;
char* stringVal;
struct cvar_s* next;
struct cvar_s* prev;
Expand Down Expand Up @@ -259,12 +258,23 @@ cvarstatus_t C_CvarCreateOrUpdate(const char* key, const char* value, cvarflags_
if (cvar) {
/* exists, update, but keep flags */
flags |= cvar->flags;

/* set modified flag */
if (type == CVAR_TYPE_INT) {
cvar->modified = (cvar->numValue.intVal != convertedValue.intVal);
} else if (type == CVAR_TYPE_FLOAT) {
cvar->modified = (cvar->numValue.floatVal != convertedValue.floatVal);
} else {
cvar->modified = (strcasecmp(value, cvar->stringVal) != 0);
}

free(cvar->stringVal);
} else {
/* create brand new cvar */
hash = HashString(key);
cvar = malloc(sizeof(cvar_t));
cvar->key = strdup(key);
cvar->modified = false;

/* register in hash map */
if (cvar_map[hash]) {
Expand Down Expand Up @@ -354,7 +364,7 @@ void C_CvarExportToFile(FILE* f)
c = cvar_map[i];

while (c) {
if (c->flags & CVAR_FLAG_ARCHIVE) {
if (c->modified && (c->flags & CVAR_FLAG_ARCHIVE)) {
switch (c->type) {
case CVAR_TYPE_INT:
fprintf(f, "set %s %d\n", c->key, c->numValue.intVal);
Expand Down

0 comments on commit 68f1af6

Please sign in to comment.