]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cvar.c
A minor removal of a few pieces of dead code. Nothing major. This is
[xonotic/darkplaces.git] / cvar.c
diff --git a/cvar.c b/cvar.c
index d38c5ba9eeda565bf22dc6b3c351e0521855c5d5..152a86aee4f52446aa95dd683d5b5484acfb4b09 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -144,7 +144,7 @@ Cvar_CompleteBuildList (char *partial)
        char    **buf;
 
        len = strlen(partial);
        char    **buf;
 
        len = strlen(partial);
-       buf = qmalloc(sizeofbuf + sizeof (char *));
+       buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (char *));
        // Loop through the alias list and print all matches
        for (cvar = cvar_vars; cvar; cvar = cvar->next)
                if (!strncasecmp(partial, cvar->name, len))
        // Loop through the alias list and print all matches
        for (cvar = cvar_vars; cvar; cvar = cvar->next)
                if (!strncasecmp(partial, cvar->name, len))
@@ -159,25 +159,31 @@ Cvar_CompleteBuildList (char *partial)
 Cvar_Set
 ============
 */
 Cvar_Set
 ============
 */
-void Cvar_Set (char *var_name, char *value)
+void Cvar_SetQuick (cvar_t *var, char *value)
 {
 {
-       cvar_t  *var;
        qboolean changed;
 
        qboolean changed;
 
-       var = Cvar_FindVar (var_name);
-       if (!var)
-       {       // there is an error in C code if this happens
-               Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
+       if (var == NULL)
+       {
+               Con_Printf("Cvar_SetQuick: var == NULL\n");
                return;
        }
 
        changed = strcmp(var->string, value);
                return;
        }
 
        changed = strcmp(var->string, value);
+       // LordHavoc: don't reallocate when there is no change
+       if (!changed)
+               return;
 
 
-       Z_Free (var->string);   // free the old value string
+       // LordHavoc: don't reallocate when the buffer is the same size
+       if (!var->string || strlen(var->string) != strlen(value))
+       {
+               Z_Free (var->string);   // free the old value string
 
 
-       var->string = Z_Malloc (strlen(value)+1);
+               var->string = Z_Malloc (strlen(value)+1);
+       }
        strcpy (var->string, value);
        var->value = atof (var->string);
        strcpy (var->string, value);
        var->value = atof (var->string);
+       var->integer = (int) var->value;
        if ((var->flags & CVAR_NOTIFY) && changed)
        {
                if (sv.active)
        if ((var->flags & CVAR_NOTIFY) && changed)
        {
                if (sv.active)
@@ -185,11 +191,34 @@ void Cvar_Set (char *var_name, char *value)
        }
 }
 
        }
 }
 
+void Cvar_Set (char *var_name, char *value)
+{
+       cvar_t *var;
+       var = Cvar_FindVar (var_name);
+       if (var == NULL)
+       {
+               // there is an error in C code if this happens
+               Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
+               return;
+       }
+
+       Cvar_SetQuick(var, value);
+}
+
 /*
 ============
 Cvar_SetValue
 ============
 */
 /*
 ============
 Cvar_SetValue
 ============
 */
+void Cvar_SetValueQuick (cvar_t *var, float value)
+{
+       char    val[32];
+
+       // LordHavoc: changed from %f to %g to use shortest representation
+       sprintf (val, "%g",value);
+       Cvar_SetQuick (var, val);
+}
+
 void Cvar_SetValue (char *var_name, float value)
 {
        char    val[32];
 void Cvar_SetValue (char *var_name, float value)
 {
        char    val[32];
@@ -229,6 +258,7 @@ void Cvar_RegisterVariable (cvar_t *variable)
        variable->string = Z_Malloc (strlen(variable->string)+1);
        strcpy (variable->string, oldstr);
        variable->value = atof (variable->string);
        variable->string = Z_Malloc (strlen(variable->string)+1);
        strcpy (variable->string, oldstr);
        variable->value = atof (variable->string);
+       variable->integer = (int) variable->value;
 
 // link the variable in
        variable->next = cvar_vars;
 
 // link the variable in
        variable->next = cvar_vars;
@@ -318,3 +348,4 @@ void Cvar_List_f (void)
        Con_Printf ("\n");
 }
 // 2000-01-09 CvarList command by Maddes
        Con_Printf ("\n");
 }
 // 2000-01-09 CvarList command by Maddes
+