FTEQW
Documentation of the FTE engine source tree.
cvar.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// cvar.h
21
22/*
23
24cvar_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
25in C code.
26
27it is sufficient to initialize a cvar_t with just the first two fields, or
28you can add a ,true flag for variables that you want saved to the configuration
29file when the game is quit:
30
31cvar_t r_draworder = {"r_draworder","1"};
32cvar_t scr_screensize = {"screensize","1",true};
33
34Cvars 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:
35Cvar_RegisterVariable (&host_framerate);
36
37
38C code usually just references a cvar in place:
39if ( r_draworder.value )
40
41It could optionally ask for the value to be looked up for a string name:
42if (Cvar_VariableValue ("r_draworder"))
43
44Interpreted prog code can access cvars with the cvar(name) or
45cvar_set (name, value) internal functions:
46teamplay = cvar("teamplay");
47cvar_set ("registered", "1");
48
49The user can access cvars from the console in two ways:
50r_draworder prints the current value
51r_draworder 0 sets the current value to 0
52Cvars are restricted from having the same names as commands to keep this
53interface from being ambiguous.
54*/
55
56#include "../qclib/hash.h"
57
58typedef struct cvar_s
59{
60 //must match q2's definition
61 char *name;
62 char *string;
63 char *latched_string; // for CVAR_LATCHMASK vars
64 unsigned int flags;
66 float value;
67 struct cvar_s *next;
68
69 //free style :)
70 char *name2;
71
72 void (QDECL *callback) (struct cvar_s *var, char *oldvalue);
73 const char *description;
74 char *enginevalue; //when changing manifest dir, the cvar will be reset to this value. never freed.
75 char *defaultstr; //this is the current mod's default value. set on first update.
77
78 int ival;
79 vec4_t vec4; //0,0,0,1 if something didn't parse.
81
82#ifdef HLSERVER
84#endif
86
87#ifdef MINIMAL
88#define CVARAFCD(ConsoleName,Value,ConsoleName2,Flags,Callback,Description) {ConsoleName, NULL, NULL, Flags, 0, 0, 0, ConsoleName2, Callback, NULL, Value}
89#else
90#define CVARAFCD(ConsoleName,Value,ConsoleName2,Flags,Callback,Description) {ConsoleName, NULL, NULL, Flags, 0, 0, 0, ConsoleName2, Callback, Description, Value}
91#endif
92#define CVARAFD(ConsoleName,Value,ConsoleName2,Flags,Description)CVARAFCD(ConsoleName, Value, ConsoleName2, Flags, NULL, Description)
93#define CVARAFC(ConsoleName,Value,ConsoleName2,Flags,Callback) CVARAFCD(ConsoleName, Value, ConsoleName2, Flags, Callback, NULL)
94#define CVARAF(ConsoleName,Value,ConsoleName2,Flags) CVARAFCD(ConsoleName, Value, ConsoleName2, Flags, NULL, NULL)
95#define CVARFCD(ConsoleName,Value,Flags,Callback,Description) CVARAFCD(ConsoleName, Value, NULL, Flags, Callback, Description)
96#define CVARFC(ConsoleName,Value,Flags,Callback) CVARAFCD(ConsoleName, Value, NULL, Flags, Callback, NULL)
97#define CVARAD(ConsoleName,Value,ConsoleName2,Description) CVARAFCD(ConsoleName, Value, ConsoleName2, 0, NULL, Description)
98#define CVARFD(ConsoleName,Value,Flags,Description) CVARAFCD(ConsoleName, Value, NULL, Flags, NULL, Description)
99#define CVARF(ConsoleName,Value,Flags) CVARFC(ConsoleName, Value, Flags, NULL)
100#define CVARC(ConsoleName,Value,Callback) CVARFC(ConsoleName, Value, 0, Callback)
101#define CVARCD(ConsoleName,Value,Callback,Description) CVARAFCD(ConsoleName, Value, NULL, 0, Callback, Description)
102#define CVARD(ConsoleName,Value,Description) CVARAFCD(ConsoleName, Value, NULL, 0, NULL, Description)
103#define CVAR(ConsoleName,Value) CVARD(ConsoleName, Value, NULL)
104
105typedef struct cvar_group_s
106{
107 const char *name;
109
112
113//q2 constants
114#define CVAR_ARCHIVE (1<<0) // set to cause it to be saved to vars.rc
115#define CVAR_USERINFO (1<<1) // added to userinfo when changed
116#define CVAR_SERVERINFO (1<<2) // added to serverinfo when changed
117#define CVAR_NOSET (1<<3) // don't allow change from console at all,
118 // but can be set from the command line
119#define CVAR_MAPLATCH (1<<4) // save changes until server restart, to avoid q2 gamecode bugging out.
120
121//freestyle
122#define CVAR_POINTER (1<<5) // q2 style. May be converted to q1 if needed. These are often specified on the command line and then converted into q1 when registered properly.
123//#define CVAR_UNUSED (1<<6) //the default string was malloced/needs to be malloced, free on unregister
124#define CVAR_NOTFROMSERVER (1<<7) //cvar cannot be set by gamecode. the console will ignore changes to cvars if set at from the server or any gamecode. This is to protect against security flaws - like qterm
125#define CVAR_USERCREATED (1<<8) //write a 'set' or 'seta' in front of the var name.
126#define CVAR_CHEAT (1<<9) //latch to the default, unless cheats are enabled.
127#define CVAR_SEMICHEAT (1<<10) //if strict ruleset, force to blank (aka 0).
128#define CVAR_RENDERERLATCH (1<<11) //requires a vid_reload to reapply.
129#define CVAR_SERVEROVERRIDE (1<<12) //the server has overridden out local value - should probably be called SERVERLATCH
130#define CVAR_RENDERERCALLBACK (1<<13) //force callback for cvars on renderer change
131#define CVAR_NOUNSAFEEXPAND (1<<14) //cvar cannot be read by gamecode. do not expand cvar value when command is from gamecode.
132#define CVAR_RULESETLATCH (1<<15) //latched by the ruleset
133#define CVAR_SHADERSYSTEM (1<<16) //change flushes shaders.
134#define CVAR_TELLGAMECODE (1<<17) //tells the gamecode when it has changed, does not prevent changing, added as an optimisation
135
136#define CVAR_CONFIGDEFAULT (1<<18) //this cvar's default value has been changed to match a config.
137#define CVAR_NOSAVE (1<<19) //this cvar should never be saved. ever.
138#define CVAR_NORESET (1<<20) //cvar is not reset by various things.
139#define CVAR_TEAMPLAYTAINT (1<<21) //current value contains the evaluation of a teamplay macro.
140
141#define CVAR_WATCHED (1<<22) //report any attempts to change this cvar.
142#define CVAR_VIDEOLATCH (1<<23)
143#define CVAR_WARNONCHANGE (1<<24) //print a warning when changed to a value other than its default.
144
145#define CVAR_LASTFLAG CVAR_VIDEOLATCH
146
147#define CVAR_LATCHMASK (CVAR_MAPLATCH|CVAR_RENDERERLATCH|CVAR_VIDEOLATCH|CVAR_SERVEROVERRIDE|CVAR_CHEAT|CVAR_SEMICHEAT) //you're only allowed one of these.
148#define CVAR_NEEDDEFAULT CVAR_CHEAT
149
150//an alias
151#define CVAR_SAVE CVAR_ARCHIVE
152
153cvar_t *Cvar_Get2 (const char *var_name, const char *value, int flags, const char *description, const char *groupname);
154#define Cvar_Get(n,v,f,g) Cvar_Get2(n,v,f,NULL,g)
155
156void Cvar_LockFromServer(cvar_t *var, const char *str);
157
158qboolean Cvar_Register (cvar_t *variable, const char *cvargroup);
159// registers a cvar that already has the name, string, and optionally the
160// archive elements set.
161
162cvar_t *Cvar_ForceSet (cvar_t *var, const char *value);
163cvar_t *Cvar_Set (cvar_t *var, const char *value);
164// equivelant to "<name> <variable>" typed at the console
165
166void Cvar_ForceSetValue (cvar_t *var, float value);
167void Cvar_SetValue (cvar_t *var, float value);
168// expands value to a string and calls Cvar_Set
169
170qboolean Cvar_ApplyLatchFlag(cvar_t *var, char *value, unsigned int newflag, unsigned int ignoreflags);
171
173void Cvar_Saved(void);
174void Cvar_ConfigChanged(void);
175
176extern int cvar_watched; //so that cmd.c knows that it should add messages when configs are execed
177void Cvar_ParseWatches(void); //parse -watch args
178
179int Cvar_ApplyLatches(int latchflag, qboolean clearflag);
180//sets vars to their latched values (and optionally forgets the cvarflag in question)
181
182void Cvar_Hook(cvar_t *cvar, void (QDECL *callback) (struct cvar_s *var, char *oldvalue));
183//hook a cvar with a given callback function at runtime
184
185void Cvar_Unhook(cvar_t *cvar);
186//unhook a cvar
187
188void Cvar_ForceCallback(cvar_t *cvar);
189// force a cvar callback
190
191void Cvar_ApplyCallbacks(int callbackflag);
192//forces callbacks to be ran for given flags
193
194void QDECL Cvar_Limiter_ZeroToOne_Callback(struct cvar_s *var, char *oldvalue);
195//cvar callback to limit cvar value to 0 or 1
196
197float Cvar_VariableValue (const char *var_name);
198// returns 0 if not defined or non numeric
199
200char *Cvar_VariableString (const char *var_name);
201// returns an empty string if not defined
202
203void Cvar_SetNamed (const char *var_name, const char *newvalue);
204
205char *Cvar_CompleteVariable (const char *partial);
206// attempts to match a partial variable name for command line completion
207// returns NULL if nothing fits
208
210// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
211// command. Returns true if the command was a variable reference that
212// was handled. (print or change)
213
215// Writes lines containing "set variable value" for all variables
216// with the archive flag set to true.
217
218cvar_t *Cvar_FindVar (const char *var_name);
219
220void Cvar_SetEngineDefault(cvar_t *var, char *val);
221
222void Cvar_Init(void);
223void Cvar_Shutdown(void);
224
225void Cvar_ForceCheatVars(qboolean semicheats, qboolean absolutecheats); //locks/unlocks cheat cvars depending on weather we are allowed them.
226
227//extern cvar_t *cvar_vars;
qboolean
Definition: api_menu.h:34
vec_t vec4_t[4]
Definition: api_menu.h:41
void dNearCallback * callback
Definition: com_phys_ode.c:655
unsigned char qbyte
Definition: common.h:127
void Cvar_Saved(void)
Definition: cvar.c:887
struct cvar_group_s cvar_group_t
void Cvar_SetEngineDefault(cvar_t *var, char *val)
Definition: cvar.c:544
char * Cvar_VariableString(const char *var_name)
Definition: cvar.c:825
char * Cvar_CompleteVariable(const char *partial)
qboolean Cvar_Command(cvar_t *v, int level)
Definition: cvar.c:1484
void Cvar_ApplyCallbacks(int callbackflag)
Definition: cvar.c:1729
void Cvar_ForceCheatVars(qboolean semicheats, qboolean absolutecheats)
Definition: cvar.c:1123
int Cvar_ApplyLatches(int latchflag, qboolean clearflag)
Definition: cvar.c:1180
void Cvar_ParseWatches(void)
Definition: cmd.c:4063
cvar_t * Cvar_FindVar(const char *var_name)
Definition: cvar.c:156
qboolean Cvar_UnsavedArchive(void)
Definition: cvar.c:879
int cvar_watched
Definition: cvar.c:115
void Cvar_Unhook(cvar_t *cvar)
Definition: cvar.c:1717
void Cvar_ForceSetValue(cvar_t *var, float value)
Definition: cvar.c:1247
cvar_t * Cvar_Set(cvar_t *var, const char *value)
Definition: cvar.c:1212
struct cvar_s cvar_t
void Cvar_Shutdown(void)
Definition: cvar.c:1766
void Cvar_SetNamed(const char *var_name, const char *newvalue)
Definition: cvar.c:835
void Cvar_SetValue(cvar_t *var, float value)
Definition: cvar.c:1226
qboolean Cvar_Register(cvar_t *variable, const char *cvargroup)
Definition: cvar.c:1302
void Cvar_Init(void)
Definition: cvar.c:1760
void Cvar_ConfigChanged(void)
Definition: cvar.c:883
void Cvar_LockFromServer(cvar_t *var, const char *str)
Definition: cvar.c:1453
cvar_t * Cvar_Get2(const char *var_name, const char *value, int flags, const char *description, const char *groupname)
Definition: cvar.c:1400
void Cvar_Hook(cvar_t *cvar, void(QDECL *callback)(struct cvar_s *var, char *oldvalue))
Definition: cvar.c:1712
qboolean Cvar_ApplyLatchFlag(cvar_t *var, char *value, unsigned int newflag, unsigned int ignoreflags)
Definition: cvar.c:1080
float Cvar_VariableValue(const char *var_name)
Definition: cvar.c:809
void QDECL Cvar_Limiter_ZeroToOne_Callback(struct cvar_s *var, char *oldvalue)
Definition: cvar.c:1746
void Cvar_ForceCallback(cvar_t *cvar)
Definition: cvar.c:1722
cvar_t * Cvar_ForceSet(cvar_t *var, const char *value)
Definition: cvar.c:1216
void Cvar_WriteVariables(vfsfile_t *f, qboolean all)
Definition: cvar.c:1667
GLint level
Definition: gl_vidcommon.c:42
GLsizei GLboolean const GLfloat * value
Definition: glquake.h:164
const GLfloat * v
Definition: glsupp.h:466
const char * var
Definition: pr_lua.c:225
Definition: cvar.h:106
cvar_t * cvars
Definition: cvar.h:110
const char * name
Definition: cvar.h:107
struct cvar_group_s * next
Definition: cvar.h:108
Definition: cvar.h:59
struct cvar_s * next
Definition: cvar.h:67
struct hlcvar_s * hlcvar
Definition: cvar.h:83
qbyte restriction
Definition: cvar.h:76
int ival
Definition: cvar.h:78
int modifiedcount
Definition: cvar.h:80
const char * description
Definition: cvar.h:73
qboolean modified
Definition: cvar.h:65
char * name2
Definition: cvar.h:70
vec4_t vec4
Definition: cvar.h:79
float value
Definition: cvar.h:66
void(QDECL *callback)(struct cvar_s *var
char * name
Definition: cvar.h:61
unsigned int flags
Definition: cvar.h:64
char * latched_string
Definition: cvar.h:63
char * enginevalue
Definition: cvar.h:74
char * oldvalue
Definition: cvar.h:72
char * defaultstr
Definition: cvar.h:75
char * string
Definition: cvar.h:62
Definition: svhl_gcapi.h:267
void * vfsfile_t
Definition: sys_plugfte.h:2
unsigned int flags
Definition: valid.c:313