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.
24 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
27 it is sufficient to initialize a cvar_t with just the first two fields, or
28 you can add a ,true flag for variables that you want saved to the configuration
29 file when the game is quit:
31 cvar_t r_draworder = {"r_draworder","1"};
32 cvar_t scr_screensize = {"screensize","1",true};
34 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:
35 Cvar_RegisterVariable (&host_framerate);
38 C code usually just references a cvar in place:
39 if ( r_draworder.value )
41 It could optionally ask for the value to be looked up for a string name:
42 if (Cvar_VariableValue ("r_draworder"))
44 Interpreted prog code can access cvars with the cvar(name) or
45 cvar_set (name, value) internal functions:
46 teamplay = cvar("teamplay");
47 cvar_set ("registered", "1");
49 The user can access cvars from the console in two ways:
50 r_draworder prints the current value
51 r_draworder 0 sets the current value to 0
52 Cvars are restricted from having the same names as commands to keep this
53 interface from being ambiguous.
63 #define CVAR_READONLY 4
64 #define CVAR_SERVERINFO 8
65 #define CVAR_USERINFO 16
66 // used to determine if flags is valid
67 #define CVAR_MAXFLAGSVAL 31
68 // for internal use only!
69 #define CVAR_DEFAULTSET (1<<30)
70 #define CVAR_ALLOCATED (1<<31)
73 // type of a cvar for menu purposes
74 #define CVARMENUTYPE_FLOAT 1
75 #define CVARMENUTYPE_INTEGER 2
76 #define CVARMENUTYPE_SLIDER 3
77 #define CVARMENUTYPE_BOOL 4
78 #define CVARMENUTYPE_STRING 5
79 #define CVARMENUTYPE_OPTION 6
81 // which menu to put a cvar in
82 #define CVARMENU_GRAPHICS 1
83 #define CVARMENU_SOUND 2
84 #define CVARMENU_INPUT 3
85 #define CVARMENU_NETWORK 4
86 #define CVARMENU_SERVER 5
88 #define MAX_CVAROPTIONS 16
90 typedef struct cvaroption_s
97 typedef struct menucvar_s
100 float valuemin, valuemax, valuestep;
102 cvaroption_t optionlist[MAX_CVAROPTIONS];
107 typedef struct cvar_s
121 //menucvar_t menuinfo;
126 void Cvar_MenuSlider(cvar_t *variable, int menu, float slider_min, float slider_max, float slider_step);
127 void Cvar_MenuBool(cvar_t *variable, int menu, const char *name_false, const char *name_true);
128 void Cvar_MenuFloat(cvar_t *variable, int menu, float range_min, float range_max);
129 void Cvar_MenuInteger(cvar_t *variable, int menu, int range_min, int range_max);
130 void Cvar_MenuString(cvar_t *variable, int menu);
131 void Cvar_MenuOption(cvar_t *variable, int menu, int value[16], const char *name[16]);
134 void Cvar_RegisterVariable (cvar_t *variable);
135 // registers a cvar that already has the name, string, and optionally the
136 // archive elements set.
138 void Cvar_Set (const char *var_name, const char *value);
139 // equivelant to "<name> <variable>" typed at the console
141 void Cvar_SetValue (const char *var_name, float value);
142 // expands value to a string and calls Cvar_Set
144 void Cvar_SetQuick (cvar_t *var, const char *value);
145 void Cvar_SetValueQuick (cvar_t *var, float value);
147 float Cvar_VariableValue (const char *var_name);
148 // returns 0 if not defined or non numeric
150 const char *Cvar_VariableString (const char *var_name);
151 // returns an empty string if not defined
153 const char *Cvar_VariableDefString (const char *var_name);
154 // returns an empty string if not defined
156 const char *Cvar_CompleteVariable (const char *partial);
157 // attempts to match a partial variable name for command line completion
158 // returns NULL if nothing fits
160 void Cvar_CompleteCvarPrint (const char *partial);
162 qboolean Cvar_Command (void);
163 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
164 // command. Returns true if the command was a variable reference that
165 // was handled. (print or change)
167 void Cvar_WriteVariables (qfile_t *f);
168 // Writes lines containing "set variable value" for all variables
169 // with the archive flag set to true.
171 cvar_t *Cvar_FindVar (const char *var_name);
172 cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags);
174 int Cvar_CompleteCountPossible (const char *partial);
175 const char **Cvar_CompleteBuildList (const char *partial);
176 // Added by EvilTypeGuy - functions for tab completion system
177 // Thanks to Fett erich@heintz.com
180 void Cvar_List_f (void);
181 // Prints a list of Cvars including a count of them to the user console
182 // Referenced in cmd.c in Cmd_Init hence it's inclusion here
183 // Added by EvilTypeGuy eviltypeguy@qeradiant.com
184 // Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
186 void Cvar_Set_f (void);
187 void Cvar_SetA_f (void);
188 // commands to create new cvars (or set existing ones)
189 // seta creates an archived cvar (saved to config)
191 cvar_t *Cvar_Get (const char *name, const char *value, int flags);
192 // allocates a cvar by name and returns its address,
193 // or merely sets its value if it already exists.