From: Cloudwalk Date: Sat, 18 Sep 2021 21:55:44 +0000 (-0400) Subject: Merge branch 'master' into Cloudwalk/cvar_overhaul X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=refs%2Fheads%2FCloudwalk%2Fcvar_overhaul;p=xonotic%2Fdarkplaces.git Merge branch 'master' into Cloudwalk/cvar_overhaul --- 6d93c4f8690ca25a0333cc5edc701dae69f41a63 diff --cc cmd.c index 3ff1d5f0,e8f16889..a0bc484c --- a/cmd.c +++ b/cmd.c @@@ -1580,7 -1579,7 +1580,7 @@@ static void Cmd_Apropos_f(cmd_state_t * partial = va(vabuf, sizeof(vabuf), "*%s*", partial); count = 0; - List_For_Each_Entry(cvar, &cmd->cvars->vars->list, list) - for (cvar = cmd->cvars->vars; cvar; cvar = cvar->next) ++ List_For_Each_Entry(cvar, &cmd->cvars->vars->list, cvar_t, list) { if (matchpattern_with_separator(cvar->name, partial, true, "", false) || matchpattern_with_separator(cvar->description, partial, true, "", false)) diff --cc cvar.c index 541ca9ef,7936c923..0f5a97cb --- a/cvar.c +++ b/cvar.c @@@ -55,18 -59,17 +55,18 @@@ cvar_t *Cvar_FindVarAfter(cvar_state_t 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; } @@@ -158,7 -194,7 +158,7 @@@ const char *Cvar_CompleteVariable(cvar_ 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; @@@ -186,9 -223,14 +186,9 @@@ int Cvar_CompleteCountPossible(cvar_sta 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; } @@@ -212,9 -254,14 +212,9 @@@ const char **Cvar_CompleteBuildList(cva 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; @@@ -241,9 -288,15 +241,9 @@@ void Cvar_CompleteCvarPrint(cvar_state_ 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 @@@ -309,12 -362,8 +309,12 @@@ static void Cvar_UpdateAutoCvar(cvar_t 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) @@@ -424,32 -482,6 +424,32 @@@ void Cvar_SetValue(cvar_state_t *cvars Cvar_Set(cvars, var_name, val); } +/* +============ +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, list) ++ 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) @@@ -460,26 -492,11 +460,26 @@@ 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) { @@@ -765,7 -795,7 +765,7 @@@ void Cvar_UnlockDefaults(cmd_state_t *c 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; } @@@ -774,9 -804,9 +774,9 @@@ void Cvar_LockDefaults_f(cmd_state_t *c 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; @@@ -792,72 -822,41 +792,72 @@@ 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 { @@@ -885,9 -912,9 +885,9 @@@ void Cvar_ResetToDefaults_All_f(cmd_sta 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); } } @@@ -897,9 -924,9 +897,9 @@@ void Cvar_ResetToDefaults_NoSaveOnly_f( 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); } } @@@ -909,9 -937,9 +909,9 @@@ void Cvar_ResetToDefaults_SaveOnly_f(cm 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); } } @@@ -930,10 -958,7 +930,10 @@@ void Cvar_WriteVariables (cvar_state_t 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); @@@ -973,7 -998,7 +973,7 @@@ void Cvar_List_f(cmd_state_t *cmd } 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)) { diff --cc prvm_cmds.c index c0b50beb,3ef0b74c..89a762ef --- a/prvm_cmds.c +++ b/prvm_cmds.c @@@ -4630,7 -4630,7 +4630,7 @@@ void VM_buf_cvarlist(prvm_prog_t *prog antiispattern = antipartial && (strchr(antipartial, '*') || strchr(antipartial, '?')); n = 0; - List_For_Each_Entry(cvar, &prog->console_cmd->cvars->vars->list, list) - for(cvar = prog->console_cmd->cvars->vars; cvar; cvar = cvar->next) ++ List_For_Each_Entry(cvar, &prog->console_cmd->cvars->vars->list, cvar_t, list) { if(len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp(partial, cvar->name, len))) continue; @@@ -4646,7 -4646,7 +4646,7 @@@ stringbuffer->strings = (char **)Mem_Alloc(prog->progs_mempool, sizeof(stringbuffer->strings[0]) * stringbuffer->max_strings); n = 0; - List_For_Each_Entry(cvar, &prog->console_cmd->cvars->vars->list, list) - for(cvar = prog->console_cmd->cvars->vars; cvar; cvar = cvar->next) ++ List_For_Each_Entry(cvar, &prog->console_cmd->cvars->vars->list, cvar_t, list) { if(len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp(partial, cvar->name, len))) continue; diff --cc prvm_edict.c index fb77fd32,ea839275..37d35e9a --- a/prvm_edict.c +++ b/prvm_edict.c @@@ -2573,7 -2573,7 +2573,7 @@@ void PRVM_Prog_Load(prvm_prog_t *prog, } } - List_For_Each_Entry(cvar, &prog->console_cmd->cvars->vars->list, list) - for (cvar = prog->console_cmd->cvars->vars; cvar; cvar = cvar->next) ++ List_For_Each_Entry(cvar, &prog->console_cmd->cvars->vars->list, cvar_t, list) cvar->globaldefindex[prog - prvm_prog_list] = -1; for (i=0 ; inumglobaldefs ; i++)