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))
Cvar_Set
============
*/
-void Cvar_Set (char *var_name, char *value)
+void Cvar_SetQuick (cvar_t *var, char *value)
{
- cvar_t *var;
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);
+ // 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);
+ var->integer = (int) var->value;
if ((var->flags & CVAR_NOTIFY) && changed)
{
if (sv.active)
}
}
+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
============
*/
+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];
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;
Con_Printf ("\n");
}
// 2000-01-09 CvarList command by Maddes
+