-
Notifications
You must be signed in to change notification settings - Fork 2
/
cvar.h
173 lines (169 loc) · 4.27 KB
/
cvar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef CVAR_CPP_H
#define CVAR_CPP_H
class CVar {
private:
const char *name;
const char *originalValue;
char *sValue;
bool archive;
bool server;
float fValue;
int iValue;
bool bValue;
bool registered;
/**
* Initialises the cvar data (called by the constructors).
*
* @param name Name of the cvar
* @param sValue String value of the cvar
* @param archive True if the cvar is saved to configs
* @param server True if the cvar is sent from server to all clients when
* changed
*/
void init(const char *name, const char *sValue, bool archive, bool server);
/**
* Parse the string value of the cvar into float, int and bool values.
*/
void parseValue();
/**
* Add the cvar to the list of cvars.
*
* @param cvar cvar to add
*/
static void addCVar(CVar *cvar);
public:
CVar(const char *name, const char *sValue);
CVar(const char *name, const char *sValue, bool archive);
CVar(const char *name, const char *sValue, bool archive, bool server);
/**
* Register the cvar so it can be looked up based on it's name.
*/
void reg();
/**
* Unregister the cvar.
*/
void unreg();
/**
* Set the value of the cvar.
*
* @param value to set the cvar to
*/
void set(const char *value);
/**
* Set the value of the cvar.
*
* @param value to set the cvar to
*/
void set(float value);
/**
* Set the value of the cvar.
*
* @param value to set the cvar to
*/
void set(bool value);
/**
* Get the name of the cvar.
*
* @return name of the cvar
*/
const char *getName(void);
/**
* Gets the string value of the cvar
*
* @return the value of the cvar
*/
char *getString(void);
/**
* Gets the bool value of the cvar. Based off the int value of the cvar.
*
* @return bool value of hte cvar
*/
bool getBool(void);
/**
* Gets the value of the cvar parsed to an int.
*
* @return int value of the cvar
*/
int getInt(void);
/**
* Gets the value of the cvar parsed to a float.
*
* @return float value of the cvar
*/
float getFloat(void);
/**
* @return true if the cvar value is saved in a config file
*/
bool isArchived(void);
/**
* @return true if the cvar value will be sent to clients if updated
*/
bool isServer(void);
/**
* Add a cvar to the list of cvars
*
* @param cvar The cvar to add
*/
static CVar *findCVar(const char *name);
/**
* Search the list of cvars for one with the given name
*
* @param name The cvar name to search for
* @return The cvar object, or null if none found
*/
static CVar *findNextServerCVar (const char *name);
/**
* Register a cvar by adding it to our list of active cvars. Ensures that there
* isn't already a cvar or command by that name.
*
* @param variable
*/
static void registerCVar(CVar *variable);
/**
* Set a cvar value given the name of the cvar and the value to set it to.
*
* @param var_name The name of the cvar to set
* @param value The value to set the cvar to
*/
static void setValue(const char *name, const char *value);
/**
* Get the float value of a cvar for the name passed in.
*
* @param name The name of the cvar
* @return Either the value of the cvar or 0 if the cvar doesn't exist or if it
* doesn't have a float value (ie is a string value)
*/
static float getFloatValue(char *name);
/**
* Get the string value of a cvar for the name passed in.
*
* @param name
* @return
*/
static const char *getStringValue(char *name);
/**
* Attempt to auto-complete a cvar name given the partial value. If there are
* multiple matches, print the matched names and return NULL.
*
* @param partial The partial name to match against
* @return the fullname of the cvar, NULL if none match or if more than one match
*/
static const char *completeVariable(char *partial);
/**
* Handles variable inspection and changing from the console
*
* @return true if the variable was found, false otherwise
*/
static bool consoleCommand(void);
/**
* Writes lines containing "set variable value" for all variables with the
* archive flag set to true.
*/
static void writeVariables(int handle);
/**
* Clear out used zone memory, so that we can look for leaking memory more
* easily.
*/
static void shutdown();
};
#endif /* CVAR_CPP_H */