Updated some CS:GO gamedata.
1 //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
8 //-----------------------------------------------------------------------------
10 //===========================================================================//
19 #include "tier0/dbg.h"
20 #include "tier1/iconvar.h"
21 #include "tier1/utlvector.h"
22 #include "tier1/utlstring.h"
27 #define FORCEINLINE_CVAR FORCEINLINE
29 #define FORCEINLINE_CVAR inline
35 //-----------------------------------------------------------------------------
36 // Uncomment me to test for threading issues for material system convars
37 // NOTE: You want to disable all threading when you do this
38 // +host_thread_mode 0 +r_threaded_particles 0 +sv_parallel_packentities 0 +sv_disable_querycache 0
39 //-----------------------------------------------------------------------------
40 //#define CONVAR_TEST_MATERIAL_THREAD_CONVARS 1
43 //-----------------------------------------------------------------------------
44 // Forward declarations
45 //-----------------------------------------------------------------------------
50 struct characterset_t;
54 //-----------------------------------------------------------------------------
55 // Any executable that wants to use ConVars need to implement one of
56 // these to hook up access to console variables.
57 //-----------------------------------------------------------------------------
58 class IConCommandBaseAccessor
61 // Flags is a combination of FCVAR flags in cvar.h.
62 // hOut is filled in with a handle to the variable.
63 virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
67 //-----------------------------------------------------------------------------
68 // Helper method for console development
69 //-----------------------------------------------------------------------------
71 void ConVar_PublishToVXConsole();
75 //-----------------------------------------------------------------------------
76 // Called when a ConCommand needs to execute
77 //-----------------------------------------------------------------------------
78 typedef void ( *FnCommandCallbackV1_t )( void );
79 typedef void ( *FnCommandCallback_t )( const CCommand &command );
81 #define COMMAND_COMPLETION_MAXITEMS 64
82 #define COMMAND_COMPLETION_ITEM_LENGTH 64
84 //-----------------------------------------------------------------------------
85 // Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
86 //-----------------------------------------------------------------------------
87 typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
90 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
93 class ICommandCallback
96 virtual void CommandCallback( const CCommand &command ) = 0;
99 class ICommandCompletionCallback
102 virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
105 //-----------------------------------------------------------------------------
106 // Purpose: The base console invoked command/cvar interface
107 //-----------------------------------------------------------------------------
112 friend class ConCommand;
113 friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
114 friend void ConVar_PublishToVXConsole();
116 // FIXME: Remove when ConVar changes are done
117 friend class CDefaultCvar;
120 ConCommandBase( void );
121 ConCommandBase( const char *pName, const char *pHelpString = 0,
124 virtual ~ConCommandBase( void );
126 virtual bool IsCommand( void ) const;
129 virtual bool IsFlagSet( int flag ) const;
131 virtual void AddFlags( int flags );
133 virtual void RemoveFlags( int flags );
135 virtual int GetFlags() const;
137 // Return name of cvar
138 virtual const char *GetName( void ) const;
140 // Return help text for cvar
141 virtual const char *GetHelpText( void ) const;
143 // Deal with next pointer
144 const ConCommandBase *GetNext( void ) const;
145 ConCommandBase *GetNext( void );
147 virtual bool IsRegistered( void ) const;
149 // Returns the DLL identifier
150 virtual CVarDLLIdentifier_t GetDLLIdentifier() const;
153 virtual void Create( const char *pName, const char *pHelpString = 0,
156 // Used internally by OneTimeInit to initialize/shutdown
160 // Internal copy routine ( uses new operator from correct module )
161 char *CopyString( const char *from );
164 // Next ConVar in chain
165 // Prior to register, it points to the next convar in the DLL.
166 // Once registered, though, m_pNext is reset to point to the next
167 // convar in the global list
168 ConCommandBase *m_pNext;
170 // Has the cvar been added to the global list?
174 const char *m_pszName;
175 const char *m_pszHelpString;
181 // ConVars add themselves to this list for the executable.
182 // Then ConVar_Register runs through all the console variables
183 // and registers them into a global list stored in vstdlib.dll
184 static ConCommandBase *s_pConCommandBases;
186 // ConVars in this executable use this 'global' to access values.
187 static IConCommandBaseAccessor *s_pAccessor;
189 inline void SetFlags(int flags)
196 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
203 CCommand( int nArgC, const char **ppArgV );
204 bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
208 const char **ArgV() const;
209 const char *ArgS() const; // All args that occur after the 0th arg, in string form
210 const char *GetCommandString() const; // The entire command in string form, including the 0th arg
211 const char *operator[]( int nIndex ) const; // Gets at arguments
212 const char *Arg( int nIndex ) const; // Gets at arguments
214 // Helper functions to parse arguments to commands.
215 const char* FindArg( const char *pName ) const;
216 int FindArgInt( const char *pName, int nDefaultVal ) const;
218 static int MaxCommandLength();
219 static characterset_t* DefaultBreakSet();
224 COMMAND_MAX_ARGC = 64,
225 COMMAND_MAX_LENGTH = 512,
230 char m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
231 char m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
232 const char* m_ppArgv[ COMMAND_MAX_ARGC ];
235 inline int CCommand::MaxCommandLength()
237 return COMMAND_MAX_LENGTH - 1;
240 inline int CCommand::ArgC() const
245 inline const char **CCommand::ArgV() const
247 return m_nArgc ? (const char**)m_ppArgv : NULL;
250 inline const char *CCommand::ArgS() const
252 return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
255 inline const char *CCommand::GetCommandString() const
257 return m_nArgc ? m_pArgSBuffer : "";
260 inline const char *CCommand::Arg( int nIndex ) const
262 // FIXME: Many command handlers appear to not be particularly careful
263 // about checking for valid argc range. For now, we're going to
264 // do the extra check and return an empty string if it's out of range
265 if ( nIndex < 0 || nIndex >= m_nArgc )
267 return m_ppArgv[nIndex];
270 inline const char *CCommand::operator[]( int nIndex ) const
272 return Arg( nIndex );
276 //-----------------------------------------------------------------------------
277 // Purpose: The console invoked command
278 //-----------------------------------------------------------------------------
279 class ConCommand : public ConCommandBase
284 typedef ConCommandBase BaseClass;
286 ConCommand( const char *pName, FnCommandCallbackV1_t callback,
287 const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
288 ConCommand( const char *pName, FnCommandCallback_t callback,
289 const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
290 ConCommand( const char *pName, ICommandCallback *pCallback,
291 const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
293 virtual ~ConCommand( void );
295 virtual bool IsCommand( void ) const;
297 virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
299 virtual bool CanAutoComplete( void );
301 // Invoke the function
302 virtual void Dispatch( const CCommand &command );
305 // NOTE: To maintain backward compat, we have to be very careful:
306 // All public virtual methods must appear in the same order always
307 // since engine code will be calling into this code, which *does not match*
308 // in the mod code; it's using slightly different, but compatible versions
309 // of this class. Also: Be very careful about adding new fields to this class.
310 // Those fields will not exist in the version of this class that is instanced
313 // Call this function when executing the command
316 FnCommandCallbackV1_t m_fnCommandCallbackV1;
317 FnCommandCallback_t m_fnCommandCallback;
318 ICommandCallback *m_pCommandCallback;
323 FnCommandCompletionCallback m_fnCompletionCallback;
324 ICommandCompletionCallback *m_pCommandCompletionCallback;
327 bool m_bHasCompletionCallback : 1;
328 bool m_bUsingNewCommandCallback : 1;
329 bool m_bUsingCommandCallbackInterface : 1;
331 inline FnCommandCallback_t GetCallback() const
333 return m_fnCommandCallback;
338 //-----------------------------------------------------------------------------
339 // Purpose: A console variable
340 //-----------------------------------------------------------------------------
341 class ConVar : public ConCommandBase, public IConVar
344 friend class ConVarRef;
345 friend class SplitScreenConVarRef;
348 typedef ConCommandBase BaseClass;
350 ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
352 ConVar( const char *pName, const char *pDefaultValue, int flags,
353 const char *pHelpString );
354 ConVar( const char *pName, const char *pDefaultValue, int flags,
355 const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
356 ConVar( const char *pName, const char *pDefaultValue, int flags,
357 const char *pHelpString, FnChangeCallback_t callback );
358 ConVar( const char *pName, const char *pDefaultValue, int flags,
359 const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
360 FnChangeCallback_t callback );
362 virtual ~ConVar( void );
364 virtual bool IsFlagSet( int flag ) const;
365 virtual const char* GetHelpText( void ) const;
366 virtual bool IsRegistered( void ) const;
367 virtual const char *GetName( void ) const;
368 // Return name of command (usually == GetName(), except in case of FCVAR_SS_ADDED vars
369 virtual const char *GetBaseName( void ) const;
370 virtual int GetSplitScreenPlayerSlot() const;
372 virtual void AddFlags( int flags );
373 virtual int GetFlags() const;
374 virtual bool IsCommand( void ) const;
376 // Install a change callback (there shouldn't already be one....)
377 void InstallChangeCallback( FnChangeCallback_t callback, bool bInvoke = true );
378 void RemoveChangeCallback( FnChangeCallback_t callbackToRemove );
380 int GetChangeCallbackCount() const { return m_pParent->m_fnChangeCallbacks.Count(); }
381 FnChangeCallback_t GetChangeCallback( int slot ) const { return m_pParent->m_fnChangeCallbacks[ slot ]; }
384 #if SOURCE_ENGINE == SE_CSGO
385 virtual float GetFloat( void ) const;
386 virtual int GetInt( void ) const;
388 FORCEINLINE_CVAR float GetFloat( void ) const;
389 FORCEINLINE_CVAR int GetInt( void ) const;
392 FORCEINLINE_CVAR Color GetColor( void ) const;
393 FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
394 FORCEINLINE_CVAR char const *GetString( void ) const;
396 // Compiler driven selection for template use
397 template <typename T> T Get( void ) const;
398 template <typename T> T Get( T * ) const;
400 // Any function that allocates/frees memory needs to be virtual or else you'll have crashes
401 // from alloc/free across dll/exe boundaries.
403 // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
404 virtual void SetValue( const char *value );
405 virtual void SetValue( float value );
406 virtual void SetValue( int value );
407 virtual void SetValue( Color value );
409 // Reset to default value
412 // True if it has a min/max setting
416 bool GetMin( float& minVal ) const;
417 bool GetMax( float& maxVal ) const;
419 float GetMinValue() const;
420 float GetMaxValue() const;
422 const char *GetDefault( void ) const;
435 FORCEINLINE_CVAR CVValue_t &GetRawValue()
439 FORCEINLINE_CVAR const CVValue_t &GetRawValue() const
445 bool InternalSetColorFromString( const char *value );
446 // Called by CCvar when the value of a var is changing.
447 virtual void InternalSetValue(const char *value);
448 // For CVARs marked FCVAR_NEVER_AS_STRING
449 virtual void InternalSetFloatValue( float fNewValue );
450 virtual void InternalSetIntValue( int nValue );
451 virtual void InternalSetColorValue( Color value );
453 virtual bool ClampValue( float& value );
454 virtual void ChangeStringValue( const char *tempVal, float flOldValue );
456 virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0,
457 const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
458 bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
460 // Used internally by OneTimeInit to initialize.
467 // This either points to "this" or it points to the original declaration of a ConVar.
468 // This allows ConVars to exist in separate modules, and they all use the first one to be declared.
469 // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
473 const char *m_pszDefaultValue;
483 // Call this function when ConVar changes
484 CUtlVector< FnChangeCallback_t > m_fnChangeCallbacks;
486 inline void SetMin(bool set, float min=0.0)
491 inline void SetMax(bool set, float max=0.0)
499 //-----------------------------------------------------------------------------
500 // Purpose: Return ConVar value as a float
502 //-----------------------------------------------------------------------------
503 FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
505 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
506 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
508 return m_pParent->m_Value.m_fValue;
511 //-----------------------------------------------------------------------------
512 // Purpose: Return ConVar value as an int
514 //-----------------------------------------------------------------------------
515 FORCEINLINE_CVAR int ConVar::GetInt( void ) const
517 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
518 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
520 return m_pParent->m_Value.m_nValue;
523 //-----------------------------------------------------------------------------
524 // Purpose: Return ConVar value as a color
526 //-----------------------------------------------------------------------------
527 FORCEINLINE_CVAR Color ConVar::GetColor( void ) const
529 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
530 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
532 unsigned char *pColorElement = ((unsigned char *)&m_pParent->m_Value.m_nValue);
533 return Color( pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3] );
537 //-----------------------------------------------------------------------------
539 template <> FORCEINLINE_CVAR float ConVar::Get<float>( void ) const { return GetFloat(); }
540 template <> FORCEINLINE_CVAR int ConVar::Get<int>( void ) const { return GetInt(); }
541 template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( void ) const { return GetBool(); }
542 template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( void ) const { return GetString(); }
543 template <> FORCEINLINE_CVAR float ConVar::Get<float>( float *p ) const { return ( *p = GetFloat() ); }
544 template <> FORCEINLINE_CVAR int ConVar::Get<int>( int *p ) const { return ( *p = GetInt() ); }
545 template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( bool *p ) const { return ( *p = GetBool() ); }
546 template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( char const **p ) const { return ( *p = GetString() ); }
548 //-----------------------------------------------------------------------------
549 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
550 // Output : const char *
551 //-----------------------------------------------------------------------------
552 FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
554 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
555 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
557 if ( m_nFlags & FCVAR_NEVER_AS_STRING )
558 return "FCVAR_NEVER_AS_STRING";
560 char const *str = m_pParent->m_Value.m_pszString;
561 return str ? str : "";
564 class CSplitScreenAddedConVar : public ConVar
566 typedef ConVar BaseClass;
568 CSplitScreenAddedConVar( int nSplitScreenSlot, const char *pName, const ConVar *pBaseVar ) :
572 pBaseVar->GetDefault(),
573 // Keep basevar flags, except remove _SS and add _SS_ADDED instead
574 ( pBaseVar->GetFlags() & ~FCVAR_SS ) | FCVAR_SS_ADDED,
575 pBaseVar->GetHelpText(),
577 pBaseVar->GetMinValue(),
579 pBaseVar->GetMaxValue()
581 m_pBaseVar( pBaseVar ),
582 m_nSplitScreenSlot( nSplitScreenSlot )
584 for ( int i = 0; i < pBaseVar->GetChangeCallbackCount(); ++i )
586 InstallChangeCallback( pBaseVar->GetChangeCallback( i ), false );
588 Assert( nSplitScreenSlot >= 1 );
589 Assert( nSplitScreenSlot < MAX_SPLITSCREEN_CLIENTS );
590 Assert( m_pBaseVar );
591 Assert( IsFlagSet( FCVAR_SS_ADDED ) );
592 Assert( !IsFlagSet( FCVAR_SS ) );
595 const ConVar *GetBaseVar() const;
596 virtual const char *GetBaseName() const;
597 void SetSplitScreenPlayerSlot( int nSlot );
598 virtual int GetSplitScreenPlayerSlot() const;
602 const ConVar *m_pBaseVar;
603 int m_nSplitScreenSlot;
606 FORCEINLINE_CVAR const ConVar *CSplitScreenAddedConVar::GetBaseVar() const
608 Assert( m_pBaseVar );
612 FORCEINLINE_CVAR const char *CSplitScreenAddedConVar::GetBaseName() const
614 Assert( m_pBaseVar );
615 return m_pBaseVar->GetName();
618 FORCEINLINE_CVAR void CSplitScreenAddedConVar::SetSplitScreenPlayerSlot( int nSlot )
620 m_nSplitScreenSlot = nSlot;
623 FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const
625 return m_nSplitScreenSlot;
628 //-----------------------------------------------------------------------------
629 // Used to read/write convars that already exist (replaces the FindVar method)
630 //-----------------------------------------------------------------------------
634 ConVarRef( const char *pName );
635 ConVarRef( const char *pName, bool bIgnoreMissing );
636 ConVarRef( IConVar *pConVar );
638 void Init( const char *pName, bool bIgnoreMissing );
639 bool IsValid() const;
640 bool IsFlagSet( int nFlags ) const;
641 IConVar *GetLinkedConVar();
644 float GetFloat( void ) const;
645 int GetInt( void ) const;
646 Color GetColor( void ) const;
647 bool GetBool() const { return !!GetInt(); }
648 const char *GetString( void ) const;
650 void SetValue( const char *pValue );
651 void SetValue( float flValue );
652 void SetValue( int nValue );
653 void SetValue( Color value );
654 void SetValue( bool bValue );
656 const char *GetName() const;
658 const char *GetDefault() const;
660 const char *GetBaseName() const;
662 int GetSplitScreenPlayerSlot() const;
665 // High-speed method to read convar data
667 ConVar *m_pConVarState;
671 //-----------------------------------------------------------------------------
672 // Did we find an existing convar of that name?
673 //-----------------------------------------------------------------------------
674 FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
676 return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
679 FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
684 FORCEINLINE_CVAR const char *ConVarRef::GetName() const
686 return m_pConVar->GetName();
689 FORCEINLINE_CVAR const char *ConVarRef::GetBaseName() const
691 return m_pConVar->GetBaseName();
694 FORCEINLINE_CVAR int ConVarRef::GetSplitScreenPlayerSlot() const
696 return m_pConVar->GetSplitScreenPlayerSlot();
699 //-----------------------------------------------------------------------------
700 // Purpose: Return ConVar value as a float
701 //-----------------------------------------------------------------------------
702 FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
704 return m_pConVarState->m_Value.m_fValue;
707 //-----------------------------------------------------------------------------
708 // Purpose: Return ConVar value as an int
709 //-----------------------------------------------------------------------------
710 FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
712 return m_pConVarState->m_Value.m_nValue;
715 //-----------------------------------------------------------------------------
716 // Purpose: Return ConVar value as a color
717 //-----------------------------------------------------------------------------
718 FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const
720 return m_pConVarState->GetColor();
723 //-----------------------------------------------------------------------------
724 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
725 //-----------------------------------------------------------------------------
726 FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
728 Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
729 return m_pConVarState->m_Value.m_pszString;
733 FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
735 m_pConVar->SetValue( pValue );
738 FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
740 m_pConVar->SetValue( flValue );
743 FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
745 m_pConVar->SetValue( nValue );
748 FORCEINLINE_CVAR void ConVarRef::SetValue( Color value )
750 m_pConVar->SetValue( value );
753 FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
755 m_pConVar->SetValue( bValue ? 1 : 0 );
758 FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
760 return m_pConVarState->m_pszDefaultValue;
763 //-----------------------------------------------------------------------------
764 // Helper for referencing splitscreen convars (i.e., "name" and "name2")
765 //-----------------------------------------------------------------------------
766 class SplitScreenConVarRef
769 SplitScreenConVarRef( const char *pName );
770 SplitScreenConVarRef( const char *pName, bool bIgnoreMissing );
771 SplitScreenConVarRef( IConVar *pConVar );
773 void Init( const char *pName, bool bIgnoreMissing );
774 bool IsValid() const;
775 bool IsFlagSet( int nFlags ) const;
778 float GetFloat( int nSlot ) const;
779 int GetInt( int nSlot ) const;
780 Color GetColor( int nSlot ) const;
781 bool GetBool( int nSlot ) const { return !!GetInt( nSlot ); }
782 const char *GetString( int nSlot ) const;
784 void SetValue( int nSlot, const char *pValue );
785 void SetValue( int nSlot, float flValue );
786 void SetValue( int nSlot, int nValue );
787 void SetValue( int nSlot, Color value );
788 void SetValue( int nSlot, bool bValue );
790 const char *GetName( int nSlot ) const;
792 const char *GetDefault() const;
794 const char *GetBaseName() const;
800 ConVar *m_pConVarState;
803 cv_t m_Info[ MAX_SPLITSCREEN_CLIENTS ];
806 //-----------------------------------------------------------------------------
807 // Did we find an existing convar of that name?
808 //-----------------------------------------------------------------------------
809 FORCEINLINE_CVAR bool SplitScreenConVarRef::IsFlagSet( int nFlags ) const
811 return ( m_Info[ 0 ].m_pConVar->IsFlagSet( nFlags ) != 0 );
814 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetName( int nSlot ) const
816 return m_Info[ nSlot ].m_pConVar->GetName();
819 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetBaseName() const
821 return m_Info[ 0 ].m_pConVar->GetBaseName();
824 //-----------------------------------------------------------------------------
825 // Purpose: Return ConVar value as a float
826 //-----------------------------------------------------------------------------
827 FORCEINLINE_CVAR float SplitScreenConVarRef::GetFloat( int nSlot ) const
829 return m_Info[ nSlot ].m_pConVarState->m_Value.m_fValue;
832 //-----------------------------------------------------------------------------
833 // Purpose: Return ConVar value as an int
834 //-----------------------------------------------------------------------------
835 FORCEINLINE_CVAR int SplitScreenConVarRef::GetInt( int nSlot ) const
837 return m_Info[ nSlot ].m_pConVarState->m_Value.m_nValue;
840 //-----------------------------------------------------------------------------
841 // Purpose: Return ConVar value as an int
842 //-----------------------------------------------------------------------------
843 FORCEINLINE_CVAR Color SplitScreenConVarRef::GetColor( int nSlot ) const
845 return m_Info[ nSlot ].m_pConVarState->GetColor();
848 //-----------------------------------------------------------------------------
849 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
850 //-----------------------------------------------------------------------------
851 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetString( int nSlot ) const
853 Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
854 return m_Info[ nSlot ].m_pConVarState->m_Value.m_pszString;
858 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, const char *pValue )
860 m_Info[ nSlot ].m_pConVar->SetValue( pValue );
863 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, float flValue )
865 m_Info[ nSlot ].m_pConVar->SetValue( flValue );
868 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, int nValue )
870 m_Info[ nSlot ].m_pConVar->SetValue( nValue );
873 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, Color value )
875 m_Info[ nSlot ].m_pConVar->SetValue( value );
878 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, bool bValue )
880 m_Info[ nSlot ].m_pConVar->SetValue( bValue ? 1 : 0 );
883 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetDefault() const
885 return m_Info[ 0 ].m_pConVarState->m_pszDefaultValue;
888 //-----------------------------------------------------------------------------
889 // Called by the framework to register ConCommands with the ICVar
890 //-----------------------------------------------------------------------------
891 void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
892 void ConVar_Unregister( );
895 //-----------------------------------------------------------------------------
897 //-----------------------------------------------------------------------------
898 void ConVar_PrintDescription( const ConCommandBase *pVar );
901 //-----------------------------------------------------------------------------
902 // Purpose: Utility class to quickly allow ConCommands to call member methods
903 //-----------------------------------------------------------------------------
905 #pragma warning (disable : 4355 )
909 class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
911 typedef ConCommand BaseClass;
912 typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
913 typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
916 CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
917 int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
918 BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
922 m_CompletionFunc = completionFunc;
925 ~CConCommandMemberAccessor()
930 void SetOwner( T* pOwner )
935 virtual void CommandCallback( const CCommand &command )
937 Assert( m_pOwner && m_Func );
938 (m_pOwner->*m_Func)( command );
941 virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
943 Assert( m_pOwner && m_CompletionFunc );
944 return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
949 FnMemberCommandCallback_t m_Func;
950 FnMemberCommandCompletionCallback_t m_CompletionFunc;
954 #pragma warning ( default : 4355 )
958 //-----------------------------------------------------------------------------
959 // Purpose: Utility macros to quicky generate a simple console command
960 //-----------------------------------------------------------------------------
961 #define CON_COMMAND( name, description ) \
962 static void name( const CCommand &args ); \
963 static ConCommand name##_command( #name, name, description ); \
964 static void name( const CCommand &args )
967 #define CON_COMMAND_SHARED( name, description ) \
968 static void name( const CCommand &args ); \
969 static ConCommand name##_command_client( #name "_client", name, description ); \
970 static void name( const CCommand &args )
972 #define CON_COMMAND_SHARED( name, description ) \
973 static void name( const CCommand &args ); \
974 static ConCommand name##_command( #name, name, description ); \
975 static void name( const CCommand &args )
979 #define CON_COMMAND_F( name, description, flags ) \
980 static void name( const CCommand &args ); \
981 static ConCommand name##_command( #name, name, description, flags ); \
982 static void name( const CCommand &args )
985 #define CON_COMMAND_F_SHARED( name, description, flags ) \
986 static void name( const CCommand &args ); \
987 static ConCommand name##_command_client( #name "_client", name, description, flags ); \
988 static void name( const CCommand &args )
990 #define CON_COMMAND_F_SHARED( name, description, flags ) \
991 static void name( const CCommand &args ); \
992 static ConCommand name##_command( #name, name, description, flags ); \
993 static void name( const CCommand &args )
997 #define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
998 static void name( const CCommand &args ); \
999 static ConCommand name##_command( #name, name, description, flags, completion ); \
1000 static void name( const CCommand &args )
1003 #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
1004 static void name( const CCommand &args ); \
1005 static ConCommand name##_command_client( #name "_client", name, description, flags, completion ); \
1006 static void name( const CCommand &args )
1008 #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
1009 static void name( const CCommand &args ); \
1010 static ConCommand name##_command( #name, name, description, flags, completion ); \
1011 static void name( const CCommand &args )
1015 #define CON_COMMAND_EXTERN( name, _funcname, description ) \
1016 void _funcname( const CCommand &args ); \
1017 static ConCommand name##_command( #name, _funcname, description ); \
1018 void _funcname( const CCommand &args )
1020 #define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
1021 void _funcname( const CCommand &args ); \
1022 static ConCommand name##_command( #name, _funcname, description, flags ); \
1023 void _funcname( const CCommand &args )
1025 #define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
1026 void _funcname( const CCommand &args ); \
1027 friend class CCommandMemberInitializer_##_funcname; \
1028 class CCommandMemberInitializer_##_funcname \
1031 CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
1033 m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
1036 CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
1039 CCommandMemberInitializer_##_funcname m_##_funcname##_register; \