UFO: Alien Invasion
Loading...
Searching...
No Matches
cvar.h
Go to the documentation of this file.
1
14
15/*
16Copyright (C) 1997-2001 Id Software, Inc.
17
18This program is free software; you can redistribute it and/or
19modify it under the terms of the GNU General Public License
20as published by the Free Software Foundation; either version 2
21of the License, or (at your option) any later version.
22
23This program is distributed in the hope that it will be useful,
24but WITHOUT ANY WARRANTY; without even the implied warranty of
25MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26
27See the GNU General Public License for more details.
28
29You should have received a copy of the GNU General Public License
30along with this program; if not, write to the Free Software
31Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32
33*/
34
35#pragma once
36
37#include "../shared/shared.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
50
51#define CVAR_R_MASK (CVAR_R_IMAGES | CVAR_R_CONTEXT | CVAR_R_PROGRAMS)
52
59typedef void (*cvarChangeListenerFunc_t) (const char* cvarName, const char* oldValue, const char* newValue, void* data);
60
61typedef struct cvarChangeListener_s {
63 struct cvarChangeListener_s* next;
64 void* data;
66
71typedef struct cvar_s {
72 char* name;
73 char* string;
76 char* oldString;
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
89typedef struct cvarList_s {
90 const char* name;
91 const char* value;
93
99public:
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
110cvar_t* Cvar_GetFirst(void);
111
117cvar_t* Cvar_Get(const char* varName, const char* value = "", int flags = 0, const char* desc = nullptr);
118
122cvar_t* Cvar_Set(const char* varName, const char* value, ...) __attribute__((format(__printf__, 2, 3)));
123
127cvar_t* Cvar_ForceSet(const char* varName, const char* value);
128
129cvar_t* Cvar_FullSet(const char* varName, const char* value, int flags);
130
134void Cvar_SetValue(const char* varName, float value);
135
139int Cvar_GetInteger(const char* varName);
140
144float Cvar_GetValue(const char* varName);
145
149const char* Cvar_GetString(const char* varName);
150
154const char* Cvar_VariableStringOld(const char* varName);
155
160int Cvar_CompleteVariable(const char* partial, const char** match);
161
165void Cvar_UpdateLatchedVars(void);
166
172bool Cvar_Command(void);
173
174void Cvar_Init(void);
175void Cvar_Shutdown(void);
176
180const char* Cvar_Userinfo(char* info, size_t infoSize);
181
185const char* Cvar_Serverinfo(char* info, size_t infoSize);
186
190bool Cvar_AssertValue(cvar_t* cvar, float minVal, float maxVal, bool shouldBeIntegral);
191
195bool Cvar_SetCheckFunction(const char* varName, bool (*check) (cvar_t* cvar));
196
204
210void Cvar_UnRegisterChangeListener(const char* varName, cvarChangeListenerFunc_t listenerFunc);
211
217
223
227void Cvar_FixCheatVars(void);
228
232bool Cvar_Delete(const char* varName);
233
237cvar_t* Cvar_FindVar(const char* varName);
238
244bool Cvar_PendingCvars(int flags);
245
246void Com_SetUserinfoModified(bool modified);
247
248bool Com_IsUserinfoModified(void);
249
250void Com_SetRenderModified(bool modified);
251
252bool Com_IsRenderModified(void);
253
254void Cvar_ClearVars(int flags);
255
256void Cvar_Reset(cvar_t* cvar);
257
258#ifdef DEBUG
259void Cvar_PrintDebugCvars(void);
260#endif
Listener for cvar changes.
Definition cvar.h:98
virtual ~CvarListener()
Definition cvar.h:100
virtual void onDelete(const struct cvar_s *cvar)=0
virtual void onCreate(const struct cvar_s *cvar)=0
cvar_t * Cvar_ForceSet(const char *varName, const char *value)
Will set the variable even if NOSET or LATCH.
Definition cvar.cpp:604
bool Cvar_PendingCvars(int flags)
Checks whether there are pending cvars for the given flags.
Definition cvar.cpp:881
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
const char * Cvar_Userinfo(char *info, size_t infoSize)
Returns an info string containing all the CVAR_USERINFO cvars.
Definition cvar.cpp:967
void Com_SetRenderModified(bool modified)
Definition cvar.cpp:66
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition cvar.cpp:671
const char * Cvar_VariableStringOld(const char *varName)
Returns the old value of cvar as string before we changed it.
Definition cvar.cpp:226
void Cvar_UnRegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Unregisters a cvar change listener.
Definition cvar.cpp:487
bool Cvar_SetCheckFunction(const char *varName, bool(*check)(cvar_t *cvar))
Set a checker function for cvar values.
Definition cvar.cpp:139
bool Cvar_Delete(const char *varName)
Function to remove the cvar and free the space.
Definition cvar.cpp:279
int Cvar_GetInteger(const char *varName)
Returns the int value of a cvar.
Definition cvar.cpp:194
bool Com_IsRenderModified(void)
Definition cvar.cpp:71
void Cvar_RegisterCvarListener(CvarListenerPtr listener)
Registers a cvar listener.
Definition cvar.cpp:406
bool Cvar_AssertValue(cvar_t *cvar, float minVal, float maxVal, bool shouldBeIntegral)
Checks cvar values.
Definition cvar.cpp:161
void Cvar_UnRegisterCvarListener(CvarListenerPtr listener)
Unregisters a cvar listener.
Definition cvar.cpp:415
void Cvar_Reset(cvar_t *cvar)
Sets the cvar value back to the old value.
Definition cvar.cpp:241
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
float Cvar_GetValue(const char *varName)
Returns the float value of a cvar.
Definition cvar.cpp:125
cvar_t * Cvar_FindVar(const char *varName)
Searches for a cvar given by parameter.
Definition cvar.cpp:106
bool Cvar_Command(void)
Handles variable inspection and changing from the console.
Definition cvar.cpp:708
void Cvar_ClearVars(int flags)
Definition cvar.cpp:891
void Cvar_Shutdown(void)
Definition cvar.cpp:1100
bool Com_IsUserinfoModified(void)
Definition cvar.cpp:61
void Cvar_Init(void)
Reads in all archived cvars.
Definition cvar.cpp:1087
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
Definition cvar.cpp:210
void Cvar_UpdateLatchedVars(void)
Any variables with latched values will now be updated.
Definition cvar.cpp:683
void Cvar_FixCheatVars(void)
Reset cheat cvar values to default.
Definition cvar.cpp:1042
void Com_SetUserinfoModified(bool modified)
Definition cvar.cpp:56
int Cvar_CompleteVariable(const char *partial, const char **match)
Unix like tab completion for console variables.
Definition cvar.cpp:258
const char * Cvar_Serverinfo(char *info, size_t infoSize)
Returns an info string containing all the CVAR_SERVERINFO cvars.
Definition cvar.cpp:977
cvar_t * Cvar_Set(const char *varName, const char *value,...) __attribute__((format(__printf__
will create the variable if it doesn't exist
SharedPtr< CvarListener > CvarListenerPtr
Definition cvar.h:105
void(* cvarChangeListenerFunc_t)(const char *cvarName, const char *oldValue, const char *newValue, void *data)
Callback for the change listener.
Definition cvar.h:59
cvar_t * Cvar_GetFirst(void)
Return the first cvar of the cvar list.
Definition cvar.cpp:81
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,...
Definition cvar.cpp:342
#define __attribute__(x)
Definition cxx.h:37
void format(__printf__, 1, 2)))
QGL_EXTERN void(APIENTRY *qglActiveTexture)(GLenum texture)
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
Header for lua script functions.
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
struct cvar_s * next
Definition cvar.h:84
bool modified
Definition cvar.h:79
struct cvar_s * hash_next
Definition cvar.h:86
char * latchedString
Definition cvar.h:74
char * description
Definition cvar.h:77
float value
Definition cvar.h:80
int integer
Definition cvar.h:81
char * string
Definition cvar.h:73
char * defaultString
Definition cvar.h:75
char * oldString
Definition cvar.h:76
struct cvar_s * prev
Definition cvar.h:85
bool(* check)(struct cvar_s *cvar)
Definition cvar.h:82
char * name
Definition cvar.h:72
cvarChangeListener_t * changeListener
Definition cvar.h:83
int flags
Definition cvar.h:78
struct cvarChangeListener_s * next
Definition cvar.h:63
cvarChangeListenerFunc_t exec
Definition cvar.h:62
const char * name
Definition cvar.h:90
const char * value
Definition cvar.h:91