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