var = Cvar_FindVar(cvars, prev_var_name, neededflags);
if (!var)
return NULL;
- var = List_Next_Entry(var->parent ? var->parent : var, list);
- var = var->next;
++ var = List_Next_Entry(var->parent ? var->parent : var, cvar_t, list);
}
else
var = cvars->vars;
// search for the next cvar matching the needed flags
- List_For_Each_Entry_From(var, &cvars->vars->list, list)
- while (var)
++ List_For_Each_Entry_From(var, &cvars->vars->list, cvar_t, list)
{
+ if (var->parent)
+ continue;
if (var->flags & neededflags)
break;
- var = var->next;
}
return var;
}
return NULL;
// check functions
- List_For_Each_Entry(cvar, &cvars->vars->list, list)
- for (cvar=cvars->vars ; cvar ; cvar=cvar->next)
++ List_For_Each_Entry(cvar, &cvars->vars->list, cvar_t, list)
if (!strncasecmp (partial,cvar->name, len) && (cvar->flags & neededflags))
return cvar->name;
return 0;
// Loop through the cvars and count all possible matches
- List_For_Each_Entry(cvar, &cvars->vars->list, list)
- for (cvar = cvars->vars; cvar; cvar = cvar->next)
++ List_For_Each_Entry(cvar, &cvars->vars->list, cvar_t, list)
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
h++;
- else
- for (char **alias = cvar->aliases; alias && *alias; alias++)
- if (!strncasecmp(partial, *alias, len) && (cvar->flags & neededflags))
- h++;
-
return h;
}
len = strlen(partial);
buf = (const char **)Mem_Alloc(tempmempool, sizeofbuf + sizeof(const char *));
// Loop through the alias list and print all matches
- List_For_Each_Entry(cvar, &cvars->vars->list, list)
- for (cvar = cvars->vars; cvar; cvar = cvar->next)
++ List_For_Each_Entry(cvar, &cvars->vars->list, cvar_t, list)
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
buf[bpos++] = cvar->name;
- else
- for (char **alias = cvar->aliases; alias && *alias; alias++)
- if (!strncasecmp(partial, *alias, len) && (cvar->flags & neededflags))
- buf[bpos++] = *alias;
-
buf[bpos] = NULL;
return buf;
cvar_t *cvar;
size_t len = strlen(partial);
// Loop through the command list and print all matches
- List_For_Each_Entry(cvar, &cvars->vars->list, list)
- for (cvar = cvars->vars; cvar; cvar = cvar->next)
++ List_For_Each_Entry(cvar, &cvars->vars->list, cvar_t, list)
if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags))
- Cvar_PrintHelp(cvar, cvar->name, true);
- else
- for (char **alias = cvar->aliases; alias && *alias; alias++)
- if (!strncasecmp (partial, *alias, len) && (cvar->flags & neededflags))
- Cvar_PrintHelp(cvar, *alias, true);
-
-
+ Cvar_PrintHelp(cvar->parent ? cvar->parent : cvar, cvar->name, true);
}
// check if a cvar is held by some progs
void Cvar_UpdateAllAutoCvars(cvar_state_t *cvars)
{
cvar_t *var;
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next)
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
+ {
+ if(var->parent)
+ continue;
Cvar_UpdateAutoCvar(var);
+ }
}
void Cvar_Callback(cvar_t *var)
Cvar_Set(cvars, var_name, val);
}
- List_For_Each_Entry(current, &cvars->vars->list, list)
+/*
+============
+Cvar_Link
+
+Links a variable to the variable list and hashtable
+============
+*/
+static void Cvar_Link(cvar_t *variable, cvar_state_t *cvars)
+{
+ cvar_t *current;
+ int hashindex;
+
+ // Link the object in alphanumerical order
++ List_For_Each_Entry(current, &cvars->vars->list, cvar_t, list)
+ if(strcmp(current->name, variable->name) > 0)
+ break;
+
+ List_Add_Tail(&variable->list, ¤t->list);
+
+ // link to head of list in this hash table index
+ hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name)) % CVAR_HASHSIZE;
+ variable->hnext = cvars->hashtable[hashindex];
+ cvars->hashtable[hashindex] = variable;
+ variable->hashindex = hashindex;
+}
+
void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *))
{
if (variable == NULL)
variable->callback = callback;
}
-void Cvar_RegisterVirtual(cvar_t *variable, const char *name )
+static void Cvar_DeleteVirtual(cvar_t *vcvar)
+{
+ List_Delete(&vcvar->vlist);
+ List_Delete(&vcvar->list);
+ Mem_Free((char *)vcvar->name);
+ Mem_Free(vcvar);
+}
+
+static void Cvar_DeleteVirtual_All(cvar_t *var)
+{
+ cvar_t *vcvar, *vcvar_next;
+
- List_For_Each_Entry_Safe(vcvar, vcvar_next, &var->vlist, vlist)
++ List_For_Each_Entry_Safe(vcvar, vcvar_next, &var->vlist, cvar_t, vlist)
+ Cvar_DeleteVirtual(vcvar);
+}
+
+void Cvar_RegisterVirtual(cvar_t *variable, const char *name)
{
cvar_state_t *cvars = &cvars_all;
- cvar_hash_t *hash;
- int hashindex;
+ cvar_t *vcvar;
if(!*name)
{
cvar_state_t *cvars = cmd->cvars;
cvar_t *var;
// unlock the default values of all cvars
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next)
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
var->flags &= ~CF_DEFAULTSET;
}
cvar_state_t *cvars = cmd->cvars;
cvar_t *var;
// lock in the default values of all cvars
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next)
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
{
- if (!(var->flags & CF_DEFAULTSET))
+ if (!var->parent && !(var->flags & CF_DEFAULTSET))
{
size_t alloclen;
void Cvar_SaveInitState(cvar_state_t *cvars)
{
- cvar_t *c;
- for (c = cvars->vars;c;c = c->next)
+ cvar_t *cvar, *vcvar;
+
- List_For_Each_Entry(cvar, &cvars->vars->list, list)
++ List_For_Each_Entry(cvar, &cvars->vars->list, cvar_t, list)
{
- c->initstate = (cvar_t *)Z_Malloc(sizeof(cvar_t));
- memcpy(c->initstate, c, sizeof(cvar_t));
+ // Get the the virtual cvars separately
+ if(cvar->parent)
+ continue;
+
+ cvar->initstate = (cvar_t *)Mem_Alloc(cvars->mempool, sizeof(cvar_t));
+ memcpy(cvar->initstate, cvar, sizeof(cvar_t));
+
+ if(cvar->description == cvar_dummy_description)
+ cvar->initstate->description = cvar_dummy_description;
+ else
+ cvar->initstate->description = (char *)Mem_strdup(cvars->mempool, cvar->description);
+
+ cvar->initstate->string = (char *)Mem_strdup(cvars->mempool, cvar->string);
+ cvar->initstate->defstring = (char *)Mem_strdup(cvars->mempool, cvar->defstring);
+
+ /*
+ * Consider any virtual cvar created up to this point as
+ * existing during init. Use the initstate of the parent cvar.
+ */
- List_For_Each_Entry(vcvar, &cvar->vlist, list)
++ List_For_Each_Entry(vcvar, &cvar->vlist, cvar_t, list)
+ vcvar->initstate = cvar->initstate;
}
}
void Cvar_RestoreInitState(cvar_state_t *cvars)
{
- int hashindex;
- cvar_t *c, **cp;
- cvar_t *c2, **cp2;
- for (cp = &cvars->vars;(c = *cp);)
+ cvar_t *var, *next;
+
- List_For_Each_Entry_Safe(var, next, &cvars->vars->list, list)
++ List_For_Each_Entry_Safe(var, next, &cvars->vars->list, cvar_t, list)
{
- if (c->initstate)
+ // Destroy all virtual cvars that didn't exist at init
+ if(var->parent && !var->initstate)
+ {
+ Cvar_DeleteVirtual(var);
+ continue;
+ }
+
+ if (var->initstate)
{
// restore this cvar, it existed at init
- if (((c->flags ^ c->initstate->flags) & CF_MAXFLAGSVAL)
- || strcmp(c->defstring ? c->defstring : "", c->initstate->defstring ? c->initstate->defstring : "")
- || strcmp(c->string ? c->string : "", c->initstate->string ? c->initstate->string : ""))
+ Con_DPrintf("Cvar_RestoreInitState: Restoring cvar \"%s\"\n", var->name);
+ if(var->flags & CF_ALLOCATED)
{
- Con_DPrintf("Cvar_RestoreInitState: Restoring cvar \"%s\"\n", c->name);
- if (c->defstring)
- Z_Free((char *)c->defstring);
- c->defstring = Mem_strdup(zonemempool, c->initstate->defstring);
- if (c->string)
- Z_Free((char *)c->string);
- c->string = Mem_strdup(zonemempool, c->initstate->string);
+ if(var->flags & CF_ALLOCATED && var->description && var->description != cvar_dummy_description)
+ Z_Free((char *)var->description);
+ if(var->initstate->description == cvar_dummy_description)
+ var->description = cvar_dummy_description;
+ else
+ var->initstate->description = (char *)Mem_strdup(cvars->mempool, var->description);
}
- c->flags = c->initstate->flags;
- c->value = c->initstate->value;
- c->integer = c->initstate->integer;
- VectorCopy(c->initstate->vector, c->vector);
- cp = &c->next;
+
+ if (var->defstring)
+ Z_Free((char *)var->defstring);
+ var->defstring = Mem_strdup(cvars->mempool, var->initstate->defstring);
+ if (var->string)
+ Z_Free((char *)var->string);
+ var->string = Mem_strdup(cvars->mempool, var->initstate->string);
+
+ var->flags = var->initstate->flags;
+ var->value = var->initstate->value;
+ var->integer = var->initstate->integer;
+ VectorCopy(var->initstate->vector, var->vector);
}
else
{
cvar_state_t *cvars = cmd->cvars;
cvar_t *var;
// restore the default values of all cvars
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next)
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
{
- if((var->flags & CF_PERSISTENT) == 0)
+ if(!var->parent && !(var->flags & CF_PERSISTENT))
Cvar_SetQuick(var, var->defstring);
}
}
cvar_state_t *cvars = cmd->cvars;
cvar_t *var;
// restore the default values of all cvars
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next)
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
{
- if ((var->flags & (CF_PERSISTENT | CF_ARCHIVE)) == 0)
+ if (!var->parent && !(var->flags & (CF_PERSISTENT | CF_ARCHIVE)))
Cvar_SetQuick(var, var->defstring);
}
}
cvar_state_t *cvars = cmd->cvars;
cvar_t *var;
// restore the default values of all cvars
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next)
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
{
- if ((var->flags & (CF_PERSISTENT | CF_ARCHIVE)) == CF_ARCHIVE)
+ if (!var->parent && (var->flags & (CF_PERSISTENT | CF_ARCHIVE)) == CF_ARCHIVE)
Cvar_SetQuick(var, var->defstring);
}
}
char buf1[MAX_INPUTLINE], buf2[MAX_INPUTLINE];
// don't save cvars that match their default value
- List_For_Each_Entry(var, &cvars->vars->list, list)
- for (var = cvars->vars ; var ; var = var->next) {
++ List_For_Each_Entry(var, &cvars->vars->list, cvar_t, list)
+ {
+ if(var->parent)
+ continue;
if ((var->flags & CF_ARCHIVE) && (strcmp(var->string, var->defstring) || ((var->flags & CF_ALLOCATED) && !(var->flags & CF_DEFAULTSET))))
{
Cmd_QuoteString(buf1, sizeof(buf1), var->name, "\"\\$", false);
}
count = 0;
- List_For_Each_Entry(cvar, &cvars->vars->list, list)
- for (cvar = cvars->vars; cvar; cvar = cvar->next)
++ List_For_Each_Entry(cvar, &cvars->vars->list, cvar_t, list)
{
if (matchpattern_with_separator(cvar->name, partial, false, "", false))
{