2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 typedef struct cmd_state_s cmd_state_t;
27 cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly
30 it is sufficient to initialize a cvar_t with just the first two fields, or
31 you can add a ,true flag for variables that you want saved to the configuration
32 file when the game is quit:
34 cvar_t r_draworder = {"r_draworder","1"};
35 cvar_t scr_screensize = {"screensize","1",true};
37 Cvars must be registered before use, or they will have a 0 value instead of the float interpretation of the string. Generally, all cvar_t declarations should be registered in the apropriate init function before any console commands are executed:
38 Cvar_RegisterVariable (&host_framerate);
41 C code usually just references a cvar in place:
42 if ( r_draworder.value )
44 It could optionally ask for the value to be looked up for a string name:
45 if (Cvar_VariableValue ("r_draworder"))
47 Interpreted prog code can access cvars with the cvar(name) or
48 cvar_set (name, value) internal functions:
49 teamplay = cvar("teamplay");
50 cvar_set ("registered", "1");
52 The user can access cvars from the console in two ways:
53 r_draworder prints the current value
54 r_draworder 0 sets the current value to 0
55 Cvars are restricted from having the same names as commands to keep this
56 interface from being ambiguous.
69 const char *description;
74 const char *defstring;
76 void (*callback)(struct cvar_s *var);
77 qbool ignore_callback;
82 // values at init (for Cvar_RestoreInitState)
83 qbool initstate; // indicates this existed at init
85 const char *initstring;
86 const char *initdescription;
90 const char *initdefstring;
92 int globaldefindex[3];
93 int globaldefindex_stringno[3];
98 typedef struct cvar_hash_s
101 struct cvar_hash_s *next;
104 typedef struct cvar_state_s
107 cvar_hash_t *hashtable[CVAR_HASHSIZE];
111 extern cvar_state_t cvars_all;
112 extern cvar_state_t cvars_null; // used by cmd_serverfromclient which intentionally has no cvars available
114 void Cvar_RegisterAlias(cvar_t *variable, const char *alias );
116 void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *));
118 /// registers a cvar that already has the name, string, and optionally the
119 /// archive elements set.
120 void Cvar_RegisterVariable(cvar_t *variable);
122 qbool Cvar_Readonly (cvar_t *var, const char *cmd_name);
124 /// equivelant to "<name> <variable>" typed at the console
125 void Cvar_Set (cvar_state_t *cvars, const char *var_name, const char *value);
126 void Cvar_Set_NoCallback (cvar_t *var, const char *value);
128 /// expands value to a string and calls Cvar_Set
129 void Cvar_SetValue (cvar_state_t *cvars, const char *var_name, float value);
131 void Cvar_SetQuick (cvar_t *var, const char *value);
132 void Cvar_SetValueQuick (cvar_t *var, float value);
134 float Cvar_VariableValueOr (cvar_state_t *cvars, const char *var_name, float def, int neededflags);
135 // returns def if not defined
137 float Cvar_VariableValue (cvar_state_t *cvars, const char *var_name, int neededflags);
138 // returns 0 if not defined or non numeric
140 const char *Cvar_VariableStringOr (cvar_state_t *cvars, const char *var_name, const char *def, int neededflags);
141 // returns def if not defined
143 const char *Cvar_VariableString (cvar_state_t *cvars, const char *var_name, int neededflags);
144 // returns an empty string if not defined
146 const char *Cvar_VariableDefString (cvar_state_t *cvars, const char *var_name, int neededflags);
147 // returns an empty string if not defined
149 const char *Cvar_VariableDescription (cvar_state_t *cvars, const char *var_name, int neededflags);
150 // returns an empty string if not defined
152 const char *Cvar_CompleteVariable (cvar_state_t *cvars, const char *partial, int neededflags);
153 // attempts to match a partial variable name for command line completion
154 // returns NULL if nothing fits
156 void Cvar_PrintHelp(cvar_t *cvar, const char *name, qbool full);
158 void Cvar_CompleteCvarPrint (cvar_state_t *cvars, const char *partial, int neededflags);
160 qbool Cvar_Command (cmd_state_t *cmd);
161 // called by Cmd_ExecuteString when Cmd_Argv(cmd, 0) doesn't match a known
162 // command. Returns true if the command was a variable reference that
163 // was handled. (print or change)
165 void Cvar_SaveInitState(cvar_state_t *cvars);
166 void Cvar_RestoreInitState(cvar_state_t *cvars);
168 void Cvar_UnlockDefaults(cmd_state_t *cmd);
169 void Cvar_LockDefaults_f(cmd_state_t *cmd);
170 void Cvar_ResetToDefaults_All_f(cmd_state_t *cmd);
171 void Cvar_ResetToDefaults_NoSaveOnly_f(cmd_state_t *cmd);
172 void Cvar_ResetToDefaults_SaveOnly_f(cmd_state_t *cmd);
174 void Cvar_WriteVariables (cvar_state_t *cvars, qfile_t *f);
175 // Writes lines containing "set variable value" for all variables
176 // with the archive flag set to true.
178 cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, int neededflags);
179 cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, int neededflags);
181 int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, int neededflags);
182 const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, int neededflags);
183 // Added by EvilTypeGuy - functions for tab completion system
184 // Thanks to Fett erich@heintz.com
187 /// Prints a list of Cvars including a count of them to the user console
188 /// Referenced in cmd.c in Cmd_Init hence it's inclusion here.
189 /// Added by EvilTypeGuy eviltypeguy@qeradiant.com
190 /// Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
191 void Cvar_List_f(cmd_state_t *cmd);
193 void Cvar_Set_f(cmd_state_t *cmd);
194 void Cvar_SetA_f(cmd_state_t *cmd);
195 void Cvar_Del_f(cmd_state_t *cmd);
196 // commands to create new cvars (or set existing ones)
197 // seta creates an archived cvar (saved to config)
199 /// allocates a cvar by name and returns its address,
200 /// or merely sets its value if it already exists.
201 cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int flags, const char *newdescription);
203 extern const char *cvar_dummy_description; // ALWAYS the same pointer
205 void Cvar_UpdateAllAutoCvars(cvar_state_t *cvars); // updates ALL autocvars of the active prog to the cvar values (savegame loading)
207 #ifdef FILLALLCVARSWITHRUBBISH
208 void Cvar_FillAll_f(cmd_state_t *cmd);
209 #endif /* FILLALLCVARSWITHRUBBISH */