|
skamonkey@3899
|
1 |
//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======// |
|
skamonkey@3899
|
2 |
// |
|
skamonkey@3899
|
3 |
// Purpose: |
|
skamonkey@3899
|
4 |
// |
|
skamonkey@3899
|
5 |
// $Workfile: $ |
|
skamonkey@3899
|
6 |
// $Date: $ |
|
skamonkey@3899
|
7 |
// |
|
skamonkey@3899
|
8 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
9 |
// $NoKeywords: $ |
|
skamonkey@3899
|
10 |
//===========================================================================// |
|
skamonkey@3899
|
11 |
|
|
skamonkey@3899
|
12 |
#ifndef CONVAR_H |
|
skamonkey@3899
|
13 |
#define CONVAR_H |
|
skamonkey@3899
|
14 |
|
|
skamonkey@3899
|
15 |
#if _WIN32 |
|
skamonkey@3899
|
16 |
#pragma once |
|
skamonkey@3899
|
17 |
#endif |
|
skamonkey@3899
|
18 |
|
|
skamonkey@3899
|
19 |
#include "tier0/dbg.h" |
|
skamonkey@3899
|
20 |
#include "tier1/iconvar.h" |
|
skamonkey@3899
|
21 |
#include "tier1/utlvector.h" |
|
skamonkey@3899
|
22 |
#include "tier1/utlstring.h" |
|
skamonkey@3899
|
23 |
#include "Color.h" |
|
skamonkey@3899
|
24 |
#include "icvar.h" |
|
skamonkey@3899
|
25 |
|
|
skamonkey@3899
|
26 |
#ifdef _WIN32 |
|
skamonkey@3899
|
27 |
#define FORCEINLINE_CVAR FORCEINLINE |
|
skamonkey@3899
|
28 |
#elif POSIX |
|
skamonkey@3899
|
29 |
#define FORCEINLINE_CVAR inline |
|
skamonkey@3899
|
30 |
#else |
|
skamonkey@3899
|
31 |
#error "implement me" |
|
skamonkey@3899
|
32 |
#endif |
|
skamonkey@3899
|
33 |
|
|
skamonkey@3899
|
34 |
|
|
skamonkey@3899
|
35 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
36 |
// Uncomment me to test for threading issues for material system convars |
|
skamonkey@3899
|
37 |
// NOTE: You want to disable all threading when you do this |
|
skamonkey@3899
|
38 |
// +host_thread_mode 0 +r_threaded_particles 0 +sv_parallel_packentities 0 +sv_disable_querycache 0 |
|
skamonkey@3899
|
39 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
40 |
//#define CONVAR_TEST_MATERIAL_THREAD_CONVARS 1 |
|
skamonkey@3899
|
41 |
|
|
skamonkey@3899
|
42 |
|
|
skamonkey@3899
|
43 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
44 |
// Forward declarations |
|
skamonkey@3899
|
45 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
46 |
class ConVar; |
|
skamonkey@3899
|
47 |
class CCommand; |
|
skamonkey@3899
|
48 |
class ConCommand; |
|
skamonkey@3899
|
49 |
class ConCommandBase; |
|
skamonkey@3899
|
50 |
struct characterset_t; |
|
skamonkey@3899
|
51 |
|
|
skamonkey@3942
|
52 |
struct CCommandContext |
|
skamonkey@3942
|
53 |
{ |
|
skamonkey@3942
|
54 |
CCommandContext( int index ) |
|
skamonkey@3942
|
55 |
{ |
|
skamonkey@3942
|
56 |
_index = index; |
|
skamonkey@3942
|
57 |
} |
|
skamonkey@3942
|
58 |
|
|
skamonkey@3942
|
59 |
int Get() const |
|
skamonkey@3942
|
60 |
{ |
|
skamonkey@3942
|
61 |
return _index; |
|
skamonkey@3942
|
62 |
} |
|
skamonkey@3942
|
63 |
|
|
skamonkey@3942
|
64 |
private: |
|
skamonkey@3942
|
65 |
int _index; |
|
skamonkey@3942
|
66 |
}; |
|
skamonkey@3942
|
67 |
|
|
skamonkey@3899
|
68 |
|
|
skamonkey@3899
|
69 |
|
|
skamonkey@3899
|
70 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
71 |
// Any executable that wants to use ConVars need to implement one of |
|
skamonkey@3899
|
72 |
// these to hook up access to console variables. |
|
skamonkey@3899
|
73 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
74 |
class IConCommandBaseAccessor |
|
skamonkey@3899
|
75 |
{ |
|
skamonkey@3899
|
76 |
public: |
|
skamonkey@3899
|
77 |
// Flags is a combination of FCVAR flags in cvar.h. |
|
skamonkey@3899
|
78 |
// hOut is filled in with a handle to the variable. |
|
skamonkey@3899
|
79 |
virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0; |
|
skamonkey@3899
|
80 |
}; |
|
skamonkey@3899
|
81 |
|
|
skamonkey@3899
|
82 |
|
|
skamonkey@3899
|
83 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
84 |
// Helper method for console development |
|
skamonkey@3899
|
85 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
86 |
#if defined( _X360 ) |
|
skamonkey@3899
|
87 |
void ConVar_PublishToVXConsole(); |
|
skamonkey@3899
|
88 |
#endif |
|
skamonkey@3899
|
89 |
|
|
skamonkey@3899
|
90 |
|
|
skamonkey@3899
|
91 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
92 |
// Called when a ConCommand needs to execute |
|
skamonkey@3899
|
93 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
94 |
typedef void ( *FnCommandCallbackV1_t )( void ); |
|
skamonkey@3942
|
95 |
typedef void ( *FnCommandCallback_t )( const CCommandContext &context, const CCommand &command ); |
|
skamonkey@3899
|
96 |
|
|
skamonkey@3899
|
97 |
#define COMMAND_COMPLETION_MAXITEMS 64 |
|
skamonkey@3899
|
98 |
#define COMMAND_COMPLETION_ITEM_LENGTH 64 |
|
skamonkey@3899
|
99 |
|
|
skamonkey@3899
|
100 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
101 |
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings |
|
skamonkey@3899
|
102 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
103 |
typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); |
|
skamonkey@3899
|
104 |
|
|
skamonkey@3899
|
105 |
|
|
skamonkey@3899
|
106 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
107 |
// Interface version |
|
skamonkey@3899
|
108 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
109 |
class ICommandCallback |
|
skamonkey@3899
|
110 |
{ |
|
skamonkey@3899
|
111 |
public: |
|
skamonkey@3899
|
112 |
virtual void CommandCallback( const CCommand &command ) = 0; |
|
skamonkey@3899
|
113 |
}; |
|
skamonkey@3899
|
114 |
|
|
skamonkey@3899
|
115 |
class ICommandCallback2 |
|
skamonkey@3899
|
116 |
{ |
|
skamonkey@3899
|
117 |
public: |
|
skamonkey@3942
|
118 |
virtual void CommandCallback( const CCommandContext &context, const CCommand &command ) = 0; |
|
skamonkey@3899
|
119 |
}; |
|
skamonkey@3899
|
120 |
|
|
skamonkey@3899
|
121 |
class ICommandCompletionCallback |
|
skamonkey@3899
|
122 |
{ |
|
skamonkey@3899
|
123 |
public: |
|
skamonkey@3899
|
124 |
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0; |
|
skamonkey@3899
|
125 |
}; |
|
skamonkey@3899
|
126 |
|
|
skamonkey@3899
|
127 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
128 |
// Purpose: The base console invoked command/cvar interface |
|
skamonkey@3899
|
129 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
130 |
class ConCommandBase |
|
skamonkey@3899
|
131 |
{ |
|
skamonkey@3899
|
132 |
friend class CCvar; |
|
skamonkey@3899
|
133 |
friend class ConVar; |
|
skamonkey@3899
|
134 |
friend class ConCommand; |
|
skamonkey@3899
|
135 |
friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor ); |
|
skamonkey@3899
|
136 |
friend void ConVar_PublishToVXConsole(); |
|
skamonkey@3899
|
137 |
|
|
skamonkey@3899
|
138 |
// FIXME: Remove when ConVar changes are done |
|
skamonkey@3899
|
139 |
friend class CDefaultCvar; |
|
skamonkey@3899
|
140 |
|
|
skamonkey@3899
|
141 |
public: |
|
skamonkey@3899
|
142 |
ConCommandBase( void ); |
|
skamonkey@3899
|
143 |
ConCommandBase( const char *pName, const char *pHelpString = 0, |
|
skamonkey@3899
|
144 |
int flags = 0 ); |
|
skamonkey@3899
|
145 |
|
|
skamonkey@3899
|
146 |
virtual ~ConCommandBase( void ); |
|
skamonkey@3899
|
147 |
|
|
skamonkey@3899
|
148 |
virtual bool IsCommand( void ) const; |
|
skamonkey@3899
|
149 |
|
|
skamonkey@3899
|
150 |
// Check flag |
|
skamonkey@3899
|
151 |
virtual bool IsFlagSet( int flag ) const; |
|
skamonkey@3899
|
152 |
// Set flag |
|
skamonkey@3899
|
153 |
virtual void AddFlags( int flags ); |
|
skamonkey@3899
|
154 |
// Clear flag |
|
skamonkey@3899
|
155 |
virtual void RemoveFlags( int flags ); |
|
skamonkey@3899
|
156 |
|
|
skamonkey@3899
|
157 |
virtual int GetFlags() const; |
|
skamonkey@3899
|
158 |
|
|
skamonkey@3899
|
159 |
// Return name of cvar |
|
skamonkey@3899
|
160 |
virtual const char *GetName( void ) const; |
|
skamonkey@3899
|
161 |
|
|
skamonkey@3899
|
162 |
// Return help text for cvar |
|
skamonkey@3899
|
163 |
virtual const char *GetHelpText( void ) const; |
|
skamonkey@3899
|
164 |
|
|
skamonkey@3899
|
165 |
// Deal with next pointer |
|
skamonkey@3899
|
166 |
const ConCommandBase *GetNext( void ) const; |
|
skamonkey@3899
|
167 |
ConCommandBase *GetNext( void ); |
|
skamonkey@3899
|
168 |
|
|
skamonkey@3899
|
169 |
virtual bool IsRegistered( void ) const; |
|
skamonkey@3899
|
170 |
|
|
skamonkey@3899
|
171 |
// Returns the DLL identifier |
|
skamonkey@3899
|
172 |
virtual CVarDLLIdentifier_t GetDLLIdentifier() const; |
|
skamonkey@3899
|
173 |
|
|
skamonkey@3899
|
174 |
protected: |
|
skamonkey@3899
|
175 |
virtual void Create( const char *pName, const char *pHelpString = 0, |
|
skamonkey@3899
|
176 |
int flags = 0 ); |
|
skamonkey@3899
|
177 |
|
|
skamonkey@3899
|
178 |
// Used internally by OneTimeInit to initialize/shutdown |
|
skamonkey@3899
|
179 |
virtual void Init(); |
|
skamonkey@3899
|
180 |
void Shutdown(); |
|
skamonkey@3899
|
181 |
|
|
skamonkey@3899
|
182 |
// Internal copy routine ( uses new operator from correct module ) |
|
skamonkey@3899
|
183 |
char *CopyString( const char *from ); |
|
skamonkey@3899
|
184 |
|
|
skamonkey@3899
|
185 |
private: |
|
skamonkey@3899
|
186 |
// Next ConVar in chain |
|
skamonkey@3899
|
187 |
// Prior to register, it points to the next convar in the DLL. |
|
skamonkey@3899
|
188 |
// Once registered, though, m_pNext is reset to point to the next |
|
skamonkey@3899
|
189 |
// convar in the global list |
|
skamonkey@3899
|
190 |
ConCommandBase *m_pNext; |
|
skamonkey@3899
|
191 |
|
|
skamonkey@3899
|
192 |
// Has the cvar been added to the global list? |
|
skamonkey@3899
|
193 |
bool m_bRegistered; |
|
skamonkey@3899
|
194 |
|
|
skamonkey@3899
|
195 |
// Static data |
|
skamonkey@3899
|
196 |
const char *m_pszName; |
|
skamonkey@3899
|
197 |
const char *m_pszHelpString; |
|
skamonkey@3899
|
198 |
|
|
skamonkey@3899
|
199 |
// ConVar flags |
|
skamonkey@3899
|
200 |
int m_nFlags; |
|
skamonkey@3899
|
201 |
|
|
skamonkey@3899
|
202 |
protected: |
|
skamonkey@3899
|
203 |
// ConVars add themselves to this list for the executable. |
|
skamonkey@3899
|
204 |
// Then ConVar_Register runs through all the console variables |
|
skamonkey@3899
|
205 |
// and registers them into a global list stored in vstdlib.dll |
|
skamonkey@3899
|
206 |
static ConCommandBase *s_pConCommandBases; |
|
skamonkey@3899
|
207 |
|
|
skamonkey@3899
|
208 |
// ConVars in this executable use this 'global' to access values. |
|
skamonkey@3899
|
209 |
static IConCommandBaseAccessor *s_pAccessor; |
|
skamonkey@3899
|
210 |
public: |
|
skamonkey@3899
|
211 |
inline void SetFlags(int flags) |
|
skamonkey@3899
|
212 |
{ |
|
skamonkey@3899
|
213 |
m_nFlags = flags; |
|
skamonkey@3899
|
214 |
} |
|
skamonkey@3899
|
215 |
}; |
|
skamonkey@3899
|
216 |
|
|
skamonkey@3899
|
217 |
|
|
skamonkey@3899
|
218 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
219 |
// Command tokenizer |
|
skamonkey@3899
|
220 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
221 |
class CCommand |
|
skamonkey@3899
|
222 |
{ |
|
skamonkey@3899
|
223 |
public: |
|
skamonkey@3899
|
224 |
CCommand(); |
|
skamonkey@3899
|
225 |
CCommand( int nArgC, const char **ppArgV ); |
|
skamonkey@3899
|
226 |
bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL ); |
|
skamonkey@3899
|
227 |
void Reset(); |
|
skamonkey@3899
|
228 |
|
|
skamonkey@3899
|
229 |
int ArgC() const; |
|
skamonkey@3899
|
230 |
const char **ArgV() const; |
|
skamonkey@3899
|
231 |
const char *ArgS() const; // All args that occur after the 0th arg, in string form |
|
skamonkey@3899
|
232 |
const char *GetCommandString() const; // The entire command in string form, including the 0th arg |
|
skamonkey@3899
|
233 |
const char *operator[]( int nIndex ) const; // Gets at arguments |
|
skamonkey@3899
|
234 |
const char *Arg( int nIndex ) const; // Gets at arguments |
|
skamonkey@3899
|
235 |
|
|
skamonkey@3899
|
236 |
// Helper functions to parse arguments to commands. |
|
skamonkey@3899
|
237 |
const char* FindArg( const char *pName ) const; |
|
skamonkey@3899
|
238 |
int FindArgInt( const char *pName, int nDefaultVal ) const; |
|
skamonkey@3899
|
239 |
|
|
skamonkey@3899
|
240 |
static int MaxCommandLength(); |
|
skamonkey@3899
|
241 |
static characterset_t* DefaultBreakSet(); |
|
skamonkey@3899
|
242 |
|
|
skamonkey@3899
|
243 |
private: |
|
skamonkey@3899
|
244 |
enum |
|
skamonkey@3899
|
245 |
{ |
|
skamonkey@3899
|
246 |
COMMAND_MAX_ARGC = 64, |
|
skamonkey@3899
|
247 |
COMMAND_MAX_LENGTH = 512, |
|
skamonkey@3899
|
248 |
}; |
|
skamonkey@3899
|
249 |
|
|
skamonkey@3899
|
250 |
int m_nArgc; |
|
skamonkey@3899
|
251 |
int m_nArgv0Size; |
|
skamonkey@3899
|
252 |
char m_pArgSBuffer[ COMMAND_MAX_LENGTH ]; |
|
skamonkey@3899
|
253 |
char m_pArgvBuffer[ COMMAND_MAX_LENGTH ]; |
|
skamonkey@3899
|
254 |
const char* m_ppArgv[ COMMAND_MAX_ARGC ]; |
|
skamonkey@3899
|
255 |
}; |
|
skamonkey@3899
|
256 |
|
|
skamonkey@3899
|
257 |
inline int CCommand::MaxCommandLength() |
|
skamonkey@3899
|
258 |
{ |
|
skamonkey@3899
|
259 |
return COMMAND_MAX_LENGTH - 1; |
|
skamonkey@3899
|
260 |
} |
|
skamonkey@3899
|
261 |
|
|
skamonkey@3899
|
262 |
inline int CCommand::ArgC() const |
|
skamonkey@3899
|
263 |
{ |
|
skamonkey@3899
|
264 |
return m_nArgc; |
|
skamonkey@3899
|
265 |
} |
|
skamonkey@3899
|
266 |
|
|
skamonkey@3899
|
267 |
inline const char **CCommand::ArgV() const |
|
skamonkey@3899
|
268 |
{ |
|
skamonkey@3899
|
269 |
return m_nArgc ? (const char**)m_ppArgv : NULL; |
|
skamonkey@3899
|
270 |
} |
|
skamonkey@3899
|
271 |
|
|
skamonkey@3899
|
272 |
inline const char *CCommand::ArgS() const |
|
skamonkey@3899
|
273 |
{ |
|
skamonkey@3899
|
274 |
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; |
|
skamonkey@3899
|
275 |
} |
|
skamonkey@3899
|
276 |
|
|
skamonkey@3899
|
277 |
inline const char *CCommand::GetCommandString() const |
|
skamonkey@3899
|
278 |
{ |
|
skamonkey@3899
|
279 |
return m_nArgc ? m_pArgSBuffer : ""; |
|
skamonkey@3899
|
280 |
} |
|
skamonkey@3899
|
281 |
|
|
skamonkey@3899
|
282 |
inline const char *CCommand::Arg( int nIndex ) const |
|
skamonkey@3899
|
283 |
{ |
|
skamonkey@3899
|
284 |
// FIXME: Many command handlers appear to not be particularly careful |
|
skamonkey@3899
|
285 |
// about checking for valid argc range. For now, we're going to |
|
skamonkey@3899
|
286 |
// do the extra check and return an empty string if it's out of range |
|
skamonkey@3899
|
287 |
if ( nIndex < 0 || nIndex >= m_nArgc ) |
|
skamonkey@3899
|
288 |
return ""; |
|
skamonkey@3899
|
289 |
return m_ppArgv[nIndex]; |
|
skamonkey@3899
|
290 |
} |
|
skamonkey@3899
|
291 |
|
|
skamonkey@3899
|
292 |
inline const char *CCommand::operator[]( int nIndex ) const |
|
skamonkey@3899
|
293 |
{ |
|
skamonkey@3899
|
294 |
return Arg( nIndex ); |
|
skamonkey@3899
|
295 |
} |
|
skamonkey@3899
|
296 |
|
|
skamonkey@3899
|
297 |
|
|
skamonkey@3899
|
298 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
299 |
// Purpose: The console invoked command |
|
skamonkey@3899
|
300 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
301 |
class ConCommand : public ConCommandBase |
|
skamonkey@3899
|
302 |
{ |
|
skamonkey@3899
|
303 |
friend class CCvar; |
|
skamonkey@3899
|
304 |
|
|
skamonkey@3899
|
305 |
public: |
|
skamonkey@3899
|
306 |
typedef ConCommandBase BaseClass; |
|
skamonkey@3899
|
307 |
|
|
skamonkey@3899
|
308 |
ConCommand( const char *pName, FnCommandCallbackV1_t callback, |
|
skamonkey@3899
|
309 |
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); |
|
skamonkey@3899
|
310 |
ConCommand( const char *pName, FnCommandCallback_t callback, |
|
skamonkey@3899
|
311 |
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); |
|
skamonkey@3899
|
312 |
ConCommand( const char *pName, ICommandCallback *pCallback, |
|
skamonkey@3899
|
313 |
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); |
|
skamonkey@3899
|
314 |
ConCommand( const char *pName, ICommandCallback2 *pCallback, |
|
skamonkey@3899
|
315 |
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); |
|
skamonkey@3899
|
316 |
|
|
skamonkey@3899
|
317 |
virtual ~ConCommand( void ); |
|
skamonkey@3899
|
318 |
|
|
skamonkey@3899
|
319 |
virtual bool IsCommand( void ) const; |
|
skamonkey@3899
|
320 |
|
|
skamonkey@3899
|
321 |
virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands ); |
|
skamonkey@3899
|
322 |
|
|
skamonkey@3899
|
323 |
virtual bool CanAutoComplete( void ); |
|
skamonkey@3899
|
324 |
|
|
skamonkey@3899
|
325 |
// Invoke the function |
|
skamonkey@3942
|
326 |
virtual void Dispatch( const CCommandContext &context, const CCommand &command ); |
|
skamonkey@3899
|
327 |
|
|
skamonkey@3899
|
328 |
private: |
|
skamonkey@3899
|
329 |
// NOTE: To maintain backward compat, we have to be very careful: |
|
skamonkey@3899
|
330 |
// All public virtual methods must appear in the same order always |
|
skamonkey@3899
|
331 |
// since engine code will be calling into this code, which *does not match* |
|
skamonkey@3899
|
332 |
// in the mod code; it's using slightly different, but compatible versions |
|
skamonkey@3899
|
333 |
// of this class. Also: Be very careful about adding new fields to this class. |
|
skamonkey@3899
|
334 |
// Those fields will not exist in the version of this class that is instanced |
|
skamonkey@3899
|
335 |
// in mod code. |
|
skamonkey@3899
|
336 |
|
|
skamonkey@3899
|
337 |
// Call this function when executing the command |
|
skamonkey@3899
|
338 |
union |
|
skamonkey@3899
|
339 |
{ |
|
skamonkey@3899
|
340 |
FnCommandCallbackV1_t m_fnCommandCallbackV1; |
|
skamonkey@3899
|
341 |
FnCommandCallback_t m_fnCommandCallback; |
|
skamonkey@3899
|
342 |
ICommandCallback *m_pCommandCallback; |
|
skamonkey@3899
|
343 |
ICommandCallback2 *m_pCommandCallback2; |
|
skamonkey@3899
|
344 |
}; |
|
skamonkey@3899
|
345 |
|
|
skamonkey@3899
|
346 |
union |
|
skamonkey@3899
|
347 |
{ |
|
skamonkey@3899
|
348 |
FnCommandCompletionCallback m_fnCompletionCallback; |
|
skamonkey@3899
|
349 |
ICommandCompletionCallback *m_pCommandCompletionCallback; |
|
skamonkey@3899
|
350 |
}; |
|
skamonkey@3899
|
351 |
|
|
skamonkey@3899
|
352 |
bool m_bHasCompletionCallback : 1; |
|
skamonkey@3899
|
353 |
bool m_bUsingNewCommandCallback : 1; |
|
skamonkey@3899
|
354 |
bool m_bUsingCommandCallbackInterface : 1; |
|
skamonkey@3899
|
355 |
bool m_bUsingCommandCallbackInterface2 : 1; |
|
skamonkey@3899
|
356 |
public: |
|
skamonkey@3899
|
357 |
inline FnCommandCallback_t GetCallback() const |
|
skamonkey@3899
|
358 |
{ |
|
skamonkey@3899
|
359 |
return m_fnCommandCallback; |
|
skamonkey@3899
|
360 |
} |
|
skamonkey@3899
|
361 |
}; |
|
skamonkey@3899
|
362 |
|
|
skamonkey@3899
|
363 |
|
|
skamonkey@3899
|
364 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
365 |
// Purpose: A console variable |
|
skamonkey@3899
|
366 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
367 |
class ConVar : public ConCommandBase, public IConVar |
|
skamonkey@3899
|
368 |
{ |
|
skamonkey@3899
|
369 |
friend class CCvar; |
|
skamonkey@3899
|
370 |
friend class ConVarRef; |
|
skamonkey@3899
|
371 |
friend class SplitScreenConVarRef; |
|
skamonkey@3899
|
372 |
|
|
skamonkey@3899
|
373 |
public: |
|
skamonkey@3899
|
374 |
typedef ConCommandBase BaseClass; |
|
skamonkey@3899
|
375 |
|
|
skamonkey@3899
|
376 |
ConVar( const char *pName, const char *pDefaultValue, int flags = 0); |
|
skamonkey@3899
|
377 |
|
|
skamonkey@3899
|
378 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
skamonkey@3899
|
379 |
const char *pHelpString ); |
|
skamonkey@3899
|
380 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
skamonkey@3899
|
381 |
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); |
|
skamonkey@3899
|
382 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
skamonkey@3899
|
383 |
const char *pHelpString, FnChangeCallback_t callback ); |
|
skamonkey@3899
|
384 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
skamonkey@3899
|
385 |
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, |
|
skamonkey@3899
|
386 |
FnChangeCallback_t callback ); |
|
skamonkey@3899
|
387 |
|
|
skamonkey@3899
|
388 |
virtual ~ConVar( void ); |
|
skamonkey@3899
|
389 |
|
|
skamonkey@3899
|
390 |
virtual bool IsFlagSet( int flag ) const; |
|
skamonkey@3899
|
391 |
virtual const char* GetHelpText( void ) const; |
|
skamonkey@3899
|
392 |
virtual bool IsRegistered( void ) const; |
|
skamonkey@3899
|
393 |
virtual const char *GetName( void ) const; |
|
skamonkey@3899
|
394 |
// Return name of command (usually == GetName(), except in case of FCVAR_SS_ADDED vars |
|
skamonkey@3899
|
395 |
virtual const char *GetBaseName( void ) const; |
|
skamonkey@3899
|
396 |
virtual int GetSplitScreenPlayerSlot() const; |
|
skamonkey@3899
|
397 |
|
|
skamonkey@3899
|
398 |
virtual void AddFlags( int flags ); |
|
skamonkey@3899
|
399 |
virtual int GetFlags() const; |
|
skamonkey@3899
|
400 |
virtual bool IsCommand( void ) const; |
|
skamonkey@3899
|
401 |
|
|
skamonkey@3899
|
402 |
// Install a change callback (there shouldn't already be one....) |
|
skamonkey@3899
|
403 |
void InstallChangeCallback( FnChangeCallback_t callback, bool bInvoke = true ); |
|
skamonkey@3899
|
404 |
void RemoveChangeCallback( FnChangeCallback_t callbackToRemove ); |
|
skamonkey@3899
|
405 |
|
|
skamonkey@3899
|
406 |
int GetChangeCallbackCount() const { return m_pParent->m_fnChangeCallbacks.Count(); } |
|
skamonkey@3899
|
407 |
FnChangeCallback_t GetChangeCallback( int slot ) const { return m_pParent->m_fnChangeCallbacks[ slot ]; } |
|
skamonkey@3899
|
408 |
|
|
skamonkey@3899
|
409 |
// Retrieve value |
|
skamonkey@3899
|
410 |
FORCEINLINE_CVAR float GetFloat( void ) const; |
|
skamonkey@3899
|
411 |
FORCEINLINE_CVAR int GetInt( void ) const; |
|
skamonkey@3899
|
412 |
FORCEINLINE_CVAR Color GetColor( void ) const; |
|
skamonkey@3899
|
413 |
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } |
|
skamonkey@3899
|
414 |
FORCEINLINE_CVAR char const *GetString( void ) const; |
|
skamonkey@3899
|
415 |
|
|
skamonkey@3899
|
416 |
// Compiler driven selection for template use |
|
skamonkey@3899
|
417 |
template <typename T> T Get( void ) const; |
|
skamonkey@3899
|
418 |
template <typename T> T Get( T * ) const; |
|
skamonkey@3899
|
419 |
|
|
skamonkey@3899
|
420 |
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes |
|
skamonkey@3899
|
421 |
// from alloc/free across dll/exe boundaries. |
|
skamonkey@3899
|
422 |
|
|
skamonkey@3899
|
423 |
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). |
|
skamonkey@3899
|
424 |
virtual void SetValue( const char *value ); |
|
skamonkey@3899
|
425 |
virtual void SetValue( float value ); |
|
skamonkey@3899
|
426 |
virtual void SetValue( int value ); |
|
skamonkey@3899
|
427 |
virtual void SetValue( Color value ); |
|
skamonkey@3899
|
428 |
|
|
skamonkey@3899
|
429 |
// Reset to default value |
|
skamonkey@3899
|
430 |
void Revert( void ); |
|
skamonkey@3899
|
431 |
|
|
skamonkey@3899
|
432 |
// True if it has a min/max setting |
|
skamonkey@3899
|
433 |
bool HasMin() const; |
|
skamonkey@3899
|
434 |
bool HasMax() const; |
|
skamonkey@3899
|
435 |
|
|
skamonkey@3899
|
436 |
bool GetMin( float& minVal ) const; |
|
skamonkey@3899
|
437 |
bool GetMax( float& maxVal ) const; |
|
skamonkey@3899
|
438 |
|
|
skamonkey@3899
|
439 |
float GetMinValue() const; |
|
skamonkey@3899
|
440 |
float GetMaxValue() const; |
|
skamonkey@3899
|
441 |
|
|
skamonkey@3899
|
442 |
const char *GetDefault( void ) const; |
|
skamonkey@3899
|
443 |
|
|
skamonkey@3899
|
444 |
// Value |
|
skamonkey@3899
|
445 |
struct CVValue_t |
|
skamonkey@3899
|
446 |
{ |
|
skamonkey@3899
|
447 |
char *m_pszString; |
|
skamonkey@3899
|
448 |
int m_StringLength; |
|
skamonkey@3899
|
449 |
|
|
skamonkey@3899
|
450 |
// Values |
|
skamonkey@3899
|
451 |
float m_fValue; |
|
skamonkey@3899
|
452 |
int m_nValue; |
|
skamonkey@3899
|
453 |
}; |
|
skamonkey@3899
|
454 |
|
|
skamonkey@3899
|
455 |
FORCEINLINE_CVAR CVValue_t &GetRawValue() |
|
skamonkey@3899
|
456 |
{ |
|
skamonkey@3899
|
457 |
return m_Value; |
|
skamonkey@3899
|
458 |
} |
|
skamonkey@3899
|
459 |
FORCEINLINE_CVAR const CVValue_t &GetRawValue() const |
|
skamonkey@3899
|
460 |
{ |
|
skamonkey@3899
|
461 |
return m_Value; |
|
skamonkey@3899
|
462 |
} |
|
skamonkey@3899
|
463 |
|
|
skamonkey@3899
|
464 |
private: |
|
skamonkey@3899
|
465 |
bool InternalSetColorFromString( const char *value ); |
|
skamonkey@3899
|
466 |
// Called by CCvar when the value of a var is changing. |
|
skamonkey@3899
|
467 |
virtual void InternalSetValue(const char *value); |
|
skamonkey@3899
|
468 |
// For CVARs marked FCVAR_NEVER_AS_STRING |
|
skamonkey@3899
|
469 |
virtual void InternalSetFloatValue( float fNewValue ); |
|
skamonkey@3899
|
470 |
virtual void InternalSetIntValue( int nValue ); |
|
skamonkey@3899
|
471 |
virtual void InternalSetColorValue( Color value ); |
|
skamonkey@3899
|
472 |
|
|
skamonkey@3899
|
473 |
virtual bool ClampValue( float& value ); |
|
skamonkey@3899
|
474 |
virtual void ChangeStringValue( const char *tempVal, float flOldValue ); |
|
skamonkey@3899
|
475 |
|
|
skamonkey@3899
|
476 |
virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, |
|
skamonkey@3899
|
477 |
const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, |
|
skamonkey@3899
|
478 |
bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); |
|
skamonkey@3899
|
479 |
|
|
skamonkey@3899
|
480 |
// Used internally by OneTimeInit to initialize. |
|
skamonkey@3899
|
481 |
virtual void Init(); |
|
skamonkey@3899
|
482 |
|
|
skamonkey@3899
|
483 |
|
|
skamonkey@3899
|
484 |
|
|
skamonkey@3899
|
485 |
protected: |
|
skamonkey@3899
|
486 |
|
|
skamonkey@3899
|
487 |
// This either points to "this" or it points to the original declaration of a ConVar. |
|
skamonkey@3899
|
488 |
// This allows ConVars to exist in separate modules, and they all use the first one to be declared. |
|
skamonkey@3899
|
489 |
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). |
|
skamonkey@3899
|
490 |
ConVar *m_pParent; |
|
skamonkey@3899
|
491 |
|
|
skamonkey@3899
|
492 |
// Static data |
|
skamonkey@3899
|
493 |
const char *m_pszDefaultValue; |
|
skamonkey@3899
|
494 |
|
|
skamonkey@3899
|
495 |
CVValue_t m_Value; |
|
skamonkey@3899
|
496 |
|
|
skamonkey@3899
|
497 |
// Min/Max values |
|
skamonkey@3899
|
498 |
bool m_bHasMin; |
|
skamonkey@3899
|
499 |
float m_fMinVal; |
|
skamonkey@3899
|
500 |
bool m_bHasMax; |
|
skamonkey@3899
|
501 |
float m_fMaxVal; |
|
skamonkey@3899
|
502 |
|
|
skamonkey@3899
|
503 |
// Call this function when ConVar changes |
|
skamonkey@3899
|
504 |
CUtlVector< FnChangeCallback_t > m_fnChangeCallbacks; |
|
skamonkey@3899
|
505 |
public: |
|
skamonkey@3899
|
506 |
inline void SetMin(bool set, float min=0.0) |
|
skamonkey@3899
|
507 |
{ |
|
skamonkey@3899
|
508 |
m_bHasMin = set; |
|
skamonkey@3899
|
509 |
m_fMinVal = min; |
|
skamonkey@3899
|
510 |
} |
|
skamonkey@3899
|
511 |
inline void SetMax(bool set, float max=0.0) |
|
skamonkey@3899
|
512 |
{ |
|
skamonkey@3899
|
513 |
m_bHasMax = set; |
|
skamonkey@3899
|
514 |
m_fMaxVal = max; |
|
skamonkey@3899
|
515 |
} |
|
skamonkey@3899
|
516 |
}; |
|
skamonkey@3899
|
517 |
|
|
skamonkey@3899
|
518 |
|
|
skamonkey@3899
|
519 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
520 |
// Purpose: Return ConVar value as a float |
|
skamonkey@3899
|
521 |
// Output : float |
|
skamonkey@3899
|
522 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
523 |
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const |
|
skamonkey@3899
|
524 |
{ |
|
skamonkey@3899
|
525 |
#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS |
|
skamonkey@3899
|
526 |
Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); |
|
skamonkey@3899
|
527 |
#endif |
|
skamonkey@3899
|
528 |
return m_pParent->m_Value.m_fValue; |
|
skamonkey@3899
|
529 |
} |
|
skamonkey@3899
|
530 |
|
|
skamonkey@3899
|
531 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
532 |
// Purpose: Return ConVar value as an int |
|
skamonkey@3899
|
533 |
// Output : int |
|
skamonkey@3899
|
534 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
535 |
FORCEINLINE_CVAR int ConVar::GetInt( void ) const |
|
skamonkey@3899
|
536 |
{ |
|
skamonkey@3899
|
537 |
#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS |
|
skamonkey@3899
|
538 |
Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); |
|
skamonkey@3899
|
539 |
#endif |
|
skamonkey@3899
|
540 |
return m_pParent->m_Value.m_nValue; |
|
skamonkey@3899
|
541 |
} |
|
skamonkey@3899
|
542 |
|
|
skamonkey@3899
|
543 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
544 |
// Purpose: Return ConVar value as a color |
|
skamonkey@3899
|
545 |
// Output : Color |
|
skamonkey@3899
|
546 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
547 |
FORCEINLINE_CVAR Color ConVar::GetColor( void ) const |
|
skamonkey@3899
|
548 |
{ |
|
skamonkey@3899
|
549 |
#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS |
|
skamonkey@3899
|
550 |
Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); |
|
skamonkey@3899
|
551 |
#endif |
|
skamonkey@3899
|
552 |
unsigned char *pColorElement = ((unsigned char *)&m_pParent->m_Value.m_nValue); |
|
skamonkey@3899
|
553 |
return Color( pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3] ); |
|
skamonkey@3899
|
554 |
} |
|
skamonkey@3899
|
555 |
|
|
skamonkey@3899
|
556 |
|
|
skamonkey@3899
|
557 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
558 |
|
|
skamonkey@3899
|
559 |
template <> FORCEINLINE_CVAR float ConVar::Get<float>( void ) const { return GetFloat(); } |
|
skamonkey@3899
|
560 |
template <> FORCEINLINE_CVAR int ConVar::Get<int>( void ) const { return GetInt(); } |
|
skamonkey@3899
|
561 |
template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( void ) const { return GetBool(); } |
|
skamonkey@3899
|
562 |
template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( void ) const { return GetString(); } |
|
skamonkey@3899
|
563 |
template <> FORCEINLINE_CVAR float ConVar::Get<float>( float *p ) const { return ( *p = GetFloat() ); } |
|
skamonkey@3899
|
564 |
template <> FORCEINLINE_CVAR int ConVar::Get<int>( int *p ) const { return ( *p = GetInt() ); } |
|
skamonkey@3899
|
565 |
template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( bool *p ) const { return ( *p = GetBool() ); } |
|
skamonkey@3899
|
566 |
template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( char const **p ) const { return ( *p = GetString() ); } |
|
skamonkey@3899
|
567 |
|
|
skamonkey@3899
|
568 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
569 |
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. |
|
skamonkey@3899
|
570 |
// Output : const char * |
|
skamonkey@3899
|
571 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
572 |
FORCEINLINE_CVAR const char *ConVar::GetString( void ) const |
|
skamonkey@3899
|
573 |
{ |
|
skamonkey@3899
|
574 |
#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS |
|
skamonkey@3899
|
575 |
Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) ); |
|
skamonkey@3899
|
576 |
#endif |
|
skamonkey@3899
|
577 |
if ( m_nFlags & FCVAR_NEVER_AS_STRING ) |
|
skamonkey@3899
|
578 |
return "FCVAR_NEVER_AS_STRING"; |
|
skamonkey@3899
|
579 |
|
|
skamonkey@3899
|
580 |
char const *str = m_pParent->m_Value.m_pszString; |
|
skamonkey@3899
|
581 |
return str ? str : ""; |
|
skamonkey@3899
|
582 |
} |
|
skamonkey@3899
|
583 |
|
|
skamonkey@3899
|
584 |
class CSplitScreenAddedConVar : public ConVar |
|
skamonkey@3899
|
585 |
{ |
|
skamonkey@3899
|
586 |
typedef ConVar BaseClass; |
|
skamonkey@3899
|
587 |
public: |
|
skamonkey@3899
|
588 |
CSplitScreenAddedConVar( int nSplitScreenSlot, const char *pName, const ConVar *pBaseVar ) : |
|
skamonkey@3899
|
589 |
BaseClass |
|
skamonkey@3899
|
590 |
( |
|
skamonkey@3899
|
591 |
pName, |
|
skamonkey@3899
|
592 |
pBaseVar->GetDefault(), |
|
skamonkey@3899
|
593 |
// Keep basevar flags, except remove _SS and add _SS_ADDED instead |
|
skamonkey@3899
|
594 |
( pBaseVar->GetFlags() & ~FCVAR_SS ) | FCVAR_SS_ADDED, |
|
skamonkey@3899
|
595 |
pBaseVar->GetHelpText(), |
|
skamonkey@3899
|
596 |
pBaseVar->HasMin(), |
|
skamonkey@3899
|
597 |
pBaseVar->GetMinValue(), |
|
skamonkey@3899
|
598 |
pBaseVar->HasMax(), |
|
skamonkey@3899
|
599 |
pBaseVar->GetMaxValue() |
|
skamonkey@3899
|
600 |
), |
|
skamonkey@3899
|
601 |
m_pBaseVar( pBaseVar ), |
|
skamonkey@3899
|
602 |
m_nSplitScreenSlot( nSplitScreenSlot ) |
|
skamonkey@3899
|
603 |
{ |
|
skamonkey@3899
|
604 |
for ( int i = 0; i < pBaseVar->GetChangeCallbackCount(); ++i ) |
|
skamonkey@3899
|
605 |
{ |
|
skamonkey@3899
|
606 |
InstallChangeCallback( pBaseVar->GetChangeCallback( i ), false ); |
|
skamonkey@3899
|
607 |
} |
|
skamonkey@3899
|
608 |
Assert( nSplitScreenSlot >= 1 ); |
|
skamonkey@3899
|
609 |
Assert( nSplitScreenSlot < MAX_SPLITSCREEN_CLIENTS ); |
|
skamonkey@3899
|
610 |
Assert( m_pBaseVar ); |
|
skamonkey@3899
|
611 |
Assert( IsFlagSet( FCVAR_SS_ADDED ) ); |
|
skamonkey@3899
|
612 |
Assert( !IsFlagSet( FCVAR_SS ) ); |
|
skamonkey@3899
|
613 |
} |
|
skamonkey@3899
|
614 |
|
|
skamonkey@3899
|
615 |
const ConVar *GetBaseVar() const; |
|
skamonkey@3899
|
616 |
virtual const char *GetBaseName() const; |
|
skamonkey@3899
|
617 |
void SetSplitScreenPlayerSlot( int nSlot ); |
|
skamonkey@3899
|
618 |
virtual int GetSplitScreenPlayerSlot() const; |
|
skamonkey@3899
|
619 |
|
|
skamonkey@3899
|
620 |
protected: |
|
skamonkey@3899
|
621 |
|
|
skamonkey@3899
|
622 |
const ConVar *m_pBaseVar; |
|
skamonkey@3899
|
623 |
int m_nSplitScreenSlot; |
|
skamonkey@3899
|
624 |
}; |
|
skamonkey@3899
|
625 |
|
|
skamonkey@3899
|
626 |
FORCEINLINE_CVAR const ConVar *CSplitScreenAddedConVar::GetBaseVar() const |
|
skamonkey@3899
|
627 |
{ |
|
skamonkey@3899
|
628 |
Assert( m_pBaseVar ); |
|
skamonkey@3899
|
629 |
return m_pBaseVar; |
|
skamonkey@3899
|
630 |
} |
|
skamonkey@3899
|
631 |
|
|
skamonkey@3899
|
632 |
FORCEINLINE_CVAR const char *CSplitScreenAddedConVar::GetBaseName() const |
|
skamonkey@3899
|
633 |
{ |
|
skamonkey@3899
|
634 |
Assert( m_pBaseVar ); |
|
skamonkey@3899
|
635 |
return m_pBaseVar->GetName(); |
|
skamonkey@3899
|
636 |
} |
|
skamonkey@3899
|
637 |
|
|
skamonkey@3899
|
638 |
FORCEINLINE_CVAR void CSplitScreenAddedConVar::SetSplitScreenPlayerSlot( int nSlot ) |
|
skamonkey@3899
|
639 |
{ |
|
skamonkey@3899
|
640 |
m_nSplitScreenSlot = nSlot; |
|
skamonkey@3899
|
641 |
} |
|
skamonkey@3899
|
642 |
|
|
skamonkey@3899
|
643 |
FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const |
|
skamonkey@3899
|
644 |
{ |
|
skamonkey@3899
|
645 |
return m_nSplitScreenSlot; |
|
skamonkey@3899
|
646 |
} |
|
skamonkey@3899
|
647 |
|
|
skamonkey@3899
|
648 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
649 |
// Used to read/write convars that already exist (replaces the FindVar method) |
|
skamonkey@3899
|
650 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
651 |
class ConVarRef |
|
skamonkey@3899
|
652 |
{ |
|
skamonkey@3899
|
653 |
public: |
|
skamonkey@3899
|
654 |
ConVarRef( const char *pName ); |
|
skamonkey@3899
|
655 |
ConVarRef( const char *pName, bool bIgnoreMissing ); |
|
skamonkey@3899
|
656 |
ConVarRef( IConVar *pConVar ); |
|
skamonkey@3899
|
657 |
|
|
skamonkey@3899
|
658 |
void Init( const char *pName, bool bIgnoreMissing ); |
|
skamonkey@3899
|
659 |
bool IsValid() const; |
|
skamonkey@3899
|
660 |
bool IsFlagSet( int nFlags ) const; |
|
skamonkey@3899
|
661 |
IConVar *GetLinkedConVar(); |
|
skamonkey@3899
|
662 |
|
|
skamonkey@3899
|
663 |
// Get/Set value |
|
skamonkey@3899
|
664 |
float GetFloat( void ) const; |
|
skamonkey@3899
|
665 |
int GetInt( void ) const; |
|
skamonkey@3899
|
666 |
Color GetColor( void ) const; |
|
skamonkey@3899
|
667 |
bool GetBool() const { return !!GetInt(); } |
|
skamonkey@3899
|
668 |
const char *GetString( void ) const; |
|
skamonkey@3899
|
669 |
|
|
skamonkey@3899
|
670 |
void SetValue( const char *pValue ); |
|
skamonkey@3899
|
671 |
void SetValue( float flValue ); |
|
skamonkey@3899
|
672 |
void SetValue( int nValue ); |
|
skamonkey@3899
|
673 |
void SetValue( Color value ); |
|
skamonkey@3899
|
674 |
void SetValue( bool bValue ); |
|
skamonkey@3899
|
675 |
|
|
skamonkey@3899
|
676 |
const char *GetName() const; |
|
skamonkey@3899
|
677 |
|
|
skamonkey@3899
|
678 |
const char *GetDefault() const; |
|
skamonkey@3899
|
679 |
|
|
skamonkey@3899
|
680 |
const char *GetBaseName() const; |
|
skamonkey@3899
|
681 |
|
|
skamonkey@3899
|
682 |
int GetSplitScreenPlayerSlot() const; |
|
skamonkey@3899
|
683 |
|
|
skamonkey@3899
|
684 |
private: |
|
skamonkey@3899
|
685 |
// High-speed method to read convar data |
|
skamonkey@3899
|
686 |
IConVar *m_pConVar; |
|
skamonkey@3899
|
687 |
ConVar *m_pConVarState; |
|
skamonkey@3899
|
688 |
}; |
|
skamonkey@3899
|
689 |
|
|
skamonkey@3899
|
690 |
|
|
skamonkey@3899
|
691 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
692 |
// Did we find an existing convar of that name? |
|
skamonkey@3899
|
693 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
694 |
FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const |
|
skamonkey@3899
|
695 |
{ |
|
skamonkey@3899
|
696 |
return ( m_pConVar->IsFlagSet( nFlags ) != 0 ); |
|
skamonkey@3899
|
697 |
} |
|
skamonkey@3899
|
698 |
|
|
skamonkey@3899
|
699 |
FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar() |
|
skamonkey@3899
|
700 |
{ |
|
skamonkey@3899
|
701 |
return m_pConVar; |
|
skamonkey@3899
|
702 |
} |
|
skamonkey@3899
|
703 |
|
|
skamonkey@3899
|
704 |
FORCEINLINE_CVAR const char *ConVarRef::GetName() const |
|
skamonkey@3899
|
705 |
{ |
|
skamonkey@3899
|
706 |
return m_pConVar->GetName(); |
|
skamonkey@3899
|
707 |
} |
|
skamonkey@3899
|
708 |
|
|
skamonkey@3899
|
709 |
FORCEINLINE_CVAR const char *ConVarRef::GetBaseName() const |
|
skamonkey@3899
|
710 |
{ |
|
skamonkey@3899
|
711 |
return m_pConVar->GetBaseName(); |
|
skamonkey@3899
|
712 |
} |
|
skamonkey@3899
|
713 |
|
|
skamonkey@3899
|
714 |
FORCEINLINE_CVAR int ConVarRef::GetSplitScreenPlayerSlot() const |
|
skamonkey@3899
|
715 |
{ |
|
skamonkey@3899
|
716 |
return m_pConVar->GetSplitScreenPlayerSlot(); |
|
skamonkey@3899
|
717 |
} |
|
skamonkey@3899
|
718 |
|
|
skamonkey@3899
|
719 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
720 |
// Purpose: Return ConVar value as a float |
|
skamonkey@3899
|
721 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
722 |
FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const |
|
skamonkey@3899
|
723 |
{ |
|
skamonkey@3899
|
724 |
return m_pConVarState->m_Value.m_fValue; |
|
skamonkey@3899
|
725 |
} |
|
skamonkey@3899
|
726 |
|
|
skamonkey@3899
|
727 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
728 |
// Purpose: Return ConVar value as an int |
|
skamonkey@3899
|
729 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
730 |
FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const |
|
skamonkey@3899
|
731 |
{ |
|
skamonkey@3899
|
732 |
return m_pConVarState->m_Value.m_nValue; |
|
skamonkey@3899
|
733 |
} |
|
skamonkey@3899
|
734 |
|
|
skamonkey@3899
|
735 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
736 |
// Purpose: Return ConVar value as a color |
|
skamonkey@3899
|
737 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
738 |
FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const |
|
skamonkey@3899
|
739 |
{ |
|
skamonkey@3899
|
740 |
return m_pConVarState->GetColor(); |
|
skamonkey@3899
|
741 |
} |
|
skamonkey@3899
|
742 |
|
|
skamonkey@3899
|
743 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
744 |
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. |
|
skamonkey@3899
|
745 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
746 |
FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const |
|
skamonkey@3899
|
747 |
{ |
|
skamonkey@3899
|
748 |
Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); |
|
skamonkey@3899
|
749 |
return m_pConVarState->m_Value.m_pszString; |
|
skamonkey@3899
|
750 |
} |
|
skamonkey@3899
|
751 |
|
|
skamonkey@3899
|
752 |
|
|
skamonkey@3899
|
753 |
FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) |
|
skamonkey@3899
|
754 |
{ |
|
skamonkey@3899
|
755 |
m_pConVar->SetValue( pValue ); |
|
skamonkey@3899
|
756 |
} |
|
skamonkey@3899
|
757 |
|
|
skamonkey@3899
|
758 |
FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue ) |
|
skamonkey@3899
|
759 |
{ |
|
skamonkey@3899
|
760 |
m_pConVar->SetValue( flValue ); |
|
skamonkey@3899
|
761 |
} |
|
skamonkey@3899
|
762 |
|
|
skamonkey@3899
|
763 |
FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue ) |
|
skamonkey@3899
|
764 |
{ |
|
skamonkey@3899
|
765 |
m_pConVar->SetValue( nValue ); |
|
skamonkey@3899
|
766 |
} |
|
skamonkey@3899
|
767 |
|
|
skamonkey@3899
|
768 |
FORCEINLINE_CVAR void ConVarRef::SetValue( Color value ) |
|
skamonkey@3899
|
769 |
{ |
|
skamonkey@3899
|
770 |
m_pConVar->SetValue( value ); |
|
skamonkey@3899
|
771 |
} |
|
skamonkey@3899
|
772 |
|
|
skamonkey@3899
|
773 |
FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue ) |
|
skamonkey@3899
|
774 |
{ |
|
skamonkey@3899
|
775 |
m_pConVar->SetValue( bValue ? 1 : 0 ); |
|
skamonkey@3899
|
776 |
} |
|
skamonkey@3899
|
777 |
|
|
skamonkey@3899
|
778 |
FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const |
|
skamonkey@3899
|
779 |
{ |
|
skamonkey@3899
|
780 |
return m_pConVarState->m_pszDefaultValue; |
|
skamonkey@3899
|
781 |
} |
|
skamonkey@3899
|
782 |
|
|
skamonkey@3899
|
783 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
784 |
// Helper for referencing splitscreen convars (i.e., "name" and "name2") |
|
skamonkey@3899
|
785 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
786 |
class SplitScreenConVarRef |
|
skamonkey@3899
|
787 |
{ |
|
skamonkey@3899
|
788 |
public: |
|
skamonkey@3899
|
789 |
SplitScreenConVarRef( const char *pName ); |
|
skamonkey@3899
|
790 |
SplitScreenConVarRef( const char *pName, bool bIgnoreMissing ); |
|
skamonkey@3899
|
791 |
SplitScreenConVarRef( IConVar *pConVar ); |
|
skamonkey@3899
|
792 |
|
|
skamonkey@3899
|
793 |
void Init( const char *pName, bool bIgnoreMissing ); |
|
skamonkey@3899
|
794 |
bool IsValid() const; |
|
skamonkey@3899
|
795 |
bool IsFlagSet( int nFlags ) const; |
|
skamonkey@3899
|
796 |
|
|
skamonkey@3899
|
797 |
// Get/Set value |
|
skamonkey@3899
|
798 |
float GetFloat( int nSlot ) const; |
|
skamonkey@3899
|
799 |
int GetInt( int nSlot ) const; |
|
skamonkey@3899
|
800 |
Color GetColor( int nSlot ) const; |
|
skamonkey@3899
|
801 |
bool GetBool( int nSlot ) const { return !!GetInt( nSlot ); } |
|
skamonkey@3899
|
802 |
const char *GetString( int nSlot ) const; |
|
skamonkey@3899
|
803 |
|
|
skamonkey@3899
|
804 |
void SetValue( int nSlot, const char *pValue ); |
|
skamonkey@3899
|
805 |
void SetValue( int nSlot, float flValue ); |
|
skamonkey@3899
|
806 |
void SetValue( int nSlot, int nValue ); |
|
skamonkey@3899
|
807 |
void SetValue( int nSlot, Color value ); |
|
skamonkey@3899
|
808 |
void SetValue( int nSlot, bool bValue ); |
|
skamonkey@3899
|
809 |
|
|
skamonkey@3899
|
810 |
const char *GetName( int nSlot ) const; |
|
skamonkey@3899
|
811 |
|
|
skamonkey@3899
|
812 |
const char *GetDefault() const; |
|
skamonkey@3899
|
813 |
|
|
skamonkey@3899
|
814 |
const char *GetBaseName() const; |
|
skamonkey@3899
|
815 |
|
|
skamonkey@3899
|
816 |
private: |
|
skamonkey@3899
|
817 |
struct cv_t |
|
skamonkey@3899
|
818 |
{ |
|
skamonkey@3899
|
819 |
IConVar *m_pConVar; |
|
skamonkey@3899
|
820 |
ConVar *m_pConVarState; |
|
skamonkey@3899
|
821 |
}; |
|
skamonkey@3899
|
822 |
|
|
skamonkey@3899
|
823 |
cv_t m_Info[ MAX_SPLITSCREEN_CLIENTS ]; |
|
skamonkey@3899
|
824 |
}; |
|
skamonkey@3899
|
825 |
|
|
skamonkey@3899
|
826 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
827 |
// Did we find an existing convar of that name? |
|
skamonkey@3899
|
828 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
829 |
FORCEINLINE_CVAR bool SplitScreenConVarRef::IsFlagSet( int nFlags ) const |
|
skamonkey@3899
|
830 |
{ |
|
skamonkey@3899
|
831 |
return ( m_Info[ 0 ].m_pConVar->IsFlagSet( nFlags ) != 0 ); |
|
skamonkey@3899
|
832 |
} |
|
skamonkey@3899
|
833 |
|
|
skamonkey@3899
|
834 |
FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetName( int nSlot ) const |
|
skamonkey@3899
|
835 |
{ |
|
skamonkey@3899
|
836 |
return m_Info[ nSlot ].m_pConVar->GetName(); |
|
skamonkey@3899
|
837 |
} |
|
skamonkey@3899
|
838 |
|
|
skamonkey@3899
|
839 |
FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetBaseName() const |
|
skamonkey@3899
|
840 |
{ |
|
skamonkey@3899
|
841 |
return m_Info[ 0 ].m_pConVar->GetBaseName(); |
|
skamonkey@3899
|
842 |
} |
|
skamonkey@3899
|
843 |
|
|
skamonkey@3899
|
844 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
845 |
// Purpose: Return ConVar value as a float |
|
skamonkey@3899
|
846 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
847 |
FORCEINLINE_CVAR float SplitScreenConVarRef::GetFloat( int nSlot ) const |
|
skamonkey@3899
|
848 |
{ |
|
skamonkey@3899
|
849 |
return m_Info[ nSlot ].m_pConVarState->m_Value.m_fValue; |
|
skamonkey@3899
|
850 |
} |
|
skamonkey@3899
|
851 |
|
|
skamonkey@3899
|
852 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
853 |
// Purpose: Return ConVar value as an int |
|
skamonkey@3899
|
854 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
855 |
FORCEINLINE_CVAR int SplitScreenConVarRef::GetInt( int nSlot ) const |
|
skamonkey@3899
|
856 |
{ |
|
skamonkey@3899
|
857 |
return m_Info[ nSlot ].m_pConVarState->m_Value.m_nValue; |
|
skamonkey@3899
|
858 |
} |
|
skamonkey@3899
|
859 |
|
|
skamonkey@3899
|
860 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
861 |
// Purpose: Return ConVar value as an int |
|
skamonkey@3899
|
862 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
863 |
FORCEINLINE_CVAR Color SplitScreenConVarRef::GetColor( int nSlot ) const |
|
skamonkey@3899
|
864 |
{ |
|
skamonkey@3899
|
865 |
return m_Info[ nSlot ].m_pConVarState->GetColor(); |
|
skamonkey@3899
|
866 |
} |
|
skamonkey@3899
|
867 |
|
|
skamonkey@3899
|
868 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
869 |
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. |
|
skamonkey@3899
|
870 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
871 |
FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetString( int nSlot ) const |
|
skamonkey@3899
|
872 |
{ |
|
skamonkey@3899
|
873 |
Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); |
|
skamonkey@3899
|
874 |
return m_Info[ nSlot ].m_pConVarState->m_Value.m_pszString; |
|
skamonkey@3899
|
875 |
} |
|
skamonkey@3899
|
876 |
|
|
skamonkey@3899
|
877 |
|
|
skamonkey@3899
|
878 |
FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, const char *pValue ) |
|
skamonkey@3899
|
879 |
{ |
|
skamonkey@3899
|
880 |
m_Info[ nSlot ].m_pConVar->SetValue( pValue ); |
|
skamonkey@3899
|
881 |
} |
|
skamonkey@3899
|
882 |
|
|
skamonkey@3899
|
883 |
FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, float flValue ) |
|
skamonkey@3899
|
884 |
{ |
|
skamonkey@3899
|
885 |
m_Info[ nSlot ].m_pConVar->SetValue( flValue ); |
|
skamonkey@3899
|
886 |
} |
|
skamonkey@3899
|
887 |
|
|
skamonkey@3899
|
888 |
FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, int nValue ) |
|
skamonkey@3899
|
889 |
{ |
|
skamonkey@3899
|
890 |
m_Info[ nSlot ].m_pConVar->SetValue( nValue ); |
|
skamonkey@3899
|
891 |
} |
|
skamonkey@3899
|
892 |
|
|
skamonkey@3899
|
893 |
FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, Color value ) |
|
skamonkey@3899
|
894 |
{ |
|
skamonkey@3899
|
895 |
m_Info[ nSlot ].m_pConVar->SetValue( value ); |
|
skamonkey@3899
|
896 |
} |
|
skamonkey@3899
|
897 |
|
|
skamonkey@3899
|
898 |
FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, bool bValue ) |
|
skamonkey@3899
|
899 |
{ |
|
skamonkey@3899
|
900 |
m_Info[ nSlot ].m_pConVar->SetValue( bValue ? 1 : 0 ); |
|
skamonkey@3899
|
901 |
} |
|
skamonkey@3899
|
902 |
|
|
skamonkey@3899
|
903 |
FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetDefault() const |
|
skamonkey@3899
|
904 |
{ |
|
skamonkey@3899
|
905 |
return m_Info[ 0 ].m_pConVarState->m_pszDefaultValue; |
|
skamonkey@3899
|
906 |
} |
|
skamonkey@3899
|
907 |
|
|
skamonkey@3899
|
908 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
909 |
// Called by the framework to register ConCommands with the ICVar |
|
skamonkey@3899
|
910 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
911 |
void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL ); |
|
skamonkey@3899
|
912 |
void ConVar_Unregister( ); |
|
skamonkey@3899
|
913 |
|
|
skamonkey@3899
|
914 |
|
|
skamonkey@3899
|
915 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
916 |
// Utility methods |
|
skamonkey@3899
|
917 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
918 |
void ConVar_PrintDescription( const ConCommandBase *pVar ); |
|
skamonkey@3899
|
919 |
|
|
skamonkey@3899
|
920 |
|
|
skamonkey@3899
|
921 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
922 |
// Purpose: Utility class to quickly allow ConCommands to call member methods |
|
skamonkey@3899
|
923 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
924 |
#ifdef _MSC_VER |
|
skamonkey@3899
|
925 |
#pragma warning (disable : 4355 ) |
|
skamonkey@3899
|
926 |
#endif |
|
skamonkey@3899
|
927 |
|
|
skamonkey@3899
|
928 |
template< class T > |
|
skamonkey@3899
|
929 |
class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback |
|
skamonkey@3899
|
930 |
{ |
|
skamonkey@3899
|
931 |
typedef ConCommand BaseClass; |
|
skamonkey@3899
|
932 |
typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command ); |
|
skamonkey@3899
|
933 |
typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands ); |
|
skamonkey@3899
|
934 |
|
|
skamonkey@3899
|
935 |
public: |
|
skamonkey@3899
|
936 |
CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0, |
|
skamonkey@3899
|
937 |
int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) : |
|
skamonkey@3899
|
938 |
BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL ) |
|
skamonkey@3899
|
939 |
{ |
|
skamonkey@3899
|
940 |
m_pOwner = pOwner; |
|
skamonkey@3899
|
941 |
m_Func = callback; |
|
skamonkey@3899
|
942 |
m_CompletionFunc = completionFunc; |
|
skamonkey@3899
|
943 |
} |
|
skamonkey@3899
|
944 |
|
|
skamonkey@3899
|
945 |
~CConCommandMemberAccessor() |
|
skamonkey@3899
|
946 |
{ |
|
skamonkey@3899
|
947 |
Shutdown(); |
|
skamonkey@3899
|
948 |
} |
|
skamonkey@3899
|
949 |
|
|
skamonkey@3899
|
950 |
void SetOwner( T* pOwner ) |
|
skamonkey@3899
|
951 |
{ |
|
skamonkey@3899
|
952 |
m_pOwner = pOwner; |
|
skamonkey@3899
|
953 |
} |
|
skamonkey@3899
|
954 |
|
|
skamonkey@3899
|
955 |
virtual void CommandCallback( const CCommand &command ) |
|
skamonkey@3899
|
956 |
{ |
|
skamonkey@3899
|
957 |
Assert( m_pOwner && m_Func ); |
|
skamonkey@3899
|
958 |
(m_pOwner->*m_Func)( command ); |
|
skamonkey@3899
|
959 |
} |
|
skamonkey@3899
|
960 |
|
|
skamonkey@3899
|
961 |
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) |
|
skamonkey@3899
|
962 |
{ |
|
skamonkey@3899
|
963 |
Assert( m_pOwner && m_CompletionFunc ); |
|
skamonkey@3899
|
964 |
return (m_pOwner->*m_CompletionFunc)( pPartial, commands ); |
|
skamonkey@3899
|
965 |
} |
|
skamonkey@3899
|
966 |
|
|
skamonkey@3899
|
967 |
private: |
|
skamonkey@3899
|
968 |
T* m_pOwner; |
|
skamonkey@3899
|
969 |
FnMemberCommandCallback_t m_Func; |
|
skamonkey@3899
|
970 |
FnMemberCommandCompletionCallback_t m_CompletionFunc; |
|
skamonkey@3899
|
971 |
}; |
|
skamonkey@3899
|
972 |
|
|
skamonkey@3899
|
973 |
#ifdef _MSC_VER |
|
skamonkey@3899
|
974 |
#pragma warning ( default : 4355 ) |
|
skamonkey@3899
|
975 |
#endif |
|
skamonkey@3899
|
976 |
|
|
skamonkey@3899
|
977 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
978 |
// Purpose: Utility macros to quicky generate a simple console command |
|
skamonkey@3899
|
979 |
//----------------------------------------------------------------------------- |
|
skamonkey@3899
|
980 |
#define CON_COMMAND( name, description ) \ |
|
skamonkey@3942
|
981 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
982 |
static ConCommand name##_command( #name, name, description ); \ |
|
skamonkey@3942
|
983 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
984 |
|
|
skamonkey@3899
|
985 |
#ifdef CLIENT_DLL |
|
skamonkey@3899
|
986 |
#define CON_COMMAND_SHARED( name, description ) \ |
|
skamonkey@3942
|
987 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
988 |
static ConCommand name##_command_client( #name "_client", name, description ); \ |
|
skamonkey@3942
|
989 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
990 |
#else |
|
skamonkey@3899
|
991 |
#define CON_COMMAND_SHARED( name, description ) \ |
|
skamonkey@3942
|
992 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
993 |
static ConCommand name##_command( #name, name, description ); \ |
|
skamonkey@3942
|
994 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
995 |
#endif |
|
skamonkey@3899
|
996 |
|
|
skamonkey@3899
|
997 |
|
|
skamonkey@3899
|
998 |
#define CON_COMMAND_F( name, description, flags ) \ |
|
skamonkey@3942
|
999 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1000 |
static ConCommand name##_command( #name, name, description, flags ); \ |
|
skamonkey@3942
|
1001 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1002 |
|
|
skamonkey@3899
|
1003 |
#ifdef CLIENT_DLL |
|
skamonkey@3899
|
1004 |
#define CON_COMMAND_F_SHARED( name, description, flags ) \ |
|
skamonkey@3942
|
1005 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1006 |
static ConCommand name##_command_client( #name "_client", name, description, flags ); \ |
|
skamonkey@3942
|
1007 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1008 |
#else |
|
skamonkey@3899
|
1009 |
#define CON_COMMAND_F_SHARED( name, description, flags ) \ |
|
skamonkey@3942
|
1010 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1011 |
static ConCommand name##_command( #name, name, description, flags ); \ |
|
skamonkey@3942
|
1012 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1013 |
#endif |
|
skamonkey@3899
|
1014 |
|
|
skamonkey@3899
|
1015 |
|
|
skamonkey@3899
|
1016 |
#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \ |
|
skamonkey@3942
|
1017 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1018 |
static ConCommand name##_command( #name, name, description, flags, completion ); \ |
|
skamonkey@3942
|
1019 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1020 |
|
|
skamonkey@3899
|
1021 |
#ifdef CLIENT_DLL |
|
skamonkey@3899
|
1022 |
#define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \ |
|
skamonkey@3942
|
1023 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1024 |
static ConCommand name##_command_client( #name "_client", name, description, flags, completion ); \ |
|
skamonkey@3942
|
1025 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1026 |
#else |
|
skamonkey@3899
|
1027 |
#define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \ |
|
skamonkey@3942
|
1028 |
static void name( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1029 |
static ConCommand name##_command( #name, name, description, flags, completion ); \ |
|
skamonkey@3942
|
1030 |
static void name( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1031 |
#endif |
|
skamonkey@3899
|
1032 |
|
|
skamonkey@3899
|
1033 |
|
|
skamonkey@3899
|
1034 |
#define CON_COMMAND_EXTERN( name, _funcname, description ) \ |
|
skamonkey@3942
|
1035 |
void _funcname( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1036 |
static ConCommand name##_command( #name, _funcname, description ); \ |
|
skamonkey@3942
|
1037 |
void _funcname( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1038 |
|
|
skamonkey@3899
|
1039 |
#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \ |
|
skamonkey@3942
|
1040 |
void _funcname( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1041 |
static ConCommand name##_command( #name, _funcname, description, flags ); \ |
|
skamonkey@3942
|
1042 |
void _funcname( const CCommandContext &context, const CCommand &args ) |
|
skamonkey@3899
|
1043 |
|
|
skamonkey@3899
|
1044 |
#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \ |
|
skamonkey@3942
|
1045 |
void _funcname( const CCommandContext &context, const CCommand &args ); \ |
|
skamonkey@3899
|
1046 |
friend class CCommandMemberInitializer_##_funcname; \ |
|
skamonkey@3899
|
1047 |
class CCommandMemberInitializer_##_funcname \ |
|
skamonkey@3899
|
1048 |
{ \ |
|
skamonkey@3899
|
1049 |
public: \ |
|
skamonkey@3899
|
1050 |
CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \ |
|
skamonkey@3899
|
1051 |
{ \ |
|
skamonkey@3899
|
1052 |
m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \ |
|
skamonkey@3899
|
1053 |
} \ |
|
skamonkey@3899
|
1054 |
private: \ |
|
skamonkey@3899
|
1055 |
CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \ |
|
skamonkey@3899
|
1056 |
}; \ |
|
skamonkey@3899
|
1057 |
\ |
|
skamonkey@3899
|
1058 |
CCommandMemberInitializer_##_funcname m_##_funcname##_register; \ |
|
skamonkey@3899
|
1059 |
|
|
skamonkey@3899
|
1060 |
|
|
skamonkey@3899
|
1061 |
#endif // CONVAR_H |