UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cvar.h
Go to the documentation of this file.
1 
15 /*
16 Copyright (C) 1997-2001 Id Software, Inc.
17 
18 This program is free software; you can redistribute it and/or
19 modify it under the terms of the GNU General Public License
20 as published by the Free Software Foundation; either version 2
21 of the License, or (at your option) any later version.
22 
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 
27 See the GNU General Public License for more details.
28 
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 
33 */
34 
35 #pragma once
36 
37 #include "../shared/shared.h"
38 #include "../common/scripts_lua.h"
39 
40 #define CVAR_ARCHIVE 1
41 #define CVAR_USERINFO 2
42 #define CVAR_SERVERINFO 4
43 #define CVAR_NOSET 8
44 #define CVAR_LATCH 16
45 #define CVAR_DEVELOPER 32
46 #define CVAR_CHEAT 64
47 #define CVAR_R_IMAGES 128
48 #define CVAR_R_CONTEXT 256
49 #define CVAR_R_PROGRAMS 512
51 #define CVAR_R_MASK (CVAR_R_IMAGES | CVAR_R_CONTEXT | CVAR_R_PROGRAMS)
52 
59 typedef void (*cvarChangeListenerFunc_t) (const char* cvarName, const char* oldValue, const char* newValue, void* data);
60 
61 typedef struct cvarChangeListener_s {
64  void* data;
66 
71 typedef struct cvar_s {
72  char* name;
73  char* string;
74  char* latchedString;
75  char* defaultString;
76  char* oldString;
77  char* description;
78  int flags;
79  bool modified;
80  float value;
81  int integer;
82  bool (*check) (struct cvar_s* cvar);
84  struct cvar_s* next;
85  struct cvar_s* prev;
86  struct cvar_s* hash_next;
87 } cvar_t;
88 
89 typedef struct cvarList_s {
90  const char* name;
91  const char* value;
92 } cvarList_t;
93 
98 class CvarListener {
99 public:
100  virtual ~CvarListener() {}
101  virtual void onCreate (const struct cvar_s* cvar) = 0;
102  virtual void onDelete (const struct cvar_s* cvar) = 0;
103 };
104 
106 
110 cvar_t* Cvar_GetFirst(void);
111 
117 cvar_t* Cvar_Get(const char* varName, const char* value = "", int flags = 0, const char* desc = nullptr);
118 
122 cvar_t* Cvar_Set(const char* varName, const char* value, ...) __attribute__((format(__printf__, 2, 3)));
123 
127 cvar_t* Cvar_ForceSet(const char* varName, const char* value);
128 
129 cvar_t* Cvar_FullSet(const char* varName, const char* value, int flags);
130 
134 void Cvar_SetValue(const char* varName, float value);
135 
139 int Cvar_GetInteger(const char* varName);
140 
144 float Cvar_GetValue(const char* varName);
145 
149 const char* Cvar_GetString(const char* varName);
150 
154 const char* Cvar_VariableStringOld(const char* varName);
155 
160 int Cvar_CompleteVariable(const char* partial, const char** match);
161 
165 void Cvar_UpdateLatchedVars(void);
166 
172 bool Cvar_Command(void);
173 
174 void Cvar_Init(void);
175 void Cvar_Shutdown(void);
176 
180 const char* Cvar_Userinfo(char* info, size_t infoSize);
181 
185 const char* Cvar_Serverinfo(char* info, size_t infoSize);
186 
190 bool Cvar_AssertValue(cvar_t* cvar, float minVal, float maxVal, bool shouldBeIntegral);
191 
195 bool Cvar_SetCheckFunction(const char* varName, bool (*check) (cvar_t* cvar));
196 
204 
210 void Cvar_UnRegisterChangeListener(const char* varName, cvarChangeListenerFunc_t listenerFunc);
211 
217 
223 
227 void Cvar_FixCheatVars(void);
228 
232 bool Cvar_Delete(const char* varName);
233 
237 cvar_t* Cvar_FindVar(const char* varName);
238 
244 bool Cvar_PendingCvars(int flags);
245 
246 void Com_SetUserinfoModified(bool modified);
247 
248 bool Com_IsUserinfoModified(void);
249 
250 void Com_SetRenderModified(bool modified);
251 
252 bool Com_IsRenderModified(void);
253 
254 void Cvar_ClearVars(int flags);
255 
256 void Cvar_Reset(cvar_t* cvar);
257 
258 #ifdef DEBUG
259 void Cvar_PrintDebugCvars(void);
260 #endif
struct cvar_s cvar_t
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
cvar_t cvar_t * Cvar_ForceSet(const char *varName, const char *value)
will set the variable even if NOSET or LATCH
Definition: cvar.cpp:604
void Com_SetUserinfoModified(bool modified)
Definition: cvar.cpp:56
struct cvar_s * hash_next
Definition: cvar.h:86
cvar_t * Cvar_FindVar(const char *varName)
Searches for a cvar given by parameter.
Definition: cvar.cpp:106
void Cvar_SetValue(const char *varName, float value)
expands value to a string and calls Cvar_Set
Definition: cvar.cpp:671
bool Cvar_Command(void)
called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known command. Returns true if the comma...
Definition: cvar.cpp:708
cvar_t * Cvar_Set(const char *varName, const char *value,...) __attribute__((format(__printf__
will create the variable if it doesn't exist
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
const char * name
Definition: cvar.h:90
const char * Cvar_VariableStringOld(const char *varName)
returns an empty string if not defined
Definition: cvar.cpp:226
float Cvar_GetValue(const char *varName)
returns 0.0 if not defined or non numeric
Definition: cvar.cpp:125
void Com_SetRenderModified(bool modified)
Definition: cvar.cpp:66
void(* cvarChangeListenerFunc_t)(const char *cvarName, const char *oldValue, const char *newValue, void *data)
Callback for the change listener.
Definition: cvar.h:59
float value
Definition: cvar.h:80
void Cvar_FixCheatVars(void)
Reset cheat cvar values to default.
Definition: cvar.cpp:1042
virtual void onDelete(const struct cvar_s *cvar)=0
char * defaultString
Definition: cvar.h:75
cvarChangeListener_t * Cvar_RegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Registers a listener that is executed each time a cvar changed its value.
Definition: cvar.cpp:446
#define __attribute__(x)
Definition: cxx.h:37
cvar_t * Cvar_Get(const char *varName, const char *value="", int flags=0, const char *desc=nullptr)
creates the variable if it doesn't exist, or returns the existing one if it exists, the value will not be changed, but flags will be ORed in that allows variables to be unarchived without needing bitflags
Definition: cvar.cpp:342
int integer
Definition: cvar.h:81
void Cvar_UnRegisterCvarListener(CvarListenerPtr listener)
Unregisters a cvar listener.
Definition: cvar.cpp:415
struct cvar_s * next
Definition: cvar.h:84
int flags
Definition: cvar.h:78
char * latchedString
Definition: cvar.h:74
cvarChangeListenerFunc_t exec
Definition: cvar.h:62
char * oldString
Definition: cvar.h:76
struct cvarChangeListener_s cvarChangeListener_t
const char * Cvar_GetString(const char *varName)
returns an empty string if not defined
Definition: cvar.cpp:210
cvar_t * Cvar_FullSet(const char *varName, const char *value, int flags)
Sets a cvar from console with the given flags.
Definition: cvar.cpp:640
void Cvar_Shutdown(void)
Definition: cvar.cpp:1100
const char * Cvar_Serverinfo(char *info, size_t infoSize)
returns an info string containing all the CVAR_SERVERINFO cvars
Definition: cvar.cpp:977
void Cvar_UnRegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Unregisters a cvar change listener.
Definition: cvar.cpp:487
bool Com_IsUserinfoModified(void)
Definition: cvar.cpp:61
void Cvar_Reset(cvar_t *cvar)
Sets the cvar value back to the old value.
Definition: cvar.cpp:241
char * description
Definition: cvar.h:77
struct cvar_s * prev
Definition: cvar.h:85
virtual ~CvarListener()
Definition: cvar.h:100
void Cvar_UpdateLatchedVars(void)
any CVAR_LATCHED variables that have been set will now take effect
Definition: cvar.cpp:683
int Cvar_CompleteVariable(const char *partial, const char **match)
attempts to match a partial variable name for command line completion returns nullptr if nothing fits...
Definition: cvar.cpp:258
bool Cvar_AssertValue(cvar_t *cvar, float minVal, float maxVal, bool shouldBeIntegral)
this function checks cvar ranges and integral values
Definition: cvar.cpp:161
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
Definition: r_gl.h:189
struct cvarList_s cvarList_t
cvarChangeListener_t * changeListener
Definition: cvar.h:83
void Cvar_RegisterCvarListener(CvarListenerPtr listener)
Registers a cvar listener.
Definition: cvar.cpp:406
char * string
Definition: cvar.h:73
bool Cvar_PendingCvars(int flags)
Checks whether there are pending cvars for the given flags.
Definition: cvar.cpp:881
const char * value
Definition: cvar.h:91
bool(* check)(struct cvar_s *cvar)
Definition: cvar.h:82
SharedPtr< CvarListener > CvarListenerPtr
Definition: cvar.h:105
void Cvar_Init(void)
Reads in all archived cvars.
Definition: cvar.cpp:1087
GLsizei const GLvoid * data
Definition: r_gl.h:152
struct cvarChangeListener_s * next
Definition: cvar.h:63
bool Cvar_SetCheckFunction(const char *varName, bool(*check)(cvar_t *cvar))
Sets the check functions for a cvar (e.g. Cvar_Assert)
Definition: cvar.cpp:139
const char * Cvar_Userinfo(char *info, size_t infoSize)
returns an info string containing all the CVAR_USERINFO cvars
Definition: cvar.cpp:967
bool modified
Definition: cvar.h:79
int Cvar_GetInteger(const char *varName)
returns 0 if not defined or non numeric
Definition: cvar.cpp:194
Listener for cvar changes.
Definition: cvar.h:98
cvar_t * Cvar_GetFirst(void)
Return the first cvar of the cvar list.
Definition: cvar.cpp:81
char * name
Definition: cvar.h:72
void format(__printf__, 1, 2)))
void Cvar_ClearVars(int flags)
Definition: cvar.cpp:891
virtual void onCreate(const struct cvar_s *cvar)=0
bool Com_IsRenderModified(void)
Definition: cvar.cpp:71
bool Cvar_Delete(const char *varName)
Function to remove the cvar and free the space.
Definition: cvar.cpp:279