|
ds@2400
|
1 |
//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======// |
|
ds@2400
|
2 |
// |
|
ds@2400
|
3 |
// Purpose: |
|
ds@2400
|
4 |
// |
|
ds@2400
|
5 |
// $Workfile: $ |
|
ds@2400
|
6 |
// $Date: $ |
|
ds@2400
|
7 |
// |
|
ds@2400
|
8 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
9 |
// $NoKeywords: $ |
|
ds@2400
|
10 |
//===========================================================================// |
|
ds@2400
|
11 |
|
|
ds@2400
|
12 |
#ifndef CONVAR_H |
|
ds@2400
|
13 |
#define CONVAR_H |
|
ds@2400
|
14 |
|
|
ds@2400
|
15 |
#if _WIN32 |
|
ds@2400
|
16 |
#pragma once |
|
ds@2400
|
17 |
#endif |
|
ds@2400
|
18 |
|
|
ds@2400
|
19 |
#include "tier0/dbg.h" |
|
ds@2400
|
20 |
#include "tier1/iconvar.h" |
|
ds@2400
|
21 |
#include "tier1/utlvector.h" |
|
ds@2400
|
22 |
#include "tier1/utlstring.h" |
|
ds@2400
|
23 |
#include "icvar.h" |
|
ds@2400
|
24 |
|
|
ds@2400
|
25 |
#ifdef _WIN32 |
|
ds@2400
|
26 |
#define FORCEINLINE_CVAR FORCEINLINE |
|
ds@3138
|
27 |
#elif defined _LINUX || defined __APPLE__ |
|
ds@2400
|
28 |
#define FORCEINLINE_CVAR inline |
|
ds@2400
|
29 |
#else |
|
ds@2400
|
30 |
#error "implement me" |
|
ds@2400
|
31 |
#endif |
|
ds@2400
|
32 |
|
|
ds@2400
|
33 |
|
|
ds@2400
|
34 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
35 |
// Forward declarations |
|
ds@2400
|
36 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
37 |
class ConVar; |
|
ds@2400
|
38 |
class CCommand; |
|
ds@2400
|
39 |
class ConCommand; |
|
ds@2400
|
40 |
class ConCommandBase; |
|
ds@2400
|
41 |
struct characterset_t; |
|
ds@2400
|
42 |
|
|
ds@2400
|
43 |
|
|
ds@2400
|
44 |
|
|
ds@2400
|
45 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
46 |
// Any executable that wants to use ConVars need to implement one of |
|
ds@2400
|
47 |
// these to hook up access to console variables. |
|
ds@2400
|
48 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
49 |
class IConCommandBaseAccessor |
|
ds@2400
|
50 |
{ |
|
ds@2400
|
51 |
public: |
|
ds@2400
|
52 |
// Flags is a combination of FCVAR flags in cvar.h. |
|
ds@2400
|
53 |
// hOut is filled in with a handle to the variable. |
|
ds@2400
|
54 |
virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0; |
|
ds@2400
|
55 |
}; |
|
ds@2400
|
56 |
|
|
ds@2400
|
57 |
|
|
ds@2400
|
58 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
59 |
// Helper method for console development |
|
ds@2400
|
60 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
61 |
#if defined( _X360 ) && !defined( _RETAIL ) |
|
ds@2400
|
62 |
void ConVar_PublishToVXConsole(); |
|
ds@2400
|
63 |
#endif |
|
ds@2400
|
64 |
|
|
ds@2400
|
65 |
|
|
ds@2400
|
66 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
67 |
// Called when a ConCommand needs to execute |
|
ds@2400
|
68 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
69 |
typedef void ( *FnCommandCallbackV1_t )( void ); |
|
ds@2400
|
70 |
typedef void ( *FnCommandCallback_t )( const CCommand &command ); |
|
ds@2400
|
71 |
|
|
ds@2400
|
72 |
#define COMMAND_COMPLETION_MAXITEMS 64 |
|
ds@2400
|
73 |
#define COMMAND_COMPLETION_ITEM_LENGTH 64 |
|
ds@2400
|
74 |
|
|
ds@2400
|
75 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
76 |
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings |
|
ds@2400
|
77 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
78 |
typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ); |
|
ds@2400
|
79 |
|
|
ds@2400
|
80 |
|
|
ds@2400
|
81 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
82 |
// Interface version |
|
ds@2400
|
83 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
84 |
class ICommandCallback |
|
ds@2400
|
85 |
{ |
|
ds@2400
|
86 |
public: |
|
ds@2400
|
87 |
virtual void CommandCallback( const CCommand &command ) = 0; |
|
ds@2400
|
88 |
}; |
|
ds@2400
|
89 |
|
|
ds@2400
|
90 |
class ICommandCompletionCallback |
|
ds@2400
|
91 |
{ |
|
ds@2400
|
92 |
public: |
|
ds@2400
|
93 |
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0; |
|
ds@2400
|
94 |
}; |
|
ds@2400
|
95 |
|
|
ds@2400
|
96 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
97 |
// Purpose: The base console invoked command/cvar interface |
|
ds@2400
|
98 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
99 |
class ConCommandBase |
|
ds@2400
|
100 |
{ |
|
ds@2400
|
101 |
friend class CCvar; |
|
ds@2400
|
102 |
friend class ConVar; |
|
ds@2400
|
103 |
friend class ConCommand; |
|
ds@2400
|
104 |
friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor ); |
|
ds@2400
|
105 |
friend void ConVar_PublishToVXConsole(); |
|
ds@2400
|
106 |
|
|
ds@2400
|
107 |
// FIXME: Remove when ConVar changes are done |
|
ds@2400
|
108 |
friend class CDefaultCvar; |
|
ds@2400
|
109 |
|
|
ds@2400
|
110 |
public: |
|
ds@2400
|
111 |
ConCommandBase( void ); |
|
ds@2400
|
112 |
ConCommandBase( const char *pName, const char *pHelpString = 0, |
|
ds@2400
|
113 |
int flags = 0 ); |
|
ds@2400
|
114 |
|
|
ds@2400
|
115 |
virtual ~ConCommandBase( void ); |
|
ds@2400
|
116 |
|
|
ds@2400
|
117 |
virtual bool IsCommand( void ) const; |
|
ds@2400
|
118 |
|
|
ds@2400
|
119 |
// Check flag |
|
ds@2400
|
120 |
virtual bool IsFlagSet( int flag ) const; |
|
ds@2400
|
121 |
// Set flag |
|
ds@2400
|
122 |
virtual void AddFlags( int flags ); |
|
ds@2400
|
123 |
// Remove flag |
|
ds@2400
|
124 |
virtual void RemoveFlags( int flags ); |
|
ds@2400
|
125 |
// Get flags |
|
ds@2400
|
126 |
virtual int GetFlags( void ) const; |
|
ds@2400
|
127 |
|
|
ds@2400
|
128 |
// Return name of cvar |
|
ds@2400
|
129 |
virtual const char *GetName( void ) const; |
|
ds@2400
|
130 |
|
|
ds@2400
|
131 |
// Return help text for cvar |
|
ds@2400
|
132 |
virtual const char *GetHelpText( void ) const; |
|
ds@2400
|
133 |
|
|
ds@2400
|
134 |
// Deal with next pointer |
|
ds@2400
|
135 |
const ConCommandBase *GetNext( void ) const; |
|
ds@2400
|
136 |
ConCommandBase *GetNext( void ); |
|
ds@2400
|
137 |
|
|
ds@2400
|
138 |
inline void SetNext(ConCommandBase *pBase) |
|
ds@2400
|
139 |
{ |
|
ds@2400
|
140 |
m_pNext = pBase; |
|
ds@2400
|
141 |
} |
|
ds@2400
|
142 |
|
|
ds@2400
|
143 |
virtual bool IsRegistered( void ) const; |
|
ds@2400
|
144 |
|
|
ds@2400
|
145 |
// Returns the DLL identifier |
|
ds@2400
|
146 |
virtual CVarDLLIdentifier_t GetDLLIdentifier() const; |
|
ds@2400
|
147 |
|
|
ds@2400
|
148 |
protected: |
|
ds@2400
|
149 |
virtual void Create( const char *pName, const char *pHelpString = 0, |
|
ds@2400
|
150 |
int flags = 0 ); |
|
ds@2400
|
151 |
|
|
ds@2400
|
152 |
// Used internally by OneTimeInit to initialize/shutdown |
|
ds@2400
|
153 |
virtual void Init(); |
|
ds@2400
|
154 |
void Shutdown(); |
|
ds@2400
|
155 |
|
|
ds@2400
|
156 |
// Internal copy routine ( uses new operator from correct module ) |
|
ds@2400
|
157 |
char *CopyString( const char *from ); |
|
ds@2400
|
158 |
|
|
ds@2400
|
159 |
private: |
|
ds@2400
|
160 |
// Next ConVar in chain |
|
ds@2400
|
161 |
// Prior to register, it points to the next convar in the DLL. |
|
ds@2400
|
162 |
// Once registered, though, m_pNext is reset to point to the next |
|
ds@2400
|
163 |
// convar in the global list |
|
ds@2400
|
164 |
ConCommandBase *m_pNext; |
|
ds@2400
|
165 |
|
|
ds@2400
|
166 |
// Has the cvar been added to the global list? |
|
ds@2400
|
167 |
bool m_bRegistered; |
|
ds@2400
|
168 |
|
|
ds@2400
|
169 |
// Static data |
|
ds@2400
|
170 |
const char *m_pszName; |
|
ds@2400
|
171 |
const char *m_pszHelpString; |
|
ds@2400
|
172 |
|
|
ds@2400
|
173 |
// ConVar flags |
|
ds@2400
|
174 |
int m_nFlags; |
|
ds@2400
|
175 |
|
|
ds@2400
|
176 |
protected: |
|
ds@2400
|
177 |
// ConVars add themselves to this list for the executable. |
|
ds@2400
|
178 |
// Then ConVar_Register runs through all the console variables |
|
ds@2400
|
179 |
// and registers them into a global list stored in vstdlib.dll |
|
ds@2400
|
180 |
static ConCommandBase *s_pConCommandBases; |
|
ds@2400
|
181 |
|
|
ds@2400
|
182 |
// ConVars in this executable use this 'global' to access values. |
|
ds@2400
|
183 |
static IConCommandBaseAccessor *s_pAccessor; |
|
ds@2400
|
184 |
public: |
|
ds@2400
|
185 |
inline void SetFlags(int flags) |
|
ds@2400
|
186 |
{ |
|
ds@2400
|
187 |
m_nFlags = flags; |
|
ds@2400
|
188 |
} |
|
ds@2400
|
189 |
}; |
|
ds@2400
|
190 |
|
|
ds@2400
|
191 |
|
|
ds@2400
|
192 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
193 |
// Command tokenizer |
|
ds@2400
|
194 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
195 |
class CCommand |
|
ds@2400
|
196 |
{ |
|
ds@2400
|
197 |
public: |
|
ds@2400
|
198 |
CCommand(); |
|
ds@2400
|
199 |
CCommand( int nArgC, const char **ppArgV ); |
|
ds@2400
|
200 |
bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL ); |
|
ds@2400
|
201 |
void Reset(); |
|
ds@2400
|
202 |
|
|
ds@2400
|
203 |
int ArgC() const; |
|
ds@2400
|
204 |
const char **ArgV() const; |
|
ds@2400
|
205 |
const char *ArgS() const; // All args that occur after the 0th arg, in string form |
|
ds@2400
|
206 |
const char *GetCommandString() const; // The entire command in string form, including the 0th arg |
|
ds@2400
|
207 |
const char *operator[]( int nIndex ) const; // Gets at arguments |
|
ds@2400
|
208 |
const char *Arg( int nIndex ) const; // Gets at arguments |
|
ds@2400
|
209 |
|
|
ds@2400
|
210 |
// Helper functions to parse arguments to commands. |
|
ds@2400
|
211 |
const char* FindArg( const char *pName ) const; |
|
ds@2400
|
212 |
int FindArgInt( const char *pName, int nDefaultVal ) const; |
|
ds@2400
|
213 |
|
|
ds@2400
|
214 |
static int MaxCommandLength(); |
|
ds@2400
|
215 |
static characterset_t* DefaultBreakSet(); |
|
ds@2400
|
216 |
|
|
ds@2400
|
217 |
private: |
|
ds@2400
|
218 |
enum |
|
ds@2400
|
219 |
{ |
|
ds@2400
|
220 |
COMMAND_MAX_ARGC = 64, |
|
ds@2400
|
221 |
COMMAND_MAX_LENGTH = 512, |
|
ds@2400
|
222 |
}; |
|
ds@2400
|
223 |
|
|
ds@2400
|
224 |
int m_nArgc; |
|
ds@2400
|
225 |
int m_nArgv0Size; |
|
ds@2400
|
226 |
char m_pArgSBuffer[ COMMAND_MAX_LENGTH ]; |
|
ds@2400
|
227 |
char m_pArgvBuffer[ COMMAND_MAX_LENGTH ]; |
|
ds@2400
|
228 |
const char* m_ppArgv[ COMMAND_MAX_ARGC ]; |
|
ds@2400
|
229 |
}; |
|
ds@2400
|
230 |
|
|
ds@2400
|
231 |
inline int CCommand::MaxCommandLength() |
|
ds@2400
|
232 |
{ |
|
ds@2400
|
233 |
return COMMAND_MAX_LENGTH - 1; |
|
ds@2400
|
234 |
} |
|
ds@2400
|
235 |
|
|
ds@2400
|
236 |
inline int CCommand::ArgC() const |
|
ds@2400
|
237 |
{ |
|
ds@2400
|
238 |
return m_nArgc; |
|
ds@2400
|
239 |
} |
|
ds@2400
|
240 |
|
|
ds@2400
|
241 |
inline const char **CCommand::ArgV() const |
|
ds@2400
|
242 |
{ |
|
ds@2400
|
243 |
return m_nArgc ? (const char**)m_ppArgv : NULL; |
|
ds@2400
|
244 |
} |
|
ds@2400
|
245 |
|
|
ds@2400
|
246 |
inline const char *CCommand::ArgS() const |
|
ds@2400
|
247 |
{ |
|
ds@2400
|
248 |
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : ""; |
|
ds@2400
|
249 |
} |
|
ds@2400
|
250 |
|
|
ds@2400
|
251 |
inline const char *CCommand::GetCommandString() const |
|
ds@2400
|
252 |
{ |
|
ds@2400
|
253 |
return m_nArgc ? m_pArgSBuffer : ""; |
|
ds@2400
|
254 |
} |
|
ds@2400
|
255 |
|
|
ds@2400
|
256 |
inline const char *CCommand::Arg( int nIndex ) const |
|
ds@2400
|
257 |
{ |
|
ds@2400
|
258 |
// FIXME: Many command handlers appear to not be particularly careful |
|
ds@2400
|
259 |
// about checking for valid argc range. For now, we're going to |
|
ds@2400
|
260 |
// do the extra check and return an empty string if it's out of range |
|
ds@2400
|
261 |
if ( nIndex < 0 || nIndex >= m_nArgc ) |
|
ds@2400
|
262 |
return ""; |
|
ds@2400
|
263 |
return m_ppArgv[nIndex]; |
|
ds@2400
|
264 |
} |
|
ds@2400
|
265 |
|
|
ds@2400
|
266 |
inline const char *CCommand::operator[]( int nIndex ) const |
|
ds@2400
|
267 |
{ |
|
ds@2400
|
268 |
return Arg( nIndex ); |
|
ds@2400
|
269 |
} |
|
ds@2400
|
270 |
|
|
ds@2400
|
271 |
|
|
ds@2400
|
272 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
273 |
// Purpose: The console invoked command |
|
ds@2400
|
274 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
275 |
class ConCommand : public ConCommandBase |
|
ds@2400
|
276 |
{ |
|
ds@2400
|
277 |
friend class CCvar; |
|
ds@2400
|
278 |
|
|
ds@2400
|
279 |
public: |
|
ds@2400
|
280 |
typedef ConCommandBase BaseClass; |
|
ds@2400
|
281 |
|
|
ds@2400
|
282 |
ConCommand( const char *pName, FnCommandCallbackV1_t callback, |
|
ds@2400
|
283 |
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); |
|
ds@2400
|
284 |
ConCommand( const char *pName, FnCommandCallback_t callback, |
|
ds@2400
|
285 |
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 ); |
|
ds@2400
|
286 |
ConCommand( const char *pName, ICommandCallback *pCallback, |
|
ds@2400
|
287 |
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 ); |
|
ds@2400
|
288 |
|
|
ds@2400
|
289 |
virtual ~ConCommand( void ); |
|
ds@2400
|
290 |
|
|
ds@2400
|
291 |
virtual bool IsCommand( void ) const; |
|
ds@2400
|
292 |
|
|
ds@2400
|
293 |
virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands ); |
|
ds@2400
|
294 |
|
|
ds@2400
|
295 |
virtual bool CanAutoComplete( void ); |
|
ds@2400
|
296 |
|
|
ds@2400
|
297 |
// Invoke the function |
|
ds@2400
|
298 |
virtual void Dispatch( const CCommand &command ); |
|
ds@2400
|
299 |
|
|
ds@2400
|
300 |
private: |
|
ds@2400
|
301 |
// NOTE: To maintain backward compat, we have to be very careful: |
|
ds@2400
|
302 |
// All public virtual methods must appear in the same order always |
|
ds@2400
|
303 |
// since engine code will be calling into this code, which *does not match* |
|
ds@2400
|
304 |
// in the mod code; it's using slightly different, but compatible versions |
|
ds@2400
|
305 |
// of this class. Also: Be very careful about adding new fields to this class. |
|
ds@2400
|
306 |
// Those fields will not exist in the version of this class that is instanced |
|
ds@2400
|
307 |
// in mod code. |
|
ds@2400
|
308 |
|
|
ds@2400
|
309 |
// Call this function when executing the command |
|
ds@2400
|
310 |
union |
|
ds@2400
|
311 |
{ |
|
ds@2400
|
312 |
FnCommandCallbackV1_t m_fnCommandCallbackV1; |
|
ds@2400
|
313 |
FnCommandCallback_t m_fnCommandCallback; |
|
ds@2400
|
314 |
ICommandCallback *m_pCommandCallback; |
|
ds@2400
|
315 |
}; |
|
ds@2400
|
316 |
|
|
ds@2400
|
317 |
union |
|
ds@2400
|
318 |
{ |
|
ds@2400
|
319 |
FnCommandCompletionCallback m_fnCompletionCallback; |
|
ds@2400
|
320 |
ICommandCompletionCallback *m_pCommandCompletionCallback; |
|
ds@2400
|
321 |
}; |
|
ds@2400
|
322 |
|
|
ds@2400
|
323 |
bool m_bHasCompletionCallback : 1; |
|
ds@2400
|
324 |
bool m_bUsingNewCommandCallback : 1; |
|
ds@2400
|
325 |
bool m_bUsingCommandCallbackInterface : 1; |
|
ds@2400
|
326 |
public: |
|
ds@2400
|
327 |
inline FnCommandCallback_t GetCallback() const |
|
ds@2400
|
328 |
{ |
|
ds@2400
|
329 |
return m_fnCommandCallback; |
|
ds@2400
|
330 |
} |
|
ds@2400
|
331 |
}; |
|
ds@2400
|
332 |
|
|
ds@2400
|
333 |
|
|
ds@2400
|
334 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
335 |
// Purpose: A console variable |
|
ds@2400
|
336 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
337 |
class ConVar : public ConCommandBase, public IConVar |
|
ds@2400
|
338 |
{ |
|
ds@2400
|
339 |
friend class CCvar; |
|
ds@2400
|
340 |
friend class ConVarRef; |
|
ds@2400
|
341 |
|
|
ds@2400
|
342 |
public: |
|
ds@2400
|
343 |
typedef ConCommandBase BaseClass; |
|
ds@2400
|
344 |
|
|
ds@2400
|
345 |
ConVar( const char *pName, const char *pDefaultValue, int flags = 0); |
|
ds@2400
|
346 |
|
|
ds@2400
|
347 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
ds@2400
|
348 |
const char *pHelpString ); |
|
ds@2400
|
349 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
ds@2400
|
350 |
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax ); |
|
ds@2400
|
351 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
ds@2400
|
352 |
const char *pHelpString, FnChangeCallback_t callback ); |
|
ds@2400
|
353 |
ConVar( const char *pName, const char *pDefaultValue, int flags, |
|
ds@2400
|
354 |
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax, |
|
ds@2400
|
355 |
FnChangeCallback_t callback ); |
|
ds@2400
|
356 |
|
|
ds@2400
|
357 |
virtual ~ConVar( void ); |
|
ds@2400
|
358 |
|
|
ds@2400
|
359 |
virtual bool IsCommand( void ) const; |
|
ds@2400
|
360 |
virtual bool IsFlagSet( int flag ) const; |
|
ds@2400
|
361 |
virtual void AddFlags( int flags ); |
|
ds@2400
|
362 |
virtual int GetFlags( void ) const; |
|
ds@2400
|
363 |
virtual const char *GetName( void ) const; |
|
ds@2400
|
364 |
virtual const char* GetHelpText( void ) const; |
|
ds@2400
|
365 |
virtual bool IsRegistered( void ) const; |
|
ds@2400
|
366 |
|
|
ds@2400
|
367 |
// Install a change callback (there shouldn't already be one....) |
|
ds@2400
|
368 |
void InstallChangeCallback( FnChangeCallback_t callback ); |
|
ds@2400
|
369 |
|
|
ds@2400
|
370 |
// Retrieve value |
|
ds@2400
|
371 |
FORCEINLINE_CVAR float GetFloat( void ) const; |
|
ds@2400
|
372 |
FORCEINLINE_CVAR int GetInt( void ) const; |
|
ds@2400
|
373 |
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); } |
|
ds@2400
|
374 |
FORCEINLINE_CVAR char const *GetString( void ) const; |
|
ds@2400
|
375 |
|
|
ds@2400
|
376 |
// Used internally by OneTimeInit to initialize. |
|
ds@2400
|
377 |
virtual void Init(); |
|
ds@2400
|
378 |
|
|
ds@2400
|
379 |
virtual const char *GetBaseName( void ) const; |
|
ds@2400
|
380 |
virtual int GetSplitScreenPlayerSlot ( void ) const; |
|
ds@2400
|
381 |
|
|
ds@2400
|
382 |
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes |
|
ds@2400
|
383 |
// from alloc/free across dll/exe boundaries. |
|
ds@2400
|
384 |
|
|
ds@2400
|
385 |
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue). |
|
ds@2400
|
386 |
virtual void SetValue( const char *value ); |
|
ds@2400
|
387 |
virtual void SetValue( float value ); |
|
ds@2400
|
388 |
virtual void SetValue( int value ); |
|
ds@3099
|
389 |
#if SOURCE_ENGINE >= SE_LEFT4DEAD2 |
|
pred@2850
|
390 |
virtual void SetValue( Color value ); |
|
pred@2850
|
391 |
#endif |
|
ds@2400
|
392 |
|
|
ds@2400
|
393 |
// Reset to default value |
|
ds@2400
|
394 |
void Revert( void ); |
|
ds@2400
|
395 |
|
|
ds@2400
|
396 |
// True if it has a min/max setting |
|
ds@2400
|
397 |
bool GetMin( float& minVal ) const; |
|
ds@2400
|
398 |
bool GetMax( float& maxVal ) const; |
|
ds@2400
|
399 |
const char *GetDefault( void ) const; |
|
ds@2400
|
400 |
|
|
ds@2400
|
401 |
private: |
|
ds@2400
|
402 |
// Called by CCvar when the value of a var is changing. |
|
ds@2400
|
403 |
virtual void InternalSetValue(const char *value); |
|
ds@2400
|
404 |
// For CVARs marked FCVAR_NEVER_AS_STRING |
|
ds@2400
|
405 |
virtual void InternalSetFloatValue( float fNewValue ); |
|
ds@2400
|
406 |
virtual void InternalSetIntValue( int nValue ); |
|
ds@3099
|
407 |
#if SOURCE_ENGINE >= SE_LEFT4DEAD2 |
|
ds@3099
|
408 |
virtual void InternalSetColorValue( Color value ); |
|
ds@3099
|
409 |
#endif |
|
ds@2400
|
410 |
|
|
ds@2400
|
411 |
virtual bool ClampValue( float& value ); |
|
ds@2400
|
412 |
virtual void ChangeStringValue( const char *tempVal, float flOldValue ); |
|
ds@2400
|
413 |
|
|
ds@2400
|
414 |
virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0, |
|
ds@2400
|
415 |
const char *pHelpString = 0, bool bMin = false, float fMin = 0.0, |
|
ds@2400
|
416 |
bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 ); |
|
ds@2400
|
417 |
|
|
ds@2400
|
418 |
private: |
|
ds@2400
|
419 |
|
|
ds@2400
|
420 |
// This either points to "this" or it points to the original declaration of a ConVar. |
|
ds@2400
|
421 |
// This allows ConVars to exist in separate modules, and they all use the first one to be declared. |
|
ds@2400
|
422 |
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar). |
|
ds@2400
|
423 |
ConVar *m_pParent; |
|
ds@2400
|
424 |
|
|
ds@2400
|
425 |
// Static data |
|
ds@2400
|
426 |
const char *m_pszDefaultValue; |
|
ds@2400
|
427 |
|
|
ds@2400
|
428 |
// Value |
|
ds@2400
|
429 |
// Dynamically allocated |
|
ds@2400
|
430 |
char *m_pszString; |
|
ds@2400
|
431 |
int m_StringLength; |
|
ds@2400
|
432 |
|
|
ds@2400
|
433 |
// Values |
|
ds@2400
|
434 |
float m_fValue; |
|
ds@2400
|
435 |
int m_nValue; |
|
ds@2400
|
436 |
|
|
ds@2400
|
437 |
// Min/Max values |
|
ds@2400
|
438 |
bool m_bHasMin; |
|
ds@2400
|
439 |
float m_fMinVal; |
|
ds@2400
|
440 |
bool m_bHasMax; |
|
ds@2400
|
441 |
float m_fMaxVal; |
|
ds@2400
|
442 |
|
|
ds@2400
|
443 |
// Call this function when ConVar changes |
|
ds@2400
|
444 |
FnChangeCallback_t m_fnChangeCallback; |
|
ds@2400
|
445 |
public: |
|
ds@2400
|
446 |
inline FnChangeCallback_t GetCallback() const |
|
ds@2400
|
447 |
{ |
|
ds@2400
|
448 |
return m_fnChangeCallback; |
|
ds@2400
|
449 |
} |
|
ds@2400
|
450 |
inline void SetMin(bool set, float min=0.0) |
|
ds@2400
|
451 |
{ |
|
ds@2400
|
452 |
m_bHasMin = set; |
|
ds@2400
|
453 |
m_fMinVal = min; |
|
ds@2400
|
454 |
} |
|
ds@2400
|
455 |
inline void SetMax(bool set, float max=0.0) |
|
ds@2400
|
456 |
{ |
|
ds@2400
|
457 |
m_bHasMax = set; |
|
ds@2400
|
458 |
m_fMaxVal = max; |
|
ds@2400
|
459 |
} |
|
ds@2400
|
460 |
}; |
|
ds@2400
|
461 |
|
|
ds@2400
|
462 |
|
|
ds@2400
|
463 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
464 |
// Purpose: Return ConVar value as a float |
|
ds@2400
|
465 |
// Output : float |
|
ds@2400
|
466 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
467 |
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const |
|
ds@2400
|
468 |
{ |
|
ds@2400
|
469 |
return m_pParent->m_fValue; |
|
ds@2400
|
470 |
} |
|
ds@2400
|
471 |
|
|
ds@2400
|
472 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
473 |
// Purpose: Return ConVar value as an int |
|
ds@2400
|
474 |
// Output : int |
|
ds@2400
|
475 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
476 |
FORCEINLINE_CVAR int ConVar::GetInt( void ) const |
|
ds@2400
|
477 |
{ |
|
ds@2400
|
478 |
return m_pParent->m_nValue; |
|
ds@2400
|
479 |
} |
|
ds@2400
|
480 |
|
|
ds@2400
|
481 |
|
|
ds@2400
|
482 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
483 |
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. |
|
ds@2400
|
484 |
// Output : const char * |
|
ds@2400
|
485 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
486 |
FORCEINLINE_CVAR const char *ConVar::GetString( void ) const |
|
ds@2400
|
487 |
{ |
|
ds@2400
|
488 |
if ( m_nFlags & FCVAR_NEVER_AS_STRING ) |
|
ds@2400
|
489 |
return "FCVAR_NEVER_AS_STRING"; |
|
ds@2400
|
490 |
|
|
ds@2400
|
491 |
return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : ""; |
|
ds@2400
|
492 |
} |
|
ds@2400
|
493 |
|
|
ds@2400
|
494 |
|
|
ds@2400
|
495 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
496 |
// Used to read/write convars that already exist (replaces the FindVar method) |
|
ds@2400
|
497 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
498 |
class ConVarRef |
|
ds@2400
|
499 |
{ |
|
ds@2400
|
500 |
public: |
|
ds@2400
|
501 |
ConVarRef( const char *pName ); |
|
ds@2400
|
502 |
ConVarRef( const char *pName, bool bIgnoreMissing ); |
|
ds@2400
|
503 |
ConVarRef( IConVar *pConVar ); |
|
ds@2400
|
504 |
|
|
ds@2400
|
505 |
void Init( const char *pName, bool bIgnoreMissing ); |
|
ds@2400
|
506 |
bool IsValid() const; |
|
ds@2400
|
507 |
bool IsFlagSet( int nFlags ) const; |
|
ds@2400
|
508 |
IConVar *GetLinkedConVar(); |
|
ds@2400
|
509 |
|
|
ds@2400
|
510 |
// Get/Set value |
|
ds@2400
|
511 |
float GetFloat( void ) const; |
|
ds@2400
|
512 |
int GetInt( void ) const; |
|
ds@2400
|
513 |
bool GetBool() const { return !!GetInt(); } |
|
ds@2400
|
514 |
const char *GetString( void ) const; |
|
ds@2400
|
515 |
|
|
ds@2400
|
516 |
void SetValue( const char *pValue ); |
|
ds@2400
|
517 |
void SetValue( float flValue ); |
|
ds@2400
|
518 |
void SetValue( int nValue ); |
|
ds@2400
|
519 |
void SetValue( bool bValue ); |
|
ds@2400
|
520 |
|
|
ds@2400
|
521 |
const char *GetName() const; |
|
ds@2400
|
522 |
|
|
ds@2400
|
523 |
const char *GetDefault() const; |
|
ds@2400
|
524 |
|
|
ds@2400
|
525 |
private: |
|
ds@2400
|
526 |
// High-speed method to read convar data |
|
ds@2400
|
527 |
IConVar *m_pConVar; |
|
ds@2400
|
528 |
ConVar *m_pConVarState; |
|
ds@2400
|
529 |
}; |
|
ds@2400
|
530 |
|
|
ds@2400
|
531 |
|
|
ds@2400
|
532 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
533 |
// Did we find an existing convar of that name? |
|
ds@2400
|
534 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
535 |
FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const |
|
ds@2400
|
536 |
{ |
|
ds@2400
|
537 |
return ( m_pConVar->IsFlagSet( nFlags ) != 0 ); |
|
ds@2400
|
538 |
} |
|
ds@2400
|
539 |
|
|
ds@2400
|
540 |
FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar() |
|
ds@2400
|
541 |
{ |
|
ds@2400
|
542 |
return m_pConVar; |
|
ds@2400
|
543 |
} |
|
ds@2400
|
544 |
|
|
ds@2400
|
545 |
FORCEINLINE_CVAR const char *ConVarRef::GetName() const |
|
ds@2400
|
546 |
{ |
|
ds@2400
|
547 |
return m_pConVar->GetName(); |
|
ds@2400
|
548 |
} |
|
ds@2400
|
549 |
|
|
ds@2400
|
550 |
|
|
ds@2400
|
551 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
552 |
// Purpose: Return ConVar value as a float |
|
ds@2400
|
553 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
554 |
FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const |
|
ds@2400
|
555 |
{ |
|
ds@2400
|
556 |
return m_pConVarState->m_fValue; |
|
ds@2400
|
557 |
} |
|
ds@2400
|
558 |
|
|
ds@2400
|
559 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
560 |
// Purpose: Return ConVar value as an int |
|
ds@2400
|
561 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
562 |
FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const |
|
ds@2400
|
563 |
{ |
|
ds@2400
|
564 |
return m_pConVarState->m_nValue; |
|
ds@2400
|
565 |
} |
|
ds@2400
|
566 |
|
|
ds@2400
|
567 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
568 |
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc. |
|
ds@2400
|
569 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
570 |
FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const |
|
ds@2400
|
571 |
{ |
|
ds@2400
|
572 |
Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) ); |
|
ds@2400
|
573 |
return m_pConVarState->m_pszString; |
|
ds@2400
|
574 |
} |
|
ds@2400
|
575 |
|
|
ds@2400
|
576 |
|
|
ds@2400
|
577 |
FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue ) |
|
ds@2400
|
578 |
{ |
|
ds@2400
|
579 |
m_pConVar->SetValue( pValue ); |
|
ds@2400
|
580 |
} |
|
ds@2400
|
581 |
|
|
ds@2400
|
582 |
FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue ) |
|
ds@2400
|
583 |
{ |
|
ds@2400
|
584 |
m_pConVar->SetValue( flValue ); |
|
ds@2400
|
585 |
} |
|
ds@2400
|
586 |
|
|
ds@2400
|
587 |
FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue ) |
|
ds@2400
|
588 |
{ |
|
ds@2400
|
589 |
m_pConVar->SetValue( nValue ); |
|
ds@2400
|
590 |
} |
|
ds@2400
|
591 |
|
|
ds@2400
|
592 |
FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue ) |
|
ds@2400
|
593 |
{ |
|
ds@2400
|
594 |
m_pConVar->SetValue( bValue ? 1 : 0 ); |
|
ds@2400
|
595 |
} |
|
ds@2400
|
596 |
|
|
ds@2400
|
597 |
FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const |
|
ds@2400
|
598 |
{ |
|
ds@2400
|
599 |
return m_pConVarState->m_pszDefaultValue; |
|
ds@2400
|
600 |
} |
|
ds@2400
|
601 |
|
|
ds@2400
|
602 |
|
|
ds@2400
|
603 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
604 |
// Called by the framework to register ConCommands with the ICVar |
|
ds@2400
|
605 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
606 |
void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL ); |
|
ds@2400
|
607 |
void ConVar_Unregister( ); |
|
ds@2400
|
608 |
|
|
ds@2400
|
609 |
|
|
ds@2400
|
610 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
611 |
// Utility methods |
|
ds@2400
|
612 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
613 |
void ConVar_PrintFlags( const ConCommandBase *var ); |
|
ds@2400
|
614 |
void ConVar_PrintDescription( const ConCommandBase *pVar ); |
|
ds@2400
|
615 |
|
|
ds@2400
|
616 |
|
|
ds@2400
|
617 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
618 |
// Purpose: Utility class to quickly allow ConCommands to call member methods |
|
ds@2400
|
619 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
620 |
#ifdef _MSC_VER |
|
ds@2400
|
621 |
#pragma warning (disable : 4355 ) |
|
ds@2400
|
622 |
#endif |
|
ds@2400
|
623 |
|
|
ds@2400
|
624 |
template< class T > |
|
ds@2400
|
625 |
class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback |
|
ds@2400
|
626 |
{ |
|
ds@2400
|
627 |
typedef ConCommand BaseClass; |
|
ds@2400
|
628 |
typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command ); |
|
ds@2400
|
629 |
typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands ); |
|
ds@2400
|
630 |
|
|
ds@2400
|
631 |
public: |
|
ds@2400
|
632 |
CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0, |
|
ds@2400
|
633 |
int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) : |
|
ds@2400
|
634 |
BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL ) |
|
ds@2400
|
635 |
{ |
|
ds@2400
|
636 |
m_pOwner = pOwner; |
|
ds@2400
|
637 |
m_Func = callback; |
|
ds@2400
|
638 |
m_CompletionFunc = completionFunc; |
|
ds@2400
|
639 |
} |
|
ds@2400
|
640 |
|
|
ds@2400
|
641 |
~CConCommandMemberAccessor() |
|
ds@2400
|
642 |
{ |
|
ds@2400
|
643 |
Shutdown(); |
|
ds@2400
|
644 |
} |
|
ds@2400
|
645 |
|
|
ds@2400
|
646 |
void SetOwner( T* pOwner ) |
|
ds@2400
|
647 |
{ |
|
ds@2400
|
648 |
m_pOwner = pOwner; |
|
ds@2400
|
649 |
} |
|
ds@2400
|
650 |
|
|
ds@2400
|
651 |
virtual void CommandCallback( const CCommand &command ) |
|
ds@2400
|
652 |
{ |
|
ds@2400
|
653 |
Assert( m_pOwner && m_Func ); |
|
ds@2400
|
654 |
(m_pOwner->*m_Func)( command ); |
|
ds@2400
|
655 |
} |
|
ds@2400
|
656 |
|
|
ds@2400
|
657 |
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) |
|
ds@2400
|
658 |
{ |
|
ds@2400
|
659 |
Assert( m_pOwner && m_CompletionFunc ); |
|
ds@2400
|
660 |
return (m_pOwner->*m_CompletionFunc)( pPartial, commands ); |
|
ds@2400
|
661 |
} |
|
ds@2400
|
662 |
|
|
ds@2400
|
663 |
private: |
|
ds@2400
|
664 |
T* m_pOwner; |
|
ds@2400
|
665 |
FnMemberCommandCallback_t m_Func; |
|
ds@2400
|
666 |
FnMemberCommandCompletionCallback_t m_CompletionFunc; |
|
ds@2400
|
667 |
}; |
|
ds@2400
|
668 |
|
|
ds@2400
|
669 |
#ifdef _MSC_VER |
|
ds@2400
|
670 |
#pragma warning ( default : 4355 ) |
|
ds@2400
|
671 |
#endif |
|
ds@2400
|
672 |
|
|
ds@2400
|
673 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
674 |
// Purpose: Utility macros to quicky generate a simple console command |
|
ds@2400
|
675 |
//----------------------------------------------------------------------------- |
|
ds@2400
|
676 |
#define CON_COMMAND( name, description ) \ |
|
ds@2400
|
677 |
static void name( const CCommand &args ); \ |
|
ds@2400
|
678 |
static ConCommand name##_command( #name, name, description ); \ |
|
ds@2400
|
679 |
static void name( const CCommand &args ) |
|
ds@2400
|
680 |
|
|
ds@2400
|
681 |
#define CON_COMMAND_F( name, description, flags ) \ |
|
ds@2400
|
682 |
static void name( const CCommand &args ); \ |
|
ds@2400
|
683 |
static ConCommand name##_command( #name, name, description, flags ); \ |
|
ds@2400
|
684 |
static void name( const CCommand &args ) |
|
ds@2400
|
685 |
|
|
ds@2400
|
686 |
#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \ |
|
ds@2400
|
687 |
static void name( const CCommand &args ); \ |
|
ds@2400
|
688 |
static ConCommand name##_command( #name, name, description, flags, completion ); \ |
|
ds@2400
|
689 |
static void name( const CCommand &args ) |
|
ds@2400
|
690 |
|
|
ds@2400
|
691 |
#define CON_COMMAND_EXTERN( name, _funcname, description ) \ |
|
ds@2400
|
692 |
void _funcname( const CCommand &args ); \ |
|
ds@2400
|
693 |
static ConCommand name##_command( #name, _funcname, description ); \ |
|
ds@2400
|
694 |
void _funcname( const CCommand &args ) |
|
ds@2400
|
695 |
|
|
ds@2400
|
696 |
#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \ |
|
ds@2400
|
697 |
void _funcname( const CCommand &args ); \ |
|
ds@2400
|
698 |
static ConCommand name##_command( #name, _funcname, description, flags ); \ |
|
ds@2400
|
699 |
void _funcname( const CCommand &args ) |
|
ds@2400
|
700 |
|
|
ds@2400
|
701 |
#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \ |
|
ds@2400
|
702 |
void _funcname( const CCommand &args ); \ |
|
ds@2400
|
703 |
friend class CCommandMemberInitializer_##_funcname; \ |
|
ds@2400
|
704 |
class CCommandMemberInitializer_##_funcname \ |
|
ds@2400
|
705 |
{ \ |
|
ds@2400
|
706 |
public: \ |
|
ds@2400
|
707 |
CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \ |
|
ds@2400
|
708 |
{ \ |
|
ds@2400
|
709 |
m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \ |
|
ds@2400
|
710 |
} \ |
|
ds@2400
|
711 |
private: \ |
|
ds@2400
|
712 |
CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \ |
|
ds@2400
|
713 |
}; \ |
|
ds@2400
|
714 |
\ |
|
ds@2400
|
715 |
CCommandMemberInitializer_##_funcname m_##_funcname##_register; \ |
|
ds@2400
|
716 |
|
|
ds@2400
|
717 |
|
|
ds@2400
|
718 |
#endif // CONVAR_H |