add Cvar_Init, which adds the "set" command to create dynamic cvars

This commit is contained in:
Bill Currie 2000-02-15 11:42:12 +00:00
parent 35fb941db1
commit b099c73cc4
2 changed files with 35 additions and 0 deletions

View file

@ -287,3 +287,35 @@ void Cvar_WriteVariables (QFile *f)
Qprintf (f, "%s \"%s\"\n", var->name, var->string);
}
void Cvar_Set_f(void)
{
cvar_t *var;
char *value;
char *var_name;
if (Cmd_Argc() != 3)
{
Con_Printf ("usage: set <cvar> <value>\n");
return;
}
var_name = Cmd_Argv (1);
value = Cmd_Argv (2);
var = Cvar_FindVar (var_name);
if (var)
{
Cvar_Set (var->name, value);
}
else
{
var = (cvar_t*)calloc(1,sizeof(cvar_t));
var->heap = 1;
var->name = strdup (var_name);
var->string = value;
Cvar_RegisterVariable (var);
}
}
void Cvar_Init()
{
Cmd_AddCommand ("set", Cvar_Set_f);
}

View file

@ -66,6 +66,7 @@ typedef struct cvar_s
qboolean archive; // set to true to cause it to be saved to vars.rc
qboolean info; // added to serverinfo or userinfo when changed
qboolean server; // notifies players when changed (UQUAKE)
qboolean heap; // allocated off the heap, safe to free
float value;
struct cvar_s *next;
} cvar_t;
@ -102,5 +103,7 @@ void Cvar_WriteVariables (QFile *f);
cvar_t *Cvar_FindVar (char *var_name);
void Cvar_Init();
extern cvar_t *cvar_vars;
#endif // _CVAR_H