|
ds@457
|
1 |
//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// |
|
ds@457
|
2 |
// |
|
ds@457
|
3 |
// Purpose: |
|
ds@457
|
4 |
// |
|
ds@457
|
5 |
// $Workfile: $ |
|
ds@457
|
6 |
// $Date: 2006-08-13 06:34:30 -0500 (Sun, 13 Aug 2006) $ |
|
ds@457
|
7 |
// |
|
ds@457
|
8 |
//----------------------------------------------------------------------------- |
|
ds@457
|
9 |
// $NoKeywords: $ |
|
ds@457
|
10 |
//=============================================================================// |
|
ds@457
|
11 |
|
|
ds@457
|
12 |
#ifndef CONVAR_H |
|
ds@457
|
13 |
#define CONVAR_H |
|
ds@457
|
14 |
#if _WIN32 |
|
ds@457
|
15 |
#pragma once |
|
ds@457
|
16 |
#endif |
|
ds@457
|
17 |
|
|
ds@457
|
18 |
#include "tier0/dbg.h" |
|
ds@457
|
19 |
|
|
ds@457
|
20 |
#ifdef _WIN32 |
|
ds@457
|
21 |
#define FORCEINLINE_CVAR FORCEINLINE |
|
ds@457
|
22 |
#elif _LINUX |
|
ds@457
|
23 |
#define FORCEINLINE_CVAR __inline__ FORCEINLINE |
|
ds@457
|
24 |
#else |
|
ds@457
|
25 |
#error "implement me" |
|
ds@457
|
26 |
#endif |
|
ds@457
|
27 |
|
|
ds@457
|
28 |
// The default, no flags at all |
|
ds@457
|
29 |
#define FCVAR_NONE 0 |
|
ds@457
|
30 |
|
|
ds@457
|
31 |
// Command to ConVars and ConCommands |
|
ds@457
|
32 |
// ConVar Systems |
|
ds@457
|
33 |
#define FCVAR_UNREGISTERED (1<<0) // If this is set, don't add to linked list, etc. |
|
ds@457
|
34 |
#define FCVAR_LAUNCHER (1<<1) // defined by launcher |
|
ds@457
|
35 |
#define FCVAR_GAMEDLL (1<<2) // defined by the game DLL |
|
ds@457
|
36 |
#define FCVAR_CLIENTDLL (1<<3) // defined by the client DLL |
|
ds@457
|
37 |
#define FCVAR_MATERIAL_SYSTEM (1<<4) // Defined by the material system. |
|
ds@457
|
38 |
#define FCVAR_DATACACHE (1<<19) // Defined by the datacache system. |
|
ds@457
|
39 |
#define FCVAR_STUDIORENDER (1<<15) // Defined by the studiorender system. |
|
ds@457
|
40 |
#define FCVAR_FILESYSTEM (1<<21) // Defined by the file system. |
|
ds@457
|
41 |
#define FCVAR_PLUGIN (1<<18) // Defined by a 3rd party plugin. |
|
ds@457
|
42 |
#define FCVAR_TOOLSYSTEM (1<<20) // Defined by an IToolSystem library |
|
ds@457
|
43 |
#define FCVAR_SOUNDSYSTEM (1<<23) // Defined by the soundsystem library |
|
ds@457
|
44 |
#define FCVAR_INPUTSYSTEM (1<<25) // Defined by the inputsystem dll |
|
ds@457
|
45 |
#define FCVAR_NETWORKSYSTEM (1<<26) // Defined by the network system |
|
ds@457
|
46 |
// NOTE!! if you add a cvar system, add it here too!!!! |
|
ds@457
|
47 |
// the engine lacks a cvar flag, but needs it for xbox |
|
ds@457
|
48 |
// an engine cvar is thus a cvar not marked with any other system |
|
ds@457
|
49 |
#define FCVAR_NON_ENGINE ((FCVAR_LAUNCHER|FCVAR_GAMEDLL|FCVAR_CLIENTDLL|FCVAR_MATERIAL_SYSTEM|FCVAR_DATACACHE|FCVAR_STUDIORENDER|FCVAR_FILESYSTEM|FCVAR_PLUGIN|FCVAR_TOOLSYSTEM|FCVAR_SOUNDSYSTEM|FCVAR_INPUTSYSTEM|FCVAR_NETWORKSYSTEM)) |
|
ds@457
|
50 |
|
|
ds@457
|
51 |
// ConVar only |
|
ds@457
|
52 |
#define FCVAR_PROTECTED (1<<5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value |
|
ds@457
|
53 |
#define FCVAR_SPONLY (1<<6) // This cvar cannot be changed by clients connected to a multiplayer server. |
|
ds@457
|
54 |
#define FCVAR_ARCHIVE (1<<7) // set to cause it to be saved to vars.rc |
|
ds@457
|
55 |
#define FCVAR_NOTIFY (1<<8) // notifies players when changed |
|
ds@457
|
56 |
#define FCVAR_USERINFO (1<<9) // changes the client's info string |
|
ds@457
|
57 |
#define FCVAR_CHEAT (1<<14) // Only useable in singleplayer / debug / multiplayer & sv_cheats |
|
ds@457
|
58 |
|
|
ds@457
|
59 |
#define FCVAR_PRINTABLEONLY (1<<10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ). |
|
ds@457
|
60 |
#define FCVAR_UNLOGGED (1<<11) // If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log |
|
ds@457
|
61 |
#define FCVAR_NEVER_AS_STRING (1<<12) // never try to print that cvar |
|
ds@457
|
62 |
|
|
ds@457
|
63 |
// It's a ConVar that's shared between the client and the server. |
|
ds@457
|
64 |
// At signon, the values of all such ConVars are sent from the server to the client (skipped for local |
|
ds@457
|
65 |
// client, of course ) |
|
ds@457
|
66 |
// If a change is requested it must come from the console (i.e., no remote client changes) |
|
ds@457
|
67 |
// If a value is changed while a server is active, it's replicated to all connected clients |
|
ds@457
|
68 |
#define FCVAR_REPLICATED (1<<13) // server setting enforced on clients, TODO rename to FCAR_SERVER at some time |
|
ds@457
|
69 |
#define FCVAR_DEMO (1<<16) // record this cvar when starting a demo file |
|
ds@457
|
70 |
#define FCVAR_DONTRECORD (1<<17) // don't record these command in demofiles |
|
ds@457
|
71 |
|
|
ds@457
|
72 |
#define FCVAR_NOT_CONNECTED (1<<22) // cvar cannot be changed by a client that is connected to a server |
|
ds@457
|
73 |
|
|
ds@457
|
74 |
#define FCVAR_ARCHIVE_XBOX (1<<24) // cvar written to config.cfg on the Xbox |
|
ds@457
|
75 |
|
|
ds@457
|
76 |
|
|
ds@457
|
77 |
// #define FCVAR_AVAILABLE (1<<27) |
|
ds@457
|
78 |
// #define FCVAR_AVAILABLE (1<<28) |
|
ds@457
|
79 |
// #define FCVAR_AVAILABLE (1<<29) |
|
ds@457
|
80 |
// #define FCVAR_AVAILABLE (1<<30) |
|
ds@457
|
81 |
// #define FCVAR_AVAILABLE (1<<31) |
|
ds@457
|
82 |
|
|
ds@457
|
83 |
|
|
ds@457
|
84 |
class ConVar; |
|
ds@457
|
85 |
class ConCommand; |
|
ds@457
|
86 |
class ConCommandBase; |
|
ds@457
|
87 |
|
|
ds@457
|
88 |
// Any executable that wants to use ConVars need to implement one of |
|
ds@457
|
89 |
// these to hook up access to console variables. |
|
ds@457
|
90 |
class IConCommandBaseAccessor |
|
ds@457
|
91 |
{ |
|
ds@457
|
92 |
public: |
|
ds@457
|
93 |
// Flags is a combination of FCVAR flags in cvar.h. |
|
ds@457
|
94 |
// hOut is filled in with a handle to the variable. |
|
ds@457
|
95 |
virtual bool RegisterConCommandBase( ConCommandBase *pVar )=0; |
|
ds@457
|
96 |
}; |
|
ds@457
|
97 |
|
|
ds@457
|
98 |
|
|
ds@457
|
99 |
// You don't have to instantiate one of these, just call its |
|
ds@457
|
100 |
// OneTimeInit function when your executable is initializing. |
|
ds@457
|
101 |
class ConCommandBaseMgr |
|
ds@457
|
102 |
{ |
|
ds@457
|
103 |
public: |
|
ds@457
|
104 |
// Call this ONCE when the executable starts up. |
|
ds@457
|
105 |
static void OneTimeInit( IConCommandBaseAccessor *pAccessor ); |
|
ds@457
|
106 |
#ifdef _XBOX |
|
ds@457
|
107 |
static bool Fixup( ConCommandBase* pConCommandBase ); |
|
ds@457
|
108 |
#ifndef _RETAIL |
|
ds@457
|
109 |
static void PublishCommands( bool bForce ); |
|
ds@457
|
110 |
#endif |
|
ds@457
|
111 |
#endif |
|
ds@457
|
112 |
}; |
|
ds@457
|
113 |
|
|
ds@457
|
114 |
// Called when a ConVar changes value |
|
ds@457
|
115 |
typedef void ( *FnChangeCallback )( ConVar *var, char const *pOldString ); |
|
ds@457
|
116 |
|
|
ds@457
|
117 |
// Called when a ConCommand needs to execute |
|
ds@457
|
118 |
typedef void ( *FnCommandCallback )( void ); |
|
ds@457
|
119 |
|
|
ds@457
|
120 |
#define COMMAND_COMPLETION_MAXITEMS 64 |
|
ds@457
|
121 |
#define COMMAND_COMPLETION_ITEM_LENGTH 64 |
|
ds@457
|
122 |
|
|
ds@457
|
123 |
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings |
|
ds@457
|
124 |
typedef int ( *FnCommandCompletionCallback )( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); |
|
ds@457
|
125 |
|
|
ds@457
|
126 |
//----------------------------------------------------------------------------- |
|
ds@457
|
127 |
// Purpose: The base console invoked command/cvar interface |
|
ds@457
|
128 |
//----------------------------------------------------------------------------- |
|
ds@457
|
129 |
class ConCommandBase |
|
ds@457
|
130 |
{ |
|
ds@457
|
131 |
friend class ConCommandBaseMgr; |
|
ds@457
|
132 |
friend class CCvar; |
|
ds@457
|
133 |
friend class ConVar; |
|
ds@457
|
134 |
friend class ConCommand; |
|
ds@457
|
135 |
|
|
ds@457
|
136 |
public: |
|
ds@457
|
137 |
ConCommandBase( void ); |
|
ds@457
|
138 |
ConCommandBase( char const *pName, char const *pHelpString = 0, |
|
ds@457
|
139 |
int flags = 0 ); |
|
ds@457
|
140 |
|
|
ds@457
|
141 |
virtual ~ConCommandBase( void ); |
|
ds@457
|
142 |
|
|
ds@457
|
143 |
virtual bool IsCommand( void ) const; |
|
ds@457
|
144 |
|
|
ds@457
|
145 |
// Check flag |
|
ds@457
|
146 |
virtual bool IsBitSet( int flag ) const; |
|
ds@457
|
147 |
// Set flag |
|
ds@457
|
148 |
virtual void AddFlags( int flags ); |
|
ds@457
|
149 |
|
|
ds@457
|
150 |
// Return name of cvar |
|
ds@457
|
151 |
virtual char const *GetName( void ) const; |
|
ds@457
|
152 |
|
|
ds@457
|
153 |
// Return help text for cvar |
|
ds@457
|
154 |
virtual char const *GetHelpText( void ) const; |
|
ds@457
|
155 |
|
|
ds@457
|
156 |
// Deal with next pointer |
|
ds@457
|
157 |
const ConCommandBase *GetNext( void ) const; |
|
ds@457
|
158 |
void SetNext( ConCommandBase *next ); |
|
ds@457
|
159 |
|
|
ds@457
|
160 |
virtual bool IsRegistered( void ) const; |
|
ds@457
|
161 |
|
|
ds@457
|
162 |
// Global methods |
|
ds@457
|
163 |
static ConCommandBase const *GetCommands( void ); |
|
ds@457
|
164 |
static void AddToList( ConCommandBase *var ); |
|
ds@457
|
165 |
static void RemoveFlaggedCommands( int flag ); |
|
ds@457
|
166 |
static void RevertFlaggedCvars( int flag ); |
|
ds@457
|
167 |
static ConCommandBase const *FindCommand( char const *name ); |
|
ds@457
|
168 |
|
|
ds@457
|
169 |
protected: |
|
ds@457
|
170 |
virtual void Create( char const *pName, char const *pHelpString = 0, |
|
ds@457
|
171 |
int flags = 0 ); |
|
ds@457
|
172 |
|
|
ds@457
|
173 |
// Used internally by OneTimeInit to initialize. |
|
ds@457
|
174 |
virtual void Init(); |
|
ds@457
|
175 |
|
|
ds@457
|
176 |
// Internal copy routine ( uses new operator from correct module ) |
|
ds@457
|
177 |
char *CopyString( char const *from ); |
|
ds@457
|
178 |
|
|
ds@457
|
179 |
// Next ConVar in chain |
|
ds@457
|
180 |
ConCommandBase *m_pNext; |
|
ds@457
|
181 |
|
|
ds@457
|
182 |
private: |
|
ds@457
|
183 |
// Has the cvar been added to the global list? |
|
ds@457
|
184 |
bool m_bRegistered; |
|
ds@457
|
185 |
|
|
ds@457
|
186 |
// Static data |
|
ds@457
|
187 |
char const *m_pszName; |
|
ds@457
|
188 |
char const *m_pszHelpString; |
|
ds@457
|
189 |
|
|
ds@457
|
190 |
// ConVar flags |
|
ds@457
|
191 |
int m_nFlags; |
|
ds@457
|
192 |
|
|
ds@457
|
193 |
protected: |
|
ds@457
|
194 |
|
|
ds@457
|
195 |
// ConVars add themselves to this list for the executable. Then ConVarMgr::Init() runs through |
|
ds@457
|
196 |
// all the console variables and registers them. |
|
ds@457
|
197 |
static ConCommandBase *s_pConCommandBases; |
|
ds@457
|
198 |
|
|
ds@457
|
199 |
// ConVars in this executable use this 'global' to access values. |
|
ds@457
|
200 |
static IConCommandBaseAccessor *s_pAccessor; |
|
ds@457
|
201 |
|
|
ds@457
|
202 |
public: // Hackalicous |
|
ds@714
|
203 |
inline int GetFlags() |
|
ds@714
|
204 |
{ |
|
ds@714
|
205 |
return m_nFlags; |
|
ds@714
|
206 |
} |
|
ds@714
|
207 |
inline void SetFlags(int flags) |
|
ds@714
|
208 |
{ |
|
ds@714
|
209 |
m_nFlags = flags; |
|
ds@714
|
210 |
} |
|
ds@457
|
211 |
}; |
|
ds@457
|
212 |
|
|
ds@457
|
213 |
//----------------------------------------------------------------------------- |
|
ds@457
|
214 |
// Purpose: The console invoked command |
|
ds@457
|
215 |
//----------------------------------------------------------------------------- |
|
ds@457
|
216 |
class ConCommand : public ConCommandBase |
|
ds@457
|
217 |
{ |
|
ds@457
|
218 |
friend class ConCommandBaseMgr; |
|
ds@457
|
219 |
friend class CCvar; |
|
ds@457
|
220 |
#ifdef _STATIC_LINKED |
|
ds@457
|
221 |
friend class G_ConCommand; |
|
ds@457
|
222 |
friend class C_ConCommand; |
|
ds@457
|
223 |
friend class M_ConCommand; |
|
ds@457
|
224 |
friend class S_ConCommand; |
|
ds@457
|
225 |
friend class D_ConCommand; |
|
ds@457
|
226 |
#endif |
|
ds@457
|
227 |
|
|
ds@457
|
228 |
public: |
|
ds@457
|
229 |
typedef ConCommandBase BaseClass; |
|
ds@457
|
230 |
|
|
ds@457
|
231 |
ConCommand( void ); |
|
ds@457
|
232 |
ConCommand( char const *pName, FnCommandCallback callback, |
|
ds@457
|
233 |
char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); |
|
ds@457
|
234 |
|
|
ds@457
|
235 |
virtual ~ConCommand( void ); |
|
ds@457
|
236 |
|
|
ds@457
|
237 |
virtual bool IsCommand( void ) const; |
|
ds@457
|
238 |
|
|
ds@457
|
239 |
virtual int AutoCompleteSuggest( char const *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); |
|
ds@457
|
240 |
|
|
ds@457
|
241 |
virtual bool CanAutoComplete( void ); |
|
ds@457
|
242 |
|
|
ds@457
|
243 |
// Invoke the function |
|
ds@457
|
244 |
virtual void Dispatch( void ); |
|
ds@457
|
245 |
private: |
|
ds@457
|
246 |
virtual void Create( char const *pName, FnCommandCallback callback, |
|
ds@457
|
247 |
char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); |
|
ds@457
|
248 |
|
|
ds@457
|
249 |
// Call this function when executing the command |
|
ds@457
|
250 |
FnCommandCallback m_fnCommandCallback; |
|
ds@457
|
251 |
|
|
ds@457
|
252 |
FnCommandCompletionCallback m_fnCompletionCallback; |
|
ds@457
|
253 |
bool m_bHasCompletionCallback; |
|
ds@457
|
254 |
public: // Hackalicous |
|
ds@714
|
255 |
inline FnCommandCallback GetCallback() |
|
ds@714
|
256 |
{ |
|
ds@714
|
257 |
return m_fnCommandCallback; |
|
ds@714
|
258 |
} |
|
ds@457
|
259 |
}; |
|
ds@457
|
260 |
|
|
ds@457
|
261 |
//----------------------------------------------------------------------------- |
|
ds@457
|
262 |
// Purpose: A console variable |
|
ds@457
|
263 |
//----------------------------------------------------------------------------- |
|
ds@457
|
264 |
class ConVar : public ConCommandBase |
|
ds@457
|
265 |
{ |
|
ds@457
|
266 |
friend class ConCommandBaseMgr; |
|
ds@457
|
267 |
friend class CCvar; |
|
ds@457
|
268 |
friend class CDefaultCvar; |
|
ds@457
|
269 |
#ifdef _STATIC_LINKED |
|
ds@457
|
270 |
friend class G_ConVar; |
|
ds@457
|
271 |
friend class C_ConVar; |
|
ds@457
|
272 |
friend class M_ConVar; |
|
ds@457
|
273 |
friend class S_ConVar; |
|
ds@457
|
274 |
friend class D_ConVar; |
|
ds@457
|
275 |
#endif |
|
ds@457
|
276 |
|
|
ds@457
|
277 |
public: |
|
ds@457
|
278 |
typedef ConCommandBase BaseClass; |
|
ds@457
|
279 |
|
|
ds@457
|
280 |
ConVar( char const *pName, char const *pDefaultValue, int flags = 0); |
|
ds@457
|
281 |
|
|
ds@457
|
282 |
ConVar( char const *pName, char const *pDefaultValue, int flags, |
|
ds@457
|
283 |
char const *pHelpString ); |
|
ds@457
|
284 |
ConVar( char const *pName, char const *pDefaultValue, int flags, |
|
ds@457
|
285 |
char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); |
|
ds@457
|
286 |
ConVar( char const *pName, char const *pDefaultValue, int flags, |
|
ds@457
|
287 |
char const *pHelpString, FnChangeCallback callback ); |
|
ds@457
|
288 |
ConVar( char const *pName, char const *pDefaultValue, int flags, |
|
ds@457
|
289 |
char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, |
|
ds@457
|
290 |
FnChangeCallback callback ); |
|
ds@457
|
291 |
|
|
ds@457
|
292 |
virtual ~ConVar( void ); |
|
ds@457
|
293 |
|
|
ds@457
|
294 |
virtual bool IsBitSet( int flag ) const; |
|
ds@457
|
295 |
virtual char const* GetHelpText( void ) const; |
|
ds@457
|
296 |
virtual bool IsRegistered( void ) const; |
|
ds@457
|
297 |
virtual char const *GetName( void ) const; |
|
ds@457
|
298 |
virtual void AddFlags( int flags ); |
|
ds@457
|
299 |
virtual bool IsCommand( void ) const; |
|
ds@457
|
300 |
|
|
ds@457
|
301 |
// Install a change callback (there shouldn't already be one....) |
|
ds@457
|
302 |
void InstallChangeCallback( FnChangeCallback callback ); |
|
ds@457
|
303 |
|
|
ds@457
|
304 |
// Retrieve value |
|
ds@457
|
305 |
FORCEINLINE_CVAR float GetFloat( void ) const; |
|
ds@457
|
306 |
FORCEINLINE_CVAR int GetInt( void ) const; |
|
ds@457
|
307 |
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } |
|
ds@457
|
308 |
FORCEINLINE_CVAR char const *GetString( void ) const; |
|
ds@457
|
309 |
|
|
ds@457
|
310 |
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes |
|
ds@457
|
311 |
// from alloc/free across dll/exe boundaries. |
|
ds@457
|
312 |
|
|
ds@457
|
313 |
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). |
|
ds@457
|
314 |
virtual void SetValue( char const *value ); |
|
ds@457
|
315 |
virtual void SetValue( float value ); |
|
ds@457
|
316 |
virtual void SetValue( int value ); |
|
ds@457
|
317 |
|
|
ds@457
|
318 |
// Reset to default value |
|
ds@457
|
319 |
void Revert( void ); |
|
ds@457
|
320 |
|
|
ds@457
|
321 |
// True if it has a min/max setting |
|
ds@457
|
322 |
bool GetMin( float& minVal ) const; |
|
ds@457
|
323 |
bool GetMax( float& maxVal ) const; |
|
ds@457
|
324 |
char const *GetDefault( void ) const; |
|
ds@457
|
325 |
|
|
ds@457
|
326 |
static void RevertAll( void ); |
|
ds@457
|
327 |
private: |
|
ds@457
|
328 |
// Called by CCvar when the value of a var is changing. |
|
ds@457
|
329 |
virtual void InternalSetValue(char const *value); |
|
ds@457
|
330 |
// For CVARs marked FCVAR_NEVER_AS_STRING |
|
ds@457
|
331 |
virtual void InternalSetFloatValue( float fNewValue ); |
|
ds@457
|
332 |
virtual void InternalSetIntValue( int nValue ); |
|
ds@457
|
333 |
|
|
ds@457
|
334 |
virtual bool ClampValue( float& value ); |
|
ds@457
|
335 |
virtual void ChangeStringValue( char const *tempVal ); |
|
ds@457
|
336 |
|
|
ds@457
|
337 |
virtual void Create( char const *pName, char const *pDefaultValue, int flags = 0, |
|
ds@457
|
338 |
char const *pHelpString = 0, bool bMin = false, float fMin = 0.0, |
|
ds@457
|
339 |
bool bMax = false, float fMax = false, FnChangeCallback callback = 0 ); |
|
ds@457
|
340 |
|
|
ds@457
|
341 |
// Used internally by OneTimeInit to initialize. |
|
ds@457
|
342 |
virtual void Init(); |
|
ds@457
|
343 |
|
|
ds@457
|
344 |
private: |
|
ds@457
|
345 |
|
|
ds@457
|
346 |
// This either points to "this" or it points to the original declaration of a ConVar. |
|
ds@457
|
347 |
// This allows ConVars to exist in separate modules, and they all use the first one to be declared. |
|
ds@457
|
348 |
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). |
|
ds@457
|
349 |
ConVar *m_pParent; |
|
ds@457
|
350 |
|
|
ds@457
|
351 |
// Static data |
|
ds@457
|
352 |
char const *m_pszDefaultValue; |
|
ds@457
|
353 |
|
|
ds@457
|
354 |
// Value |
|
ds@457
|
355 |
// Dynamically allocated |
|
ds@457
|
356 |
char *m_pszString; |
|
ds@457
|
357 |
int m_StringLength; |
|
ds@457
|
358 |
|
|
ds@457
|
359 |
// Values |
|
ds@457
|
360 |
float m_fValue; |
|
ds@457
|
361 |
int m_nValue; |
|
ds@457
|
362 |
|
|
ds@457
|
363 |
// Min/Max values |
|
ds@457
|
364 |
bool m_bHasMin; |
|
ds@457
|
365 |
float m_fMinVal; |
|
ds@457
|
366 |
bool m_bHasMax; |
|
ds@457
|
367 |
float m_fMaxVal; |
|
ds@457
|
368 |
|
|
ds@457
|
369 |
// Call this function when ConVar changes |
|
ds@457
|
370 |
FnChangeCallback m_fnChangeCallback; |
|
ds@457
|
371 |
public: // Hackalicous |
|
ds@714
|
372 |
inline FnChangeCallback GetCallback() |
|
ds@714
|
373 |
{ |
|
ds@714
|
374 |
return m_fnChangeCallback; |
|
ds@714
|
375 |
} |
|
ds@714
|
376 |
inline void SetMin(bool set, float min) |
|
ds@714
|
377 |
{ |
|
ds@714
|
378 |
m_bHasMin = set; |
|
ds@714
|
379 |
m_fMinVal = min; |
|
ds@714
|
380 |
} |
|
ds@714
|
381 |
inline void SetMax(bool set, float max) |
|
ds@714
|
382 |
{ |
|
ds@714
|
383 |
m_bHasMax = set; |
|
ds@714
|
384 |
m_fMaxVal = max; |
|
ds@714
|
385 |
} |
|
ds@457
|
386 |
}; |
|
ds@457
|
387 |
|
|
ds@457
|
388 |
|
|
ds@457
|
389 |
//----------------------------------------------------------------------------- |
|
ds@457
|
390 |
// Purpose: Return ConVar value as a float |
|
ds@457
|
391 |
// Output : float |
|
ds@457
|
392 |
//----------------------------------------------------------------------------- |
|
ds@457
|
393 |
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const |
|
ds@457
|
394 |
{ |
|
ds@457
|
395 |
return m_pParent->m_fValue; |
|
ds@457
|
396 |
} |
|
ds@457
|
397 |
|
|
ds@457
|
398 |
//----------------------------------------------------------------------------- |
|
ds@457
|
399 |
// Purpose: Return ConVar value as an int |
|
ds@457
|
400 |
// Output : int |
|
ds@457
|
401 |
//----------------------------------------------------------------------------- |
|
ds@457
|
402 |
FORCEINLINE_CVAR int ConVar::GetInt( void ) const |
|
ds@457
|
403 |
{ |
|
ds@457
|
404 |
return m_pParent->m_nValue; |
|
ds@457
|
405 |
} |
|
ds@457
|
406 |
|
|
ds@457
|
407 |
|
|
ds@457
|
408 |
//----------------------------------------------------------------------------- |
|
ds@457
|
409 |
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. |
|
ds@457
|
410 |
// Output : char const * |
|
ds@457
|
411 |
//----------------------------------------------------------------------------- |
|
ds@457
|
412 |
FORCEINLINE_CVAR char const *ConVar::GetString( void ) const |
|
ds@457
|
413 |
{ |
|
ds@457
|
414 |
if ( m_nFlags & FCVAR_NEVER_AS_STRING ) |
|
ds@457
|
415 |
{ |
|
ds@457
|
416 |
return "FCVAR_NEVER_AS_STRING"; |
|
ds@457
|
417 |
} |
|
ds@457
|
418 |
|
|
ds@457
|
419 |
return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; |
|
ds@457
|
420 |
} |
|
ds@457
|
421 |
|
|
ds@457
|
422 |
|
|
ds@457
|
423 |
#ifdef _STATIC_LINKED |
|
ds@457
|
424 |
// identifies subsystem via piggybacking constructors with flags |
|
ds@457
|
425 |
class G_ConCommand : public ConCommand |
|
ds@457
|
426 |
{ |
|
ds@457
|
427 |
public: |
|
ds@457
|
428 |
G_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_GAMEDLL, completionFunc) {} |
|
ds@457
|
429 |
}; |
|
ds@457
|
430 |
|
|
ds@457
|
431 |
class C_ConCommand : public ConCommand |
|
ds@457
|
432 |
{ |
|
ds@457
|
433 |
public: |
|
ds@457
|
434 |
C_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_CLIENTDLL, completionFunc) {} |
|
ds@457
|
435 |
}; |
|
ds@457
|
436 |
|
|
ds@457
|
437 |
class M_ConCommand : public ConCommand |
|
ds@457
|
438 |
{ |
|
ds@457
|
439 |
public: |
|
ds@457
|
440 |
M_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_MATERIAL_SYSTEM, completionFunc) {} |
|
ds@457
|
441 |
}; |
|
ds@457
|
442 |
|
|
ds@457
|
443 |
class S_ConCommand : public ConCommand |
|
ds@457
|
444 |
{ |
|
ds@457
|
445 |
public: |
|
ds@457
|
446 |
S_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_STUDIORENDER, completionFunc) {} |
|
ds@457
|
447 |
}; |
|
ds@457
|
448 |
|
|
ds@457
|
449 |
class D_ConCommand : public ConCommand |
|
ds@457
|
450 |
{ |
|
ds@457
|
451 |
public: |
|
ds@457
|
452 |
D_ConCommand(char const *pName, FnCommandCallback callback, char const *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ) : ConCommand(pName, callback, pHelpString, flags|FCVAR_DATACACHE, completionFunc) {} |
|
ds@457
|
453 |
}; |
|
ds@457
|
454 |
|
|
ds@457
|
455 |
typedef void ( *G_FnChangeCallback )( G_ConVar *var, char const *pOldString ); |
|
ds@457
|
456 |
typedef void ( *C_FnChangeCallback )( C_ConVar *var, char const *pOldString ); |
|
ds@457
|
457 |
typedef void ( *M_FnChangeCallback )( M_ConVar *var, char const *pOldString ); |
|
ds@457
|
458 |
typedef void ( *S_FnChangeCallback )( S_ConVar *var, char const *pOldString ); |
|
ds@457
|
459 |
typedef void ( *D_FnChangeCallback )( D_ConVar *var, char const *pOldString ); |
|
ds@457
|
460 |
|
|
ds@457
|
461 |
class G_ConVar : public ConVar |
|
ds@457
|
462 |
{ |
|
ds@457
|
463 |
public: |
|
ds@457
|
464 |
G_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL) {} |
|
ds@457
|
465 |
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString ) {} |
|
ds@457
|
466 |
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, bMin, fMin, bMax, fMax) {} |
|
ds@457
|
467 |
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, G_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, (FnChangeCallback)callback ) {} |
|
ds@457
|
468 |
G_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, G_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_GAMEDLL, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {} |
|
ds@457
|
469 |
}; |
|
ds@457
|
470 |
|
|
ds@457
|
471 |
class C_ConVar : public ConVar |
|
ds@457
|
472 |
{ |
|
ds@457
|
473 |
public: |
|
ds@457
|
474 |
C_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL) {} |
|
ds@457
|
475 |
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString ) {} |
|
ds@457
|
476 |
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, bMin, fMin, bMax, fMax) {} |
|
ds@457
|
477 |
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, C_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, (FnChangeCallback)callback ) {} |
|
ds@457
|
478 |
C_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, C_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_CLIENTDLL, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {} |
|
ds@457
|
479 |
}; |
|
ds@457
|
480 |
|
|
ds@457
|
481 |
class M_ConVar : public ConVar |
|
ds@457
|
482 |
{ |
|
ds@457
|
483 |
public: |
|
ds@457
|
484 |
M_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM) {} |
|
ds@457
|
485 |
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString ) {} |
|
ds@457
|
486 |
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, bMin, fMin, bMax, fMax) {} |
|
ds@457
|
487 |
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, (FnChangeCallback)callback ) {} |
|
ds@457
|
488 |
M_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_MATERIAL_SYSTEM, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {} |
|
ds@457
|
489 |
}; |
|
ds@457
|
490 |
|
|
ds@457
|
491 |
class S_ConVar : public ConVar |
|
ds@457
|
492 |
{ |
|
ds@457
|
493 |
public: |
|
ds@457
|
494 |
S_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER) {} |
|
ds@457
|
495 |
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString ) {} |
|
ds@457
|
496 |
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, bMin, fMin, bMax, fMax) {} |
|
ds@457
|
497 |
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, (FnChangeCallback)callback ) {} |
|
ds@457
|
498 |
S_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, S_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_STUDIORENDER, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {} |
|
ds@457
|
499 |
}; |
|
ds@457
|
500 |
|
|
ds@457
|
501 |
class D_ConVar : public ConVar |
|
ds@457
|
502 |
{ |
|
ds@457
|
503 |
public: |
|
ds@457
|
504 |
D_ConVar( char const *pName, char const *pDefaultValue, int flags = 0) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE) {} |
|
ds@457
|
505 |
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString ) {} |
|
ds@457
|
506 |
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, bMin, fMin, bMax, fMax) {} |
|
ds@457
|
507 |
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, M_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, (FnChangeCallback)callback ) {} |
|
ds@457
|
508 |
D_ConVar( char const *pName, char const *pDefaultValue, int flags, char const *pHelpString, bool bMin, float fMin, bool bMax, float fMax, D_FnChangeCallback callback ) : ConVar(pName, pDefaultValue, flags|FCVAR_DATACACHE, pHelpString, bMin, fMin, bMax, fMax, (FnChangeCallback)callback ) {} |
|
ds@457
|
509 |
}; |
|
ds@457
|
510 |
|
|
ds@457
|
511 |
// redirect these declarations to their specific subsystem |
|
ds@457
|
512 |
#ifdef GAME_DLL |
|
ds@457
|
513 |
#define ConCommand G_ConCommand |
|
ds@457
|
514 |
#define ConVar G_ConVar |
|
ds@457
|
515 |
#endif |
|
ds@457
|
516 |
#ifdef CLIENT_DLL |
|
ds@457
|
517 |
#define ConCommand C_ConCommand |
|
ds@457
|
518 |
#define ConVar C_ConVar |
|
ds@457
|
519 |
#endif |
|
ds@457
|
520 |
#ifdef MATERIALSYSTEM_DLL |
|
ds@457
|
521 |
#define ConCommand M_ConCommand |
|
ds@457
|
522 |
#define ConVar M_ConVar |
|
ds@457
|
523 |
#endif |
|
ds@457
|
524 |
#ifdef STUDIORENDER_DLL |
|
ds@457
|
525 |
#define ConCommand S_ConCommand |
|
ds@457
|
526 |
#define ConVar S_ConVar |
|
ds@457
|
527 |
#endif |
|
ds@457
|
528 |
#ifdef DATACACHE_DLL |
|
ds@457
|
529 |
#define ConCommand D_ConCommand |
|
ds@457
|
530 |
#define ConVar D_ConVar |
|
ds@457
|
531 |
#endif |
|
ds@457
|
532 |
#endif // _STATIC_LINKED |
|
ds@457
|
533 |
|
|
ds@457
|
534 |
//----------------------------------------------------------------------------- |
|
ds@457
|
535 |
// Purpose: Utility to quicky generate a simple console command |
|
ds@457
|
536 |
//----------------------------------------------------------------------------- |
|
ds@457
|
537 |
#define CON_COMMAND( name, description ) \ |
|
ds@457
|
538 |
static void name(); \ |
|
ds@457
|
539 |
static ConCommand name##_command( #name, name, description ); \ |
|
ds@457
|
540 |
static void name() |
|
ds@457
|
541 |
|
|
ds@457
|
542 |
//----------------------------------------------------------------------------- |
|
ds@457
|
543 |
// Purpose: Utility to quicky generate a simple console command |
|
ds@457
|
544 |
//----------------------------------------------------------------------------- |
|
ds@457
|
545 |
#define CON_COMMAND_F( name, description, flags ) \ |
|
ds@457
|
546 |
static void name(); \ |
|
ds@457
|
547 |
static ConCommand name##_command( #name, name, description, flags ); \ |
|
ds@457
|
548 |
static void name() |
|
ds@457
|
549 |
|
|
ds@457
|
550 |
|
|
ds@457
|
551 |
#endif // CONVAR_H |