]> git.xonotic.org Git - xonotic/darkplaces.git/blob - cvar.h
build: minor adjustments
[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 /*
23
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
25 in C code.
26
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:
30
31 cvar_t  r_draworder = {"r_draworder","1"};
32 cvar_t  scr_screensize = {"screensize","1",true};
33
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);
36
37
38 C code usually just references a cvar in place:
39 if ( r_draworder.value )
40
41 It could optionally ask for the value to be looked up for a string name:
42 if (Cvar_VariableValue ("r_draworder"))
43
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");
48
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.
54 */
55
56 #ifndef CVAR_H
57 #define CVAR_H
58
59 #include "qtypes.h"
60 #include "qdefs.h"
61 struct cmd_state_s;
62 struct qfile_s;
63
64 typedef struct cvar_s
65 {
66         int flags;
67
68         const char *name;
69
70         const char *string;
71         const char *description;
72         int integer;
73         float value;
74         float vector[3];
75
76         const char *defstring;
77
78         void (*callback)(struct cvar_s *var);
79         qbool ignore_callback;
80
81         char **aliases;
82         int aliasindex;
83
84         struct cvar_s *initstate; // snapshot of cvar during init
85
86         int globaldefindex[3];
87         int globaldefindex_stringno[3];
88
89         struct cvar_s *next;
90 } cvar_t;
91
92 typedef struct cvar_hash_s
93 {
94         cvar_t *cvar;
95         struct cvar_hash_s *next;
96 } cvar_hash_t;
97
98 typedef struct cvar_state_s
99 {
100         cvar_t *vars;
101         cvar_hash_t *hashtable[CVAR_HASHSIZE];
102 }
103 cvar_state_t;
104
105 extern cvar_state_t cvars_all;
106 extern cvar_state_t cvars_null; // used by cmd_serverfromclient which intentionally has no cvars available
107
108 void Cvar_RegisterAlias(cvar_t *variable, const char *alias );
109
110 void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *));
111
112 /// registers a cvar that already has the name, string, and optionally the
113 /// archive elements set.
114 void Cvar_RegisterVariable(cvar_t *variable);
115
116 qbool Cvar_Readonly (cvar_t *var, const char *cmd_name);
117
118 void Cvar_Callback(cvar_t *var);
119
120 /// equivelant to "<name> <variable>" typed at the console
121 void Cvar_Set (cvar_state_t *cvars, const char *var_name, const char *value);
122
123 /// expands value to a string and calls Cvar_Set
124 void Cvar_SetValue (cvar_state_t *cvars, const char *var_name, float value);
125
126 void Cvar_SetQuick (cvar_t *var, const char *value);
127 void Cvar_SetValueQuick (cvar_t *var, float value);
128
129 float Cvar_VariableValueOr (cvar_state_t *cvars, const char *var_name, float def, int neededflags);
130 // returns def if not defined
131
132 float Cvar_VariableValue (cvar_state_t *cvars, const char *var_name, int neededflags);
133 // returns 0 if not defined or non numeric
134
135 const char *Cvar_VariableStringOr (cvar_state_t *cvars, const char *var_name, const char *def, int neededflags);
136 // returns def if not defined
137
138 const char *Cvar_VariableString (cvar_state_t *cvars, const char *var_name, int neededflags);
139 // returns an empty string if not defined
140
141 const char *Cvar_VariableDefString (cvar_state_t *cvars, const char *var_name, int neededflags);
142 // returns an empty string if not defined
143
144 const char *Cvar_VariableDescription (cvar_state_t *cvars, const char *var_name, int neededflags);
145 // returns an empty string if not defined
146
147 const char *Cvar_CompleteVariable (cvar_state_t *cvars, const char *partial, int neededflags);
148 // attempts to match a partial variable name for command line completion
149 // returns NULL if nothing fits
150
151 void Cvar_PrintHelp(cvar_t *cvar, const char *name, qbool full);
152
153 void Cvar_CompleteCvarPrint (cvar_state_t *cvars, const char *partial, int neededflags);
154
155 qbool Cvar_Command (struct cmd_state_s *cmd);
156 // called by Cmd_ExecuteString when Cmd_Argv(cmd, 0) doesn't match a known
157 // command.  Returns true if the command was a variable reference that
158 // was handled. (print or change)
159
160 void Cvar_SaveInitState(cvar_state_t *cvars);
161 void Cvar_RestoreInitState(cvar_state_t *cvars);
162
163 void Cvar_UnlockDefaults(struct cmd_state_s *cmd);
164 void Cvar_LockDefaults_f(struct cmd_state_s *cmd);
165 void Cvar_ResetToDefaults_All_f(struct cmd_state_s *cmd);
166 void Cvar_ResetToDefaults_NoSaveOnly_f(struct cmd_state_s *cmd);
167 void Cvar_ResetToDefaults_SaveOnly_f(struct cmd_state_s *cmd);
168
169 void Cvar_WriteVariables (cvar_state_t *cvars, struct qfile_s *f);
170 // Writes lines containing "set variable value" for all variables
171 // with the archive flag set to true.
172
173 cvar_t *Cvar_FindVar(cvar_state_t *cvars, const char *var_name, int neededflags);
174 cvar_t *Cvar_FindVarAfter(cvar_state_t *cvars, const char *prev_var_name, int neededflags);
175
176 int Cvar_CompleteCountPossible(cvar_state_t *cvars, const char *partial, int neededflags);
177 const char **Cvar_CompleteBuildList(cvar_state_t *cvars, const char *partial, int neededflags);
178 // Added by EvilTypeGuy - functions for tab completion system
179 // Thanks to Fett erich@heintz.com
180 // Thanks to taniwha
181
182 /// Prints a list of Cvars including a count of them to the user console
183 /// Referenced in cmd.c in Cmd_Init hence it's inclusion here.
184 /// Added by EvilTypeGuy eviltypeguy@qeradiant.com
185 /// Thanks to Matthias "Maddes" Buecher, http://www.inside3d.com/qip/
186 void Cvar_List_f(struct cmd_state_s *cmd);
187
188 void Cvar_Set_f(struct cmd_state_s *cmd);
189 void Cvar_SetA_f(struct cmd_state_s *cmd);
190 void Cvar_Del_f(struct cmd_state_s *cmd);
191 // commands to create new cvars (or set existing ones)
192 // seta creates an archived cvar (saved to config)
193
194 /// allocates a cvar by name and returns its address,
195 /// or merely sets its value if it already exists.
196 cvar_t *Cvar_Get(cvar_state_t *cvars, const char *name, const char *value, int flags, const char *newdescription);
197
198 extern const char *cvar_dummy_description; // ALWAYS the same pointer
199
200 void Cvar_UpdateAllAutoCvars(cvar_state_t *cvars); // updates ALL autocvars of the active prog to the cvar values (savegame loading)
201
202 #ifdef FILLALLCVARSWITHRUBBISH
203 void Cvar_FillAll_f(cmd_state_t *cmd);
204 #endif /* FILLALLCVARSWITHRUBBISH */
205
206 #endif
207