From 27aa321754fe8ae393a2335adb6e9130364a1268 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Mon, 8 Jun 2020 14:46:12 +0000 Subject: [PATCH] Reimpl. the cvar alias system. Reimpl. the cvar hash table as a distinct type It is now type-safe, cleaner, and doesn't require new static cvar_t's for each alias. The hash table being implemented as a distinct type allows multiple hashes to point to the same cvar without having to create a new cvar_t for each alias. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12652 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_input.c | 6 +- cl_parse.c | 2 +- cmd.c | 22 +++++- cvar.c | 190 ++++++++++++++++++++++++++++++++++----------------- cvar.h | 23 +++++-- host.c | 8 +-- lhnet.c | 2 +- menu.c | 10 +-- netconn.c | 23 ++++--- netconn.h | 2 +- prvm_edict.c | 17 ++--- sbar.c | 83 ++++++++++++---------- screen.h | 6 +- server.h | 2 +- sv_main.c | 16 +++-- 15 files changed, 261 insertions(+), 151 deletions(-) diff --git a/cl_input.c b/cl_input.c index ed7c44c3..903b240b 100644 --- a/cl_input.c +++ b/cl_input.c @@ -1470,7 +1470,7 @@ static void CL_ClientMovement_PlayerMove(cl_clientmovement_state_t *s) CL_ClientMovement_Physics_Walk(s); } -extern cvar_t slowmo; +extern cvar_t host_timescale; void CL_UpdateMoveVars(void) { if (cls.protocol == PROTOCOL_QUAKEWORLD) @@ -1517,8 +1517,8 @@ void CL_UpdateMoveVars(void) else { cl.moveflags = 0; - cl.movevars_ticrate = (cls.demoplayback ? 1.0f : slowmo.value) / bound(1.0f, cl_netfps.value, 1000.0f); - cl.movevars_timescale = (cls.demoplayback ? 1.0f : slowmo.value); + cl.movevars_ticrate = (cls.demoplayback ? 1.0f : host_timescale.value) / bound(1.0f, cl_netfps.value, 1000.0f); + cl.movevars_timescale = (cls.demoplayback ? 1.0f : host_timescale.value); cl.movevars_gravity = sv_gravity.value; cl.movevars_stopspeed = cl_movement_stopspeed.value; cl.movevars_maxspeed = cl_movement_maxspeed.value; diff --git a/cl_parse.c b/cl_parse.c index 45bd0137..78797300 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -3278,7 +3278,7 @@ static qboolean CL_ExaminePrintString(const char *text) return true; } -extern cvar_t slowmo; +extern cvar_t host_timescale; extern cvar_t cl_lerpexcess; static void CL_NetworkTimeReceived(double newtime) { diff --git a/cmd.c b/cmd.c index 1c5c4fb4..8257f973 100644 --- a/cmd.c +++ b/cmd.c @@ -1429,6 +1429,7 @@ static void Cmd_Apropos_f(cmd_state_t *cmd) int count; qboolean ispattern; char vabuf[1024]; + char *cvar_name; if (Cmd_Argc(cmd) > 1) partial = Cmd_Args(cmd); @@ -1445,11 +1446,26 @@ static void Cmd_Apropos_f(cmd_state_t *cmd) count = 0; for (cvar = cmd->cvars->vars; cvar; cvar = cvar->next) { - if (!matchpattern_with_separator(cvar->name, partial, true, "", false)) - if (!matchpattern_with_separator(cvar->description, partial, true, "", false)) + if (!matchpattern_with_separator(cvar->name, partial, true, "", false) && + !matchpattern_with_separator(cvar->description, partial, true, "", false)) + { + for (int i = 0; i < cvar->aliasindex; i++) + { + if (!matchpattern_with_separator(cvar->aliases[i], partial, true, "", false)) { + continue; + } else { + cvar_name = cvar->aliases[i]; + goto print; + } + } continue; + } else { + cvar_name = (char *)cvar->name; + break; + } +print: Con_Printf ("cvar "); - Cvar_PrintHelp(cvar, true); + Cvar_PrintHelp(cvar, cvar_name, true); count++; } for (func = cmd->userdefined->csqc_functions; func; func = func->next) diff --git a/cvar.c b/cvar.c index 0b039e7f..a0d0cb97 100644 --- a/cvar.c +++ b/cvar.c @@ -35,14 +35,17 @@ Cvar_FindVar cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, int neededflags) { int hashindex; - cvar_t *var; + cvar_hash_t *hash; // use hash lookup to minimize search time hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name)) % CVAR_HASHSIZE; - for (var = cvars->hashtable[hashindex];var;var = var->nextonhashchain) - if (!strcmp (var_name, var->name) && (var->flags & neededflags)) - return var; - + for (hash = cvars->hashtable[hashindex];hash;hash = hash->next) + if (!strcmp (var_name, hash->cvar->name) && (hash->cvar->flags & neededflags)) + return hash->cvar; + else + for (int i = 0; i < hash->cvar->aliasindex; i++) + if (!strcmp (var_name, hash->cvar->aliases[i]) && (hash->cvar->flags & neededflags)) + return hash->cvar; return NULL; } @@ -70,34 +73,37 @@ cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, int ne return var; } -static cvar_t *Cvar_FindVarLink(cvar_state_t *cvars, const char *var_name, cvar_t **parent, cvar_t ***link, cvar_t **prev_alpha, int neededflags) +static cvar_hash_t *Cvar_FindVarLink(cvar_state_t *cvars, const char *var_name, cvar_hash_t **parent, cvar_hash_t ***link, cvar_t **prev_alpha, int neededflags) { int hashindex; - cvar_t *var; + cvar_hash_t *hash; // use hash lookup to minimize search time hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name)); if(parent) *parent = NULL; if(prev_alpha) *prev_alpha = NULL; if(link) *link = &cvars->hashtable[hashindex]; - for (var = cvars->hashtable[hashindex];var;var = var->nextonhashchain) + for (hash = cvars->hashtable[hashindex];hash;hash = hash->next) { - if (!strcmp (var_name, var->name) && (var->flags & neededflags)) - { - if(!prev_alpha || var == cvars->vars) - return var; - - *prev_alpha = cvars->vars; - // if prev_alpha happens to become NULL then there has been some inconsistency elsewhere - // already - should I still insert '*prev_alpha &&' in the loop? - while((*prev_alpha)->next != var) - *prev_alpha = (*prev_alpha)->next; - return var; - } - if(parent) *parent = var; + if (!strcmp (var_name, hash->cvar->name) && (hash->cvar->flags & neededflags)) + goto match; + else + for (int i = 0; i < hash->cvar->aliasindex; i++) + if (!strcmp (var_name, hash->cvar->aliases[i]) && (hash->cvar->flags & neededflags)) + goto match; + if(parent) *parent = hash; } - - return NULL; + return NULL; +match: + if(!prev_alpha || hash->cvar == cvars->vars) + return hash; + + *prev_alpha = cvars->vars; + // if prev_alpha happens to become NULL then there has been some inconsistency elsewhere + // already - should I still insert '*prev_alpha &&' in the loop? + while((*prev_alpha)->next != hash->cvar) + *prev_alpha = (*prev_alpha)->next; + return hash; } /* @@ -219,7 +225,11 @@ int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, int nee for (cvar = cvars->vars; cvar; cvar = cvar->next) if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags)) h++; - + else + for(int i = 0; i < cvar->aliasindex; i++) + if (!strncasecmp(partial, cvar->aliases[i], len) && (cvar->flags & neededflags)) + h++; + return h; } @@ -246,14 +256,23 @@ const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, in for (cvar = cvars->vars; cvar; cvar = cvar->next) if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags)) buf[bpos++] = cvar->name; + else + for(int i = 0; i < cvar->aliasindex; i++) + if (!strncasecmp(partial, cvar->aliases[i], len) && (cvar->flags & neededflags)) + buf[bpos++] = cvar->aliases[i]; + buf[bpos] = NULL; return buf; } -void Cvar_PrintHelp(cvar_t *cvar, qboolean full) +void Cvar_PrintHelp(cvar_t *cvar, const char *name, qboolean full) { - Con_Printf("^3%s^7 is \"%s\" [\"%s\"] ", cvar->name, ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring); + Con_Printf("^3%s^7", name); + if (strcmp(cvar->name, name)) + Con_Printf(" (now ^3%s^7)", cvar->name); + Con_Printf(" is \"%s\" [\"%s\"] ", ((cvar->flags & CVAR_PRIVATE) ? "********"/*hunter2*/ : cvar->string), cvar->defstring); + if (full) Con_Printf("%s", cvar->description); Con_Printf("\n"); @@ -267,7 +286,13 @@ void Cvar_CompleteCvarPrint(cvar_state_t *cvars, const char *partial, int needed // Loop through the command list and print all matches for (cvar = cvars->vars; cvar; cvar = cvar->next) if (!strncasecmp(partial, cvar->name, len) && (cvar->flags & neededflags)) - Cvar_PrintHelp(cvar, true); + Cvar_PrintHelp(cvar, cvar->name, true); + else + for (int i = 0; i < cvar->aliasindex; i++) + if (!strncasecmp (partial, cvar->aliases[i], len) && (cvar->flags & neededflags)) + Cvar_PrintHelp(cvar, cvar->aliases[i], true); + + } // check if a cvar is held by some progs @@ -494,6 +519,26 @@ void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(char *)) variable->callback = callback; } +void Cvar_RegisterAlias(cvar_t *variable, const char *alias ) +{ + cvar_state_t *cvars = &cvars_all; + cvar_hash_t *hash; + int hashindex; + + variable->aliases = (char **)Mem_Realloc(zonemempool, variable->aliases, sizeof(char *) * (variable->aliasindex + 1)); + // Add to it + variable->aliases[variable->aliasindex] = (char *)Z_Malloc(strlen(alias) + 1); + memcpy(variable->aliases[variable->aliasindex], alias, strlen(alias) + 1); + variable->aliasindex++; + + // link to head of list in this hash table index + hash = (cvar_hash_t *)Z_Malloc(sizeof(cvar_hash_t)); + hashindex = CRC_Block((const unsigned char *)alias, strlen(alias)) % CVAR_HASHSIZE; + hash->next = cvars->hashtable[hashindex]; + cvars->hashtable[hashindex] = hash; + hash->cvar = variable; +} + /* ============ Cvar_RegisterVariable @@ -505,6 +550,7 @@ void Cvar_RegisterVariable (cvar_t *variable) { cvar_state_t *cvars = NULL; int hashindex; + cvar_hash_t *hash; cvar_t *current, *next, *cvar; char *oldstr; size_t alloclen; @@ -590,6 +636,7 @@ void Cvar_RegisterVariable (cvar_t *variable) memcpy ((char *)variable->defstring, oldstr, alloclen); variable->value = atof (variable->string); variable->integer = (int) variable->value; + variable->aliasindex = 0; // Mark it as not an autocvar. for (i = 0;i < PRVM_PROG_MAX;i++) @@ -607,9 +654,11 @@ void Cvar_RegisterVariable (cvar_t *variable) variable->next = next; // link to head of list in this hash table index + hash = (cvar_hash_t *)Z_Malloc(sizeof(cvar_hash_t)); hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name)) % CVAR_HASHSIZE; - variable->nextonhashchain = cvars->hashtable[hashindex]; - cvars->hashtable[hashindex] = variable; + hash->next = cvars->hashtable[hashindex]; + hash->cvar = variable; + cvars->hashtable[hashindex] = hash; } /* @@ -622,6 +671,7 @@ Adds a newly allocated variable to the variable list or sets its value. cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int flags, const char *newdescription) { int hashindex; + cvar_hash_t *hash; cvar_t *current, *next, *cvar; int i; @@ -671,6 +721,8 @@ cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int f cvar->defstring = (char *)Mem_strdup(zonemempool, value); cvar->value = atof (cvar->string); cvar->integer = (int) cvar->value; + cvar->aliases = (char **)Z_Malloc(sizeof(char **)); + memset(cvar->aliases, 0, sizeof(char *)); if(newdescription && *newdescription) cvar->description = (char *)Mem_strdup(zonemempool, newdescription); @@ -692,13 +744,27 @@ cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int f cvar->next = next; // link to head of list in this hash table index + hash = (cvar_hash_t *)Z_Malloc(sizeof(cvar_hash_t)); hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name)) % CVAR_HASHSIZE; - cvar->nextonhashchain = cvars->hashtable[hashindex]; - cvars->hashtable[hashindex] = cvar; + hash->next = cvars->hashtable[hashindex]; + cvars->hashtable[hashindex] = hash; + hash->cvar = cvar; return cvar; } +qboolean Cvar_Readonly (cvar_t *var, const char *cmd_name) +{ + if (var->flags & CVAR_READONLY) + { + if(cmd_name) + Con_Printf("%s: ",cmd_name); + Con_Printf("%s", var->name); + Con_Printf(" is read-only\n"); + return true; + } + return false; +} /* ============ @@ -713,25 +779,23 @@ qboolean Cvar_Command (cmd_state_t *cmd) cvar_t *v; // check variables - v = Cvar_FindVar(cvars, Cmd_Argv(cmd, 0), cmd->cvars_flagsmask); + v = Cvar_FindVar(cvars, Cmd_Argv(cmd, 0), (cmd->cvars_flagsmask)); if (!v) return false; // perform a variable print or set if (Cmd_Argc(cmd) == 1) { - Cvar_PrintHelp(v, true); + Cvar_PrintHelp(v, Cmd_Argv(cmd, 0), true); return true; } if (developer_extra.integer) Con_DPrint("Cvar_Command: "); - - if (v->flags & CVAR_READONLY) - { - Con_Printf("%s is read-only\n", v->name); + + if(Cvar_Readonly(v, NULL)) return true; - } + Cvar_SetQuick(v, Cmd_Argv(cmd, 1)); if (developer_extra.integer) Con_DPrint("\n"); @@ -837,15 +901,15 @@ void Cvar_RestoreInitState(cvar_state_t *cvars) Con_DPrintf("Cvar_RestoreInitState: Destroying cvar \"%s\"\n", c->name); // unlink struct from hash hashindex = CRC_Block((const unsigned char *)c->name, strlen(c->name)) % CVAR_HASHSIZE; - for (cp2 = &cvars->hashtable[hashindex];(c2 = *cp2);) + for (cp2 = &cvars->hashtable[hashindex]->cvar;(c2 = *cp2);) { if (c2 == c) { - *cp2 = c2->nextonhashchain; + *cp2 = cvars->hashtable[hashindex]->next->cvar; break; } else - cp2 = &c2->nextonhashchain; + cp2 = &cvars->hashtable[hashindex]->next->cvar; } // unlink struct from main list *cp = c->next; @@ -868,8 +932,10 @@ void Cvar_ResetToDefaults_All_f(cmd_state_t *cmd) cvar_t *var; // restore the default values of all cvars for (var = cvars->vars ; var ; var = var->next) + { if((var->flags & CVAR_NORESETTODEFAULTS) == 0) Cvar_SetQuick(var, var->defstring); + } } @@ -879,8 +945,10 @@ void Cvar_ResetToDefaults_NoSaveOnly_f(cmd_state_t *cmd) cvar_t *var; // restore the default values of all cvars for (var = cvars->vars ; var ; var = var->next) + { if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == 0) Cvar_SetQuick(var, var->defstring); + } } @@ -890,8 +958,10 @@ void Cvar_ResetToDefaults_SaveOnly_f(cmd_state_t *cmd) cvar_t *var; // restore the default values of all cvars for (var = cvars->vars ; var ; var = var->next) + { if ((var->flags & (CVAR_NORESETTODEFAULTS | CVAR_SAVE)) == CVAR_SAVE) Cvar_SetQuick(var, var->defstring); + } } @@ -909,13 +979,14 @@ void Cvar_WriteVariables (cvar_state_t *cvars, qfile_t *f) char buf1[MAX_INPUTLINE], buf2[MAX_INPUTLINE]; // don't save cvars that match their default value - for (var = cvars->vars ; var ; var = var->next) + for (var = cvars->vars ; var ; var = var->next) { if ((var->flags & CVAR_SAVE) && (strcmp(var->string, var->defstring) || ((var->flags & CVAR_ALLOCATED) && !(var->flags & CVAR_DEFAULTSET)))) { Cmd_QuoteString(buf1, sizeof(buf1), var->name, "\"\\$", false); Cmd_QuoteString(buf2, sizeof(buf2), var->string, "\"\\$", false); FS_Printf(f, "%s\"%s\" \"%s\"\n", var->flags & CVAR_ALLOCATED ? "seta " : "", buf1, buf2); } + } } @@ -954,7 +1025,7 @@ void Cvar_List_f(cmd_state_t *cmd) if (len && (ispattern ? !matchpattern_with_separator(cvar->name, partial, false, "", false) : strncmp (partial,cvar->name,len))) continue; - Cvar_PrintHelp(cvar, true); + Cvar_PrintHelp(cvar, cvar->name, true); count++; } @@ -984,11 +1055,9 @@ void Cvar_Set_f(cmd_state_t *cmd) // check if it's read-only cvar = Cvar_FindVar(cvars, Cmd_Argv(cmd, 1), ~0); - if (cvar && cvar->flags & CVAR_READONLY) - { - Con_Printf("Set: %s is read-only\n", cvar->name); - return; - } + if (cvar) + if(Cvar_Readonly(cvar,"Set")) + return; if (developer_extra.integer) Con_DPrint("Set: "); @@ -1011,11 +1080,9 @@ void Cvar_SetA_f(cmd_state_t *cmd) // check if it's read-only cvar = Cvar_FindVar(cvars, Cmd_Argv(cmd, 1), ~0); - if (cvar && cvar->flags & CVAR_READONLY) - { - Con_Printf("SetA: %s is read-only\n", cvar->name); - return; - } + if (cvar) + if(Cvar_Readonly(cvar,"SetA")) + return; if (developer_extra.integer) Con_DPrint("SetA: "); @@ -1029,7 +1096,8 @@ void Cvar_Del_f(cmd_state_t *cmd) cvar_state_t *cvars = cmd->cvars; int neededflags = ~0; int i; - cvar_t *cvar, *parent, **link, *prev; + cvar_hash_t *hash, *parent, **link; + cvar_t *cvar, *prev; if(Cmd_Argc(cmd) < 2) { @@ -1038,17 +1106,16 @@ void Cvar_Del_f(cmd_state_t *cmd) } for(i = 1; i < Cmd_Argc(cmd); ++i) { - cvar = Cvar_FindVarLink(cvars, Cmd_Argv(cmd, i), &parent, &link, &prev, neededflags); + hash = Cvar_FindVarLink(cvars, Cmd_Argv(cmd, i), &parent, &link, &prev, neededflags); + cvar = hash->cvar; + if(!cvar) { Con_Printf("%s: %s is not defined\n", Cmd_Argv(cmd, 0), Cmd_Argv(cmd, i)); continue; } - if(cvar->flags & CVAR_READONLY) - { - Con_Printf("%s: %s is read-only\n", Cmd_Argv(cmd, 0), cvar->name); + if(Cvar_Readonly(cvar, Cmd_Argv(cmd, 0))) continue; - } if(!(cvar->flags & CVAR_ALLOCATED)) { Con_Printf("%s: %s is static and cannot be deleted\n", Cmd_Argv(cmd, 0), cvar->name); @@ -1066,10 +1133,9 @@ void Cvar_Del_f(cmd_state_t *cmd) } if(parent) - parent->nextonhashchain = cvar->nextonhashchain; + parent->next = hash->next; else if(link) - *link = cvar->nextonhashchain; - + *link = hash->next; if(cvar->description != cvar_dummy_description) Z_Free((char *)cvar->description); diff --git a/cvar.h b/cvar.h index 2bbcd1dc..752c2277 100644 --- a/cvar.h +++ b/cvar.h @@ -133,6 +133,9 @@ typedef struct cvar_s void (*callback)(char *value); + char **aliases; + int aliasindex; + // values at init (for Cvar_RestoreInitState) qboolean initstate; // indicates this existed at init int initflags; @@ -148,13 +151,18 @@ typedef struct cvar_s //menucvar_t menuinfo; struct cvar_s *next; - struct cvar_s *nextonhashchain; } cvar_t; +typedef struct cvar_hash_s +{ + cvar_t *cvar; + struct cvar_hash_s *next; +} cvar_hash_t; + typedef struct cvar_state_s { cvar_t *vars; - cvar_t *hashtable[CVAR_HASHSIZE]; + cvar_hash_t *hashtable[CVAR_HASHSIZE]; } cvar_state_t; @@ -170,12 +178,17 @@ void Cvar_MenuString(cvar_t *variable, int menu); void Cvar_MenuOption(cvar_t *variable, int menu, int value[16], const char *name[16]); */ -/// registers a cvar that already has the name, string, and optionally the -/// archive elements set. + +void Cvar_RegisterAlias(cvar_t *variable, const char *alias ); + void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(char *)); +/// registers a cvar that already has the name, string, and optionally the +/// archive elements set. void Cvar_RegisterVariable(cvar_t *variable); +qboolean Cvar_Readonly (cvar_t *var, const char *cmd_name); + /// equivelant to " " typed at the console void Cvar_Set (cvar_state_t *cvars, const char *var_name, const char *value); @@ -207,7 +220,7 @@ const char *Cvar_CompleteVariable (cvar_state_t *cvars, const char *partial, int // attempts to match a partial variable name for command line completion // returns NULL if nothing fits -void Cvar_PrintHelp(cvar_t *cvar, qboolean full); +void Cvar_PrintHelp(cvar_t *cvar, const char *name, qboolean full); void Cvar_CompleteCvarPrint (cvar_state_t *cvars, const char *partial, int neededflags); diff --git a/host.c b/host.c index f9dd0c57..5c6af792 100644 --- a/host.c +++ b/host.c @@ -881,8 +881,8 @@ void Host_Main(void) framelimit = cl_maxphysicsframesperserverframe.integer; aborttime = Sys_DirtyTime() + 0.1; } - if(slowmo.value > 0 && slowmo.value < 1) - advancetime = min(advancetime, 0.1 / slowmo.value); + if(host_timescale.value > 0 && host_timescale.value < 1) + advancetime = min(advancetime, 0.1 / host_timescale.value); else advancetime = min(advancetime, 0.1); @@ -899,7 +899,7 @@ void Host_Main(void) // only advance time if not paused // the game also pauses in singleplayer when menu or console is used - sv.frametime = advancetime * slowmo.value; + sv.frametime = advancetime * host_timescale.value; if (host_framerate.value) sv.frametime = host_framerate.value; if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive || cl.csqc_paused))) @@ -980,7 +980,7 @@ void Host_Main(void) // scale playback speed of demos by slowmo cvar if (cls.demoplayback) { - clframetime *= slowmo.value; + clframetime *= host_timescale.value; // if demo playback is paused, don't advance time at all if (cls.demopaused) clframetime = 0; diff --git a/lhnet.c b/lhnet.c index 40b5148b..6bacc224 100644 --- a/lhnet.c +++ b/lhnet.c @@ -1110,7 +1110,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, continue; } #ifndef STANDALONETEST - if (cl_netlocalping.value && (realtime - cl_netlocalping.value * (1.0 / 2000.0)) < p->sentdoubletime) + if (net_fakelag.value && (realtime - net_fakelag.value * (1.0 / 2000.0)) < p->sentdoubletime) continue; #endif if (value == 0 && p->destinationport == lhnetsocket->address.port) diff --git a/menu.c b/menu.c index be6c3c01..25fd8acb 100644 --- a/menu.c +++ b/menu.c @@ -1581,7 +1581,7 @@ void M_Menu_Options_f(cmd_state_t *cmd) m_entersound = true; } -extern cvar_t slowmo; +extern cvar_t host_timescale; extern dllhandle_t jpeg_dll; extern cvar_t gl_texture_anisotropy; extern cvar_t r_textshadow; @@ -1615,8 +1615,8 @@ static void M_Menu_Options_AdjustSliders (int dir) Cvar_SetValueQuick (&cl_backspeed, 400); } } - else if (options_cursor == optnum++) Cvar_SetValueQuick(&showfps, !showfps.integer); - else if (options_cursor == optnum++) {f = !(showdate.integer && showtime.integer);Cvar_SetValueQuick(&showdate, f);Cvar_SetValueQuick(&showtime, f);} + else if (options_cursor == optnum++) Cvar_SetValueQuick(&cl_showfps, !cl_showfps.integer); + else if (options_cursor == optnum++) {f = !(cl_showdate.integer && cl_showtime.integer);Cvar_SetValueQuick(&cl_showdate, f);Cvar_SetValueQuick(&cl_showtime, f);} else if (options_cursor == optnum++) ; else if (options_cursor == optnum++) Cvar_SetValueQuick(&r_hdr_scenebrightness, bound(1, r_hdr_scenebrightness.value + dir * 0.0625, 4)); else if (options_cursor == optnum++) Cvar_SetValueQuick(&v_contrast, bound(1, v_contrast.value + dir * 0.0625, 4)); @@ -1692,8 +1692,8 @@ static void M_Options_Draw (void) M_Options_PrintCheckbox(" Invert Mouse", true, m_pitch.value < 0); M_Options_PrintSlider( " Field of View", true, scr_fov.integer, 1, 170); M_Options_PrintCheckbox(" Always Run", true, cl_forwardspeed.value > 200); - M_Options_PrintCheckbox(" Show Framerate", true, showfps.integer); - M_Options_PrintCheckbox(" Show Date and Time", true, showdate.integer && showtime.integer); + M_Options_PrintCheckbox(" Show Framerate", true, cl_showfps.integer); + M_Options_PrintCheckbox(" Show Date and Time", true, cl_showdate.integer && cl_showtime.integer); M_Options_PrintCommand( " Custom Brightness", true); M_Options_PrintSlider( " Game Brightness", true, r_hdr_scenebrightness.value, 1, 4); M_Options_PrintSlider( " Brightness", true, v_contrast.value, 1, 2); diff --git a/netconn.c b/netconn.c index b7527d74..539b98c1 100755 --- a/netconn.c +++ b/netconn.c @@ -85,9 +85,9 @@ cvar_t net_sourceaddresscheck = {CVAR_CLIENT, "net_sourceaddresscheck", "1", "co cvar_t hostname = {CVAR_SERVER | CVAR_SAVE, "hostname", "UNNAMED", "server message to show in server browser"}; cvar_t developer_networking = {CVAR_CLIENT | CVAR_SERVER, "developer_networking", "0", "prints all received and sent packets (recommended only for debugging)"}; -cvar_t cl_netlocalping = {CVAR_CLIENT, "cl_netlocalping","0", "lags local loopback connection by this much ping time (useful to play more fairly on your own server with people with higher pings)"}; -static cvar_t cl_netpacketloss_send = {CVAR_CLIENT, "cl_netpacketloss_send","0", "drops this percentage of outgoing packets, useful for testing network protocol robustness (jerky movement, prediction errors, etc)"}; -static cvar_t cl_netpacketloss_receive = {CVAR_CLIENT, "cl_netpacketloss_receive","0", "drops this percentage of incoming packets, useful for testing network protocol robustness (jerky movement, effects failing to start, sounds failing to play, etc)"}; +cvar_t net_fakelag = {CVAR_CLIENT, "net_fakelag","0", "lags local loopback connection by this much ping time (useful to play more fairly on your own server with people with higher pings)"}; +static cvar_t net_fakeloss_send = {CVAR_CLIENT, "net_fakeloss_send","0", "drops this percentage of outgoing packets, useful for testing network protocol robustness (jerky movement, prediction errors, etc)"}; +static cvar_t net_fakeloss_receive = {CVAR_CLIENT, "net_fakeloss_receive","0", "drops this percentage of incoming packets, useful for testing network protocol robustness (jerky movement, effects failing to start, sounds failing to play, etc)"}; static cvar_t net_slist_queriespersecond = {CVAR_CLIENT, "net_slist_queriespersecond", "20", "how many server information requests to send per second"}; static cvar_t net_slist_queriesperframe = {CVAR_CLIENT, "net_slist_queriesperframe", "4", "maximum number of server information requests to send each rendered frame (guards against low framerates causing problems)"}; static cvar_t net_slist_timeout = {CVAR_CLIENT, "net_slist_timeout", "4", "how long to listen for a server information response before giving up"}; @@ -618,9 +618,9 @@ int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddres Thread_UnlockMutex(netconn_mutex); if (length == 0) return 0; - if (cl_netpacketloss_receive.integer) + if (net_fakeloss_receive.integer) for (i = 0;i < cl_numsockets;i++) - if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss_receive.integer) + if (cl_sockets[i] == mysocket && (rand() % 100) < net_fakeloss_receive.integer) return 0; if (developer_networking.integer) { @@ -642,9 +642,9 @@ int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const l { int ret; int i; - if (cl_netpacketloss_send.integer) + if (net_fakeloss_send.integer) for (i = 0;i < cl_numsockets;i++) - if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss_send.integer) + if (cl_sockets[i] == mysocket && (rand() % 100) < net_fakeloss_send.integer) return length; if (mysocket->address.addresstype == LHNETADDRESSTYPE_LOOP && netconn_mutex) Thread_LockMutex(netconn_mutex); @@ -3899,9 +3899,12 @@ void NetConn_Init(void) Cvar_RegisterVariable(&net_challengefloodblockingtimeout); Cvar_RegisterVariable(&net_getstatusfloodblockingtimeout); Cvar_RegisterVariable(&net_sourceaddresscheck); - Cvar_RegisterVariable(&cl_netlocalping); - Cvar_RegisterVariable(&cl_netpacketloss_send); - Cvar_RegisterVariable(&cl_netpacketloss_receive); + Cvar_RegisterVariable(&net_fakelag); + Cvar_RegisterVariable(&net_fakeloss_send); + Cvar_RegisterVariable(&net_fakeloss_receive); + Cvar_RegisterAlias(&net_fakelag, "cl_netlocalping"); + Cvar_RegisterAlias(&net_fakeloss_send, "cl_netpacketloss_send"); + Cvar_RegisterAlias(&net_fakeloss_receive, "cl_netpacketloss_receive"); Cvar_RegisterVariable(&hostname); Cvar_RegisterVariable(&developer_networking); Cvar_RegisterVariable(&cl_netport); diff --git a/netconn.h b/netconn.h index 6f0d762e..7120c531 100755 --- a/netconn.h +++ b/netconn.h @@ -421,7 +421,7 @@ extern char sv_readstring[MAX_INPUTLINE]; extern cvar_t sv_public; -extern cvar_t cl_netlocalping; +extern cvar_t net_fakelag; extern cvar_t cl_netport; extern cvar_t sv_netport; diff --git a/prvm_edict.c b/prvm_edict.c index c027ec71..5e4111b7 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1165,11 +1165,10 @@ static void PRVM_ED_EdictGet_f(cmd_state_t *cmd) if(Cmd_Argc(cmd) == 5) { cvar_t *cvar = Cvar_FindVar(cmd->cvars, Cmd_Argv(cmd, 4), cmd->cvars_flagsmask); - if (cvar && cvar->flags & CVAR_READONLY) - { - Con_Printf("prvm_edictget: %s is read-only\n", cvar->name); - goto fail; - } + if (cvar) + if(Cvar_Readonly(cvar, "prvm_edictget")) + goto fail; + Cvar_Get(cmd->cvars, Cmd_Argv(cmd, 4), s, cmd->cvars_flagsmask, NULL); } else @@ -1208,11 +1207,9 @@ static void PRVM_ED_GlobalGet_f(cmd_state_t *cmd) if(Cmd_Argc(cmd) == 4) { cvar_t *cvar = Cvar_FindVar(cmd->cvars, Cmd_Argv(cmd, 3), cmd->cvars_flagsmask); - if (cvar && cvar->flags & CVAR_READONLY) - { - Con_Printf("prvm_globalget: %s is read-only\n", cvar->name); - goto fail; - } + if (cvar) + if(Cvar_Readonly(cvar, "prvm_globalget")) + goto fail; Cvar_Get(cmd->cvars, Cmd_Argv(cmd, 3), s, cmd->cvars_flagsmask, NULL); } else diff --git a/sbar.c b/sbar.c index 010925b7..3ea32ee4 100644 --- a/sbar.c +++ b/sbar.c @@ -85,16 +85,17 @@ cachepic_t *sb_complete; cachepic_t *sb_inter; cachepic_t *sb_finale; -cvar_t showfps = {CVAR_CLIENT | CVAR_SAVE, "showfps", "0", "shows your rendered fps (frames per second)"}; -cvar_t showsound = {CVAR_CLIENT | CVAR_SAVE, "showsound", "0", "shows number of active sound sources, sound latency, and other statistics"}; -cvar_t showblur = {CVAR_CLIENT | CVAR_SAVE, "showblur", "0", "shows the current alpha level of motionblur"}; -cvar_t showspeed = {CVAR_CLIENT | CVAR_SAVE, "showspeed", "0", "shows your current speed (qu per second); number selects unit: 1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots"}; -cvar_t showtopspeed = {CVAR_CLIENT | CVAR_SAVE, "showtopspeed", "0", "shows your top speed (kept on screen for max 3 seconds); value -1 takes over the unit from showspeed, otherwise it's an unit number just like in showspeed"}; -cvar_t showtime = {CVAR_CLIENT | CVAR_SAVE, "showtime", "0", "shows current time of day (useful on screenshots)"}; -cvar_t showtime_format = {CVAR_CLIENT | CVAR_SAVE, "showtime_format", "%H:%M:%S", "format string for time of day"}; -cvar_t showdate = {CVAR_CLIENT | CVAR_SAVE, "showdate", "0", "shows current date (useful on screenshots)"}; -cvar_t showdate_format = {CVAR_CLIENT | CVAR_SAVE, "showdate_format", "%Y-%m-%d", "format string for date"}; -cvar_t showtex = {CVAR_CLIENT, "showtex", "0", "shows the name of the texture on the crosshair (for map debugging)"}; +cvar_t cl_showfps = {CVAR_CLIENT | CVAR_SAVE, "cl_showfps", "0", "shows your rendered fps (frames per second)"}; +cvar_t cl_showsound = {CVAR_CLIENT | CVAR_SAVE, "cl_showsound", "0", "shows number of active sound sources, sound latency, and other statistics"}; +cvar_t cl_showblur = {CVAR_CLIENT | CVAR_SAVE, "cl_showblur", "0", "shows the current alpha level of motionblur"}; +cvar_t cl_showspeed = {CVAR_CLIENT | CVAR_SAVE, "cl_showspeed", "0", "shows your current speed (qu per second); number selects unit: 1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots"}; +cvar_t cl_showtopspeed = {CVAR_CLIENT | CVAR_SAVE, "cl_showtopspeed", "0", "shows your top speed (kept on screen for max 3 seconds); value -1 takes over the unit from cl_showspeed, otherwise it's an unit number just like in cl_showspeed"}; +cvar_t cl_showtime = {CVAR_CLIENT | CVAR_SAVE, "cl_showtime", "0", "shows current time of day (useful on screenshots)"}; +cvar_t cl_showtime_format = {CVAR_CLIENT | CVAR_SAVE, "cl_showtime_format", "%H:%M:%S", "format string for time of day"}; +cvar_t cl_showdate = {CVAR_CLIENT | CVAR_SAVE, "cl_showdate", "0", "shows current date (useful on screenshots)"}; +cvar_t cl_showdate_format = {CVAR_CLIENT | CVAR_SAVE, "cl_showdate_format", "%Y-%m-%d", "format string for date"}; +cvar_t cl_showtex = {CVAR_CLIENT, "cl_showtex", "0", "shows the name of the texture on the crosshair (for map debugging)"}; + cvar_t sbar_alpha_bg = {CVAR_CLIENT | CVAR_SAVE, "sbar_alpha_bg", "0.4", "opacity value of the statusbar background image"}; cvar_t sbar_alpha_fg = {CVAR_CLIENT | CVAR_SAVE, "sbar_alpha_fg", "1", "opacity value of the statusbar weapon/item icons and numbers"}; cvar_t sbar_hudselector = {CVAR_CLIENT | CVAR_SAVE, "sbar_hudselector", "0", "selects which of the builtin hud layouts to use (meaning is somewhat dependent on gamemode, so nexuiz has a very different set of hud layouts than quake for example)"}; @@ -362,16 +363,28 @@ void Sbar_Init (void) Cmd_AddCommand(&cmd_client, "+showscores", Sbar_ShowScores_f, "show scoreboard"); Cmd_AddCommand(&cmd_client, "-showscores", Sbar_DontShowScores_f, "hide scoreboard"); } - Cvar_RegisterVariable(&showfps); - Cvar_RegisterVariable(&showsound); - Cvar_RegisterVariable(&showblur); - Cvar_RegisterVariable(&showspeed); - Cvar_RegisterVariable(&showtopspeed); - Cvar_RegisterVariable(&showtime); - Cvar_RegisterVariable(&showtime_format); - Cvar_RegisterVariable(&showdate); - Cvar_RegisterVariable(&showdate_format); - Cvar_RegisterVariable(&showtex); + Cvar_RegisterVariable(&cl_showfps); + Cvar_RegisterVariable(&cl_showsound); + Cvar_RegisterVariable(&cl_showblur); + Cvar_RegisterVariable(&cl_showspeed); + Cvar_RegisterVariable(&cl_showtopspeed); + Cvar_RegisterVariable(&cl_showtime); + Cvar_RegisterVariable(&cl_showtime_format); + Cvar_RegisterVariable(&cl_showdate); + Cvar_RegisterVariable(&cl_showdate_format); + Cvar_RegisterVariable(&cl_showtex); + + Cvar_RegisterAlias(&cl_showfps, "showfps"); + Cvar_RegisterAlias(&cl_showsound, "showsound"); + Cvar_RegisterAlias(&cl_showblur, "showblur"); + Cvar_RegisterAlias(&cl_showspeed, "showspeed"); + Cvar_RegisterAlias(&cl_showtopspeed, "showtopspeed"); + Cvar_RegisterAlias(&cl_showtime, "showtime"); + Cvar_RegisterAlias(&cl_showtime_format, "showtime_format"); + Cvar_RegisterAlias(&cl_showdate, "showdate"); + Cvar_RegisterAlias(&cl_showdate_format, "showdate_format"); + Cvar_RegisterAlias(&cl_showtex, "showtex"); + Cvar_RegisterVariable(&sbar_alpha_bg); Cvar_RegisterVariable(&sbar_alpha_fg); Cvar_RegisterVariable(&sbar_hudselector); @@ -1035,7 +1048,7 @@ time_t topxy_time = 0; static void get_showspeed_unit(int unitnumber, double *conversion_factor, const char **unit) { if(unitnumber < 0) - unitnumber = showspeed.integer; + unitnumber = cl_showspeed.integer; switch(unitnumber) { default: @@ -1121,10 +1134,10 @@ void Sbar_ShowFPS(void) topspeedstring[0] = 0; texstring[0] = 0; entstring[0] = 0; - if (showfps.integer) + if (cl_showfps.integer) { red = (showfps_framerate < 1.0f); - if(showfps.integer == 2) + if(cl_showfps.integer == 2) dpsnprintf(fpsstring, sizeof(fpsstring), "%7.3f mspf", (1000.0 / showfps_framerate)); else if (red) dpsnprintf(fpsstring, sizeof(fpsstring), "%4i spf", (int)(1.0 / showfps_framerate + 0.5)); @@ -1139,42 +1152,42 @@ void Sbar_ShowFPS(void) fps_strings++; } } - if (showtime.integer) + if (cl_showtime.integer) { - strlcpy(timestring, Sys_TimeString(showtime_format.string), sizeof(timestring)); + strlcpy(timestring, Sys_TimeString(cl_showtime_format.string), sizeof(timestring)); fps_strings++; } - if (showdate.integer) + if (cl_showdate.integer) { - strlcpy(datestring, Sys_TimeString(showdate_format.string), sizeof(datestring)); + strlcpy(datestring, Sys_TimeString(cl_showdate_format.string), sizeof(datestring)); fps_strings++; } - if (showblur.integer) + if (cl_showblur.integer) { dpsnprintf(blurstring, sizeof(blurstring), "%3i%% blur", (int)(cl.motionbluralpha * 100)); fps_strings++; } - if (showsound.integer) + if (cl_showsound.integer) { dpsnprintf(soundstring, sizeof(soundstring), "%4i/4%i at %3ims", cls.soundstats.mixedsounds, cls.soundstats.totalsounds, cls.soundstats.latency_milliseconds); fps_strings++; } - if (showspeed.integer || showtopspeed.integer) + if (cl_showspeed.integer || cl_showtopspeed.integer) { double speed, speedxy, f; const char *unit; speed = VectorLength(cl.movement_velocity); speedxy = sqrt(cl.movement_velocity[0] * cl.movement_velocity[0] + cl.movement_velocity[1] * cl.movement_velocity[1]); - if (showspeed.integer) + if (cl_showspeed.integer) { - get_showspeed_unit(showspeed.integer, &f, &unit); + get_showspeed_unit(cl_showspeed.integer, &f, &unit); dpsnprintf(speedstring, sizeof(speedstring), "%.0f (%.0f) %s", f*speed, f*speedxy, unit); fps_strings++; } - if (showtopspeed.integer) + if (cl_showtopspeed.integer) { qboolean topspeed_latched = false, topspeedxy_latched = false; - get_showspeed_unit(showtopspeed.integer, &f, &unit); + get_showspeed_unit(cl_showtopspeed.integer, &f, &unit); if (speed >= topspeed || current_time - top_time > 3) { topspeed = speed; @@ -1197,7 +1210,7 @@ void Sbar_ShowFPS(void) fps_strings++; } } - if (showtex.integer) + if (cl_showtex.integer) { vec3_t org; vec3_t dest; diff --git a/screen.h b/screen.h index 8a9080c7..55b0e3f0 100644 --- a/screen.h +++ b/screen.h @@ -44,9 +44,9 @@ extern int sb_lines; extern cvar_t scr_viewsize; extern cvar_t scr_fov; -extern cvar_t showfps; -extern cvar_t showtime; -extern cvar_t showdate; +extern cvar_t cl_showfps; +extern cvar_t cl_showtime; +extern cvar_t cl_showdate; extern cvar_t crosshair; extern cvar_t crosshair_size; diff --git a/server.h b/server.h index c84fab1d..46c12463 100644 --- a/server.h +++ b/server.h @@ -404,7 +404,7 @@ extern cvar_t scratch2; extern cvar_t scratch3; extern cvar_t scratch4; extern cvar_t skill; -extern cvar_t slowmo; +extern cvar_t host_timescale; extern cvar_t sv_accelerate; extern cvar_t sv_aim; extern cvar_t sv_airaccel_qw; diff --git a/sv_main.c b/sv_main.c index 0a0dd982..8ac96a11 100644 --- a/sv_main.c +++ b/sv_main.c @@ -47,7 +47,7 @@ cvar_t pausable = {CVAR_SERVER, "pausable","1", "allow players to pause or not ( cvar_t pr_checkextension = {CVAR_SERVER | CVAR_READONLY, "pr_checkextension", "1", "indicates to QuakeC that the standard quakec extensions system is available (if 0, quakec should not attempt to use extensions)"}; cvar_t samelevel = {CVAR_SERVER | CVAR_NOTIFY, "samelevel","0", "repeats same level if level ends (due to timelimit or someone hitting an exit)"}; cvar_t skill = {CVAR_SERVER, "skill","1", "difficulty level of game, affects monster layouts in levels, 0 = easy, 1 = normal, 2 = hard, 3 = nightmare (same layout as hard but monsters fire twice)"}; -cvar_t slowmo = {CVAR_CLIENT | CVAR_SERVER, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"}; +cvar_t host_timescale = {CVAR_CLIENT | CVAR_SERVER, "host_timescale", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"}; cvar_t sv_accelerate = {CVAR_SERVER, "sv_accelerate", "10", "rate at which a player accelerates to sv_maxspeed"}; cvar_t sv_aim = {CVAR_SERVER | CVAR_SAVE, "sv_aim", "2", "maximum cosine angle for quake's vertical autoaim, a value above 1 completely disables the autoaim, quake used 0.93"}; @@ -204,7 +204,7 @@ server_static_t svs; mempool_t *sv_mempool = NULL; -extern cvar_t slowmo; +extern cvar_t host_timescale; extern float scr_centertime_off; // MUST match effectnameindex_t in client.h @@ -413,7 +413,7 @@ prvm_required_field_t sv_reqglobals[] = #undef PRVM_DECLARE_function }; -static void SV_Slowmo_c(char *string) +static void Host_Timescale_c(char *string) { double value; value = atof(string); @@ -473,8 +473,10 @@ void SV_Init (void) Cvar_RegisterVariable (&pr_checkextension); Cvar_RegisterVariable (&samelevel); Cvar_RegisterVariable (&skill); - Cvar_RegisterVariable (&slowmo); - Cvar_RegisterCallback (&slowmo, SV_Slowmo_c); + Cvar_RegisterVariable (&host_timescale); + Cvar_RegisterCallback (&host_timescale, Host_Timescale_c); + Cvar_RegisterAlias (&host_timescale, "slowmo"); + Cvar_RegisterAlias (&host_timescale, "timescale"); Cvar_RegisterVariable (&sv_accelerate); Cvar_RegisterVariable (&sv_aim); Cvar_RegisterVariable (&sv_airaccel_qw); @@ -2125,7 +2127,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t | (sv_gameplayfix_gravityunaffectedbyticrate.integer ? MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE : 0) ; statsf[STAT_MOVEVARS_TICRATE] = sys_ticrate.value; - statsf[STAT_MOVEVARS_TIMESCALE] = slowmo.value; + statsf[STAT_MOVEVARS_TIMESCALE] = host_timescale.value; statsf[STAT_MOVEVARS_GRAVITY] = sv_gravity.value; statsf[STAT_MOVEVARS_STOPSPEED] = sv_stopspeed.value; statsf[STAT_MOVEVARS_MAXSPEED] = sv_maxspeed.value; @@ -4040,7 +4042,7 @@ static int SV_ThreadFunc(void *voiddata) // only advance time if not paused // the game also pauses in singleplayer when menu or console is used - sv.frametime = advancetime * slowmo.value; + sv.frametime = advancetime * host_timescale.value; if (host_framerate.value) sv.frametime = host_framerate.value; if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive || cl.csqc_paused))) -- 2.39.2