]> git.xonotic.org Git - xonotic/darkplaces.git/blob - cvar.h
Split the global cmd interpreter into 4 separate ones for specific uses (client conso...
[xonotic/darkplaces.git] / cvar.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // cvar.h
21
22 struct cmd_state_s;
23 typedef struct cmd_state_s cmd_state_t;
24
25 /*
26
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
28 in C code.
29
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:
33
34 cvar_t  r_draworder = {"r_draworder","1"};
35 cvar_t  scr_screensize = {"screensize","1",true};
36
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);
39
40
41 C code usually just references a cvar in place:
42 if ( r_draworder.value )
43
44 It could optionally ask for the value to be looked up for a string name:
45 if (Cvar_VariableValue ("r_draworder"))
46
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");
51
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.
57 */
58
59 #ifndef CVAR_H
60 #define CVAR_H
61
62 // cvar flags
63
64 #define CVAR_SAVE 1
65 #define CVAR_NOTIFY 2
66 #define CVAR_READONLY 4
67 #define CVAR_SERVERINFO 8
68 #define CVAR_USERINFO 16
69 // CVAR_PRIVATE means do not $ expand or sendcvar this cvar under any circumstances (rcon_password uses this)
70 #define CVAR_PRIVATE 32
71 // this means that this cvar should update a userinfo key but the name does not correspond directly to the userinfo key to update, and may require additional conversion ("_cl_color" for example should update "topcolor" and "bottomcolor")
72 #define CVAR_NQUSERINFOHACK 64
73 // used to determine if flags is valid
74 #define CVAR_NORESETTODEFAULTS 128
75 // for engine-owned cvars that must not be reset on gametype switch (e.g. scr_screenshot_name, which otherwise isn't set to the mod name properly)
76 #define CVAR_MAXFLAGSVAL 255
77 // for internal use only!
78 #define CVAR_DEFAULTSET (1<<30)
79 #define CVAR_ALLOCATED (1<<31)
80
81 /*
82 // type of a cvar for menu purposes
83 #define CVARMENUTYPE_FLOAT 1
84 #define CVARMENUTYPE_INTEGER 2
85 #define CVARMENUTYPE_SLIDER 3
86 #define CVARMENUTYPE_BOOL 4
87 #define CVARMENUTYPE_STRING 5
88 #define CVARMENUTYPE_OPTION 6
89
90 // which menu to put a cvar in
91 #define CVARMENU_GRAPHICS 1
92 #define CVARMENU_SOUND 2
93 #define CVARMENU_INPUT 3
94 #define CVARMENU_NETWORK 4
95 #define CVARMENU_SERVER 5
96
97 #define MAX_CVAROPTIONS 16
98
99 typedef struct cvaroption_s
100 {
101         int value;
102         const char *name;
103 }
104 cvaroption_t;
105
106 typedef struct menucvar_s
107 {
108         int type;
109         float valuemin, valuemax, valuestep;
110         int numoptions;
111         cvaroption_t optionlist[MAX_CVAROPTIONS];
112 }
113 menucvar_t;
114 */
115
116 typedef struct cvar_s
117 {
118         int flags;
119
120         const char *name;
121
122         const char *string;
123         const char *description;
124         int integer;
125         float value;
126         float vector[3];
127
128         const char *defstring;
129
130         // values at init (for Cvar_RestoreInitState)
131         qboolean initstate; // indicates this existed at init
132         int initflags;
133         const char *initstring;
134         const char *initdescription;
135         int initinteger;
136         float initvalue;
137         float initvector[3];
138         const char *initdefstring;
139
140         int globaldefindex[3];
141         int globaldefindex_stringno[3];
142
143         //menucvar_t menuinfo;
144         struct cvar_s *next;
145         struct cvar_s *nextonhashchain;
146 } cvar_t;
147
148 /*
149 void Cvar_MenuSlider(cvar_t *variable, int menu, float slider_min, float slider_max, float slider_step);
150 void Cvar_MenuBool(cvar_t *variable, int menu, const char *name_false, const char *name_true);
151 void Cvar_MenuFloat(cvar_t *variable, int menu, float range_min, float range_max);
152 void Cvar_MenuInteger(cvar_t *variable, int menu, int range_min, int range_max);
153 void Cvar_MenuString(cvar_t *variable, int menu);
154 void Cvar_MenuOption(cvar_t *variable, int menu, int value[16], const char *name[16]);
155 */
156
157 /// registers a cvar that already has the name, string, and optionally the
158 /// archive elements set.
159 void Cvar_RegisterVariable (cvar_t *variable);
160
161 /// equivelant to "<name> <variable>" typed at the console
162 void Cvar_Set (const char *var_name, const char *value);
163
164 /// expands value to a string and calls Cvar_Set
165 void Cvar_SetValue (const char *var_name, float value);
166
167 void Cvar_SetQuick (cvar_t *var, const char *value);
168 void Cvar_SetValueQuick (cvar_t *var, float value);
169
170 float Cvar_VariableValueOr (const char *var_name, float def);
171 // returns def if not defined
172
173 float Cvar_VariableValue (const char *var_name);
174 // returns 0 if not defined or non numeric
175
176 const char *Cvar_VariableStringOr (const char *var_name, const char *def);
177 // returns def if not defined
178
179 const char *Cvar_VariableString (const char *var_name);
180 // returns an empty string if not defined
181
182 const char *Cvar_VariableDefString (const char *var_name);
183 // returns an empty string if not defined
184
185 const char *Cvar_VariableDescription (const char *var_name);
186 // returns an empty string if not defined
187
188 const char *Cvar_CompleteVariable (const char *partial);
189 // attempts to match a partial variable name for command line completion
190 // returns NULL if nothing fits
191
192 void Cvar_CompleteCvarPrint (const char *partial);
193
194 qboolean Cvar_Command (cmd_state_t *cmd);
195 // called by Cmd_ExecuteString when Cmd_Argv(cmd, 0) doesn't match a known
196 // command.  Returns true if the command was a variable reference that
197 // was handled. (print or change)
198
199 void Cvar_SaveInitState(void);
200 void Cvar_RestoreInitState(void);
201
202 void Cvar_UnlockDefaults (void);
203 void Cvar_LockDefaults_f(cmd_state_t *cmd);
204 void Cvar_ResetToDefaults_All_f(cmd_state_t *cmd);
205 void Cvar_ResetToDefaults_NoSaveOnly_f(cmd_state_t *cmd);
206 void Cvar_ResetToDefaults_SaveOnly_f(cmd_state_t *cmd);
207
208 void Cvar_WriteVariables (qfile_t *f);
209 // Writes lines containing "set variable value" for all variables
210 // with the archive flag set to true.
211
212 cvar_t *Cvar_FindVar (const char *var_name);
213 cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags);
214
215 int Cvar_CompleteCountPossible (const char *partial);
216 const char **Cvar_CompleteBuildList (const char *partial);
217 // Added by EvilTypeGuy - functions for tab completion system
218 // Thanks to Fett erich@heintz.com
219 // Thanks to taniwha
220
221 /// Prints a list of Cvars including a count of them to the user console
222 /// Referenced in cmd.c in Cmd_Init hence it's inclusion here.
223 /// Added by EvilTypeGuy eviltypeguy@qeradiant.com
224 /// Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
225 void Cvar_List_f(cmd_state_t *cmd);
226
227 void Cvar_Set_f(cmd_state_t *cmd);
228 void Cvar_SetA_f(cmd_state_t *cmd);
229 void Cvar_Del_f(cmd_state_t *cmd);
230 // commands to create new cvars (or set existing ones)
231 // seta creates an archived cvar (saved to config)
232
233 /// allocates a cvar by name and returns its address,
234 /// or merely sets its value if it already exists.
235 cvar_t *Cvar_Get (const char *name, const char *value, int flags, const char *newdescription);
236
237 extern const char *cvar_dummy_description; // ALWAYS the same pointer
238 extern cvar_t *cvar_vars; // used to list all cvars
239
240 void Cvar_UpdateAllAutoCvars(void); // updates ALL autocvars of the active prog to the cvar values (savegame loading)
241
242 #ifdef FILLALLCVARSWITHRUBBISH
243 void Cvar_FillAll_f(cmd_state_t *cmd);
244 #endif /* FILLALLCVARSWITHRUBBISH */
245
246 #endif
247