Added new TF2 weapon defines (r=me).
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 FORCEINLINE_CVAR float GetFloat( void ) const;
385 FORCEINLINE_CVAR int GetInt( void ) const;
386 FORCEINLINE_CVAR Color GetColor( void ) const;
387 FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
388 FORCEINLINE_CVAR char const *GetString( void ) const;
390 // Compiler driven selection for template use
391 template <typename T> T Get( void ) const;
392 template <typename T> T Get( T * ) const;
394 // Any function that allocates/frees memory needs to be virtual or else you'll have crashes
395 // from alloc/free across dll/exe boundaries.
397 // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
398 virtual void SetValue( const char *value );
399 virtual void SetValue( float value );
400 virtual void SetValue( int value );
401 virtual void SetValue( Color value );
403 // Reset to default value
406 // True if it has a min/max setting
410 bool GetMin( float& minVal ) const;
411 bool GetMax( float& maxVal ) const;
413 float GetMinValue() const;
414 float GetMaxValue() const;
416 const char *GetDefault( void ) const;
429 FORCEINLINE_CVAR CVValue_t &GetRawValue()
433 FORCEINLINE_CVAR const CVValue_t &GetRawValue() const
439 bool InternalSetColorFromString( const char *value );
440 // Called by CCvar when the value of a var is changing.
441 virtual void InternalSetValue(const char *value);
442 // For CVARs marked FCVAR_NEVER_AS_STRING
443 virtual void InternalSetFloatValue( float fNewValue );
444 virtual void InternalSetIntValue( int nValue );
445 virtual void InternalSetColorValue( Color value );
447 virtual bool ClampValue( float& value );
448 virtual void ChangeStringValue( const char *tempVal, float flOldValue );
450 virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0,
451 const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
452 bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
454 // Used internally by OneTimeInit to initialize.
461 // This either points to "this" or it points to the original declaration of a ConVar.
462 // This allows ConVars to exist in separate modules, and they all use the first one to be declared.
463 // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
467 const char *m_pszDefaultValue;
477 // Call this function when ConVar changes
478 CUtlVector< FnChangeCallback_t > m_fnChangeCallbacks;
480 inline void SetMin(bool set, float min=0.0)
485 inline void SetMax(bool set, float max=0.0)
493 //-----------------------------------------------------------------------------
494 // Purpose: Return ConVar value as a float
496 //-----------------------------------------------------------------------------
497 FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
499 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
500 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
502 return m_pParent->m_Value.m_fValue;
505 //-----------------------------------------------------------------------------
506 // Purpose: Return ConVar value as an int
508 //-----------------------------------------------------------------------------
509 FORCEINLINE_CVAR int ConVar::GetInt( void ) const
511 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
512 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
514 return m_pParent->m_Value.m_nValue;
517 //-----------------------------------------------------------------------------
518 // Purpose: Return ConVar value as a color
520 //-----------------------------------------------------------------------------
521 FORCEINLINE_CVAR Color ConVar::GetColor( void ) const
523 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
524 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
526 unsigned char *pColorElement = ((unsigned char *)&m_pParent->m_Value.m_nValue);
527 return Color( pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3] );
531 //-----------------------------------------------------------------------------
533 template <> FORCEINLINE_CVAR float ConVar::Get<float>( void ) const { return GetFloat(); }
534 template <> FORCEINLINE_CVAR int ConVar::Get<int>( void ) const { return GetInt(); }
535 template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( void ) const { return GetBool(); }
536 template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( void ) const { return GetString(); }
537 template <> FORCEINLINE_CVAR float ConVar::Get<float>( float *p ) const { return ( *p = GetFloat() ); }
538 template <> FORCEINLINE_CVAR int ConVar::Get<int>( int *p ) const { return ( *p = GetInt() ); }
539 template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( bool *p ) const { return ( *p = GetBool() ); }
540 template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( char const **p ) const { return ( *p = GetString() ); }
542 //-----------------------------------------------------------------------------
543 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
544 // Output : const char *
545 //-----------------------------------------------------------------------------
546 FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
548 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
549 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
551 if ( m_nFlags & FCVAR_NEVER_AS_STRING )
552 return "FCVAR_NEVER_AS_STRING";
554 char const *str = m_pParent->m_Value.m_pszString;
555 return str ? str : "";
558 class CSplitScreenAddedConVar : public ConVar
560 typedef ConVar BaseClass;
562 CSplitScreenAddedConVar( int nSplitScreenSlot, const char *pName, const ConVar *pBaseVar ) :
566 pBaseVar->GetDefault(),
567 // Keep basevar flags, except remove _SS and add _SS_ADDED instead
568 ( pBaseVar->GetFlags() & ~FCVAR_SS ) | FCVAR_SS_ADDED,
569 pBaseVar->GetHelpText(),
571 pBaseVar->GetMinValue(),
573 pBaseVar->GetMaxValue()
575 m_pBaseVar( pBaseVar ),
576 m_nSplitScreenSlot( nSplitScreenSlot )
578 for ( int i = 0; i < pBaseVar->GetChangeCallbackCount(); ++i )
580 InstallChangeCallback( pBaseVar->GetChangeCallback( i ), false );
582 Assert( nSplitScreenSlot >= 1 );
583 Assert( nSplitScreenSlot < MAX_SPLITSCREEN_CLIENTS );
584 Assert( m_pBaseVar );
585 Assert( IsFlagSet( FCVAR_SS_ADDED ) );
586 Assert( !IsFlagSet( FCVAR_SS ) );
589 const ConVar *GetBaseVar() const;
590 virtual const char *GetBaseName() const;
591 void SetSplitScreenPlayerSlot( int nSlot );
592 virtual int GetSplitScreenPlayerSlot() const;
596 const ConVar *m_pBaseVar;
597 int m_nSplitScreenSlot;
600 FORCEINLINE_CVAR const ConVar *CSplitScreenAddedConVar::GetBaseVar() const
602 Assert( m_pBaseVar );
606 FORCEINLINE_CVAR const char *CSplitScreenAddedConVar::GetBaseName() const
608 Assert( m_pBaseVar );
609 return m_pBaseVar->GetName();
612 FORCEINLINE_CVAR void CSplitScreenAddedConVar::SetSplitScreenPlayerSlot( int nSlot )
614 m_nSplitScreenSlot = nSlot;
617 FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const
619 return m_nSplitScreenSlot;
622 //-----------------------------------------------------------------------------
623 // Used to read/write convars that already exist (replaces the FindVar method)
624 //-----------------------------------------------------------------------------
628 ConVarRef( const char *pName );
629 ConVarRef( const char *pName, bool bIgnoreMissing );
630 ConVarRef( IConVar *pConVar );
632 void Init( const char *pName, bool bIgnoreMissing );
633 bool IsValid() const;
634 bool IsFlagSet( int nFlags ) const;
635 IConVar *GetLinkedConVar();
638 float GetFloat( void ) const;
639 int GetInt( void ) const;
640 Color GetColor( void ) const;
641 bool GetBool() const { return !!GetInt(); }
642 const char *GetString( void ) const;
644 void SetValue( const char *pValue );
645 void SetValue( float flValue );
646 void SetValue( int nValue );
647 void SetValue( Color value );
648 void SetValue( bool bValue );
650 const char *GetName() const;
652 const char *GetDefault() const;
654 const char *GetBaseName() const;
656 int GetSplitScreenPlayerSlot() const;
659 // High-speed method to read convar data
661 ConVar *m_pConVarState;
665 //-----------------------------------------------------------------------------
666 // Did we find an existing convar of that name?
667 //-----------------------------------------------------------------------------
668 FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
670 return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
673 FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
678 FORCEINLINE_CVAR const char *ConVarRef::GetName() const
680 return m_pConVar->GetName();
683 FORCEINLINE_CVAR const char *ConVarRef::GetBaseName() const
685 return m_pConVar->GetBaseName();
688 FORCEINLINE_CVAR int ConVarRef::GetSplitScreenPlayerSlot() const
690 return m_pConVar->GetSplitScreenPlayerSlot();
693 //-----------------------------------------------------------------------------
694 // Purpose: Return ConVar value as a float
695 //-----------------------------------------------------------------------------
696 FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
698 return m_pConVarState->m_Value.m_fValue;
701 //-----------------------------------------------------------------------------
702 // Purpose: Return ConVar value as an int
703 //-----------------------------------------------------------------------------
704 FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
706 return m_pConVarState->m_Value.m_nValue;
709 //-----------------------------------------------------------------------------
710 // Purpose: Return ConVar value as a color
711 //-----------------------------------------------------------------------------
712 FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const
714 return m_pConVarState->GetColor();
717 //-----------------------------------------------------------------------------
718 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
719 //-----------------------------------------------------------------------------
720 FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
722 Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
723 return m_pConVarState->m_Value.m_pszString;
727 FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
729 m_pConVar->SetValue( pValue );
732 FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
734 m_pConVar->SetValue( flValue );
737 FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
739 m_pConVar->SetValue( nValue );
742 FORCEINLINE_CVAR void ConVarRef::SetValue( Color value )
744 m_pConVar->SetValue( value );
747 FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
749 m_pConVar->SetValue( bValue ? 1 : 0 );
752 FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
754 return m_pConVarState->m_pszDefaultValue;
757 //-----------------------------------------------------------------------------
758 // Helper for referencing splitscreen convars (i.e., "name" and "name2")
759 //-----------------------------------------------------------------------------
760 class SplitScreenConVarRef
763 SplitScreenConVarRef( const char *pName );
764 SplitScreenConVarRef( const char *pName, bool bIgnoreMissing );
765 SplitScreenConVarRef( IConVar *pConVar );
767 void Init( const char *pName, bool bIgnoreMissing );
768 bool IsValid() const;
769 bool IsFlagSet( int nFlags ) const;
772 float GetFloat( int nSlot ) const;
773 int GetInt( int nSlot ) const;
774 Color GetColor( int nSlot ) const;
775 bool GetBool( int nSlot ) const { return !!GetInt( nSlot ); }
776 const char *GetString( int nSlot ) const;
778 void SetValue( int nSlot, const char *pValue );
779 void SetValue( int nSlot, float flValue );
780 void SetValue( int nSlot, int nValue );
781 void SetValue( int nSlot, Color value );
782 void SetValue( int nSlot, bool bValue );
784 const char *GetName( int nSlot ) const;
786 const char *GetDefault() const;
788 const char *GetBaseName() const;
794 ConVar *m_pConVarState;
797 cv_t m_Info[ MAX_SPLITSCREEN_CLIENTS ];
800 //-----------------------------------------------------------------------------
801 // Did we find an existing convar of that name?
802 //-----------------------------------------------------------------------------
803 FORCEINLINE_CVAR bool SplitScreenConVarRef::IsFlagSet( int nFlags ) const
805 return ( m_Info[ 0 ].m_pConVar->IsFlagSet( nFlags ) != 0 );
808 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetName( int nSlot ) const
810 return m_Info[ nSlot ].m_pConVar->GetName();
813 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetBaseName() const
815 return m_Info[ 0 ].m_pConVar->GetBaseName();
818 //-----------------------------------------------------------------------------
819 // Purpose: Return ConVar value as a float
820 //-----------------------------------------------------------------------------
821 FORCEINLINE_CVAR float SplitScreenConVarRef::GetFloat( int nSlot ) const
823 return m_Info[ nSlot ].m_pConVarState->m_Value.m_fValue;
826 //-----------------------------------------------------------------------------
827 // Purpose: Return ConVar value as an int
828 //-----------------------------------------------------------------------------
829 FORCEINLINE_CVAR int SplitScreenConVarRef::GetInt( int nSlot ) const
831 return m_Info[ nSlot ].m_pConVarState->m_Value.m_nValue;
834 //-----------------------------------------------------------------------------
835 // Purpose: Return ConVar value as an int
836 //-----------------------------------------------------------------------------
837 FORCEINLINE_CVAR Color SplitScreenConVarRef::GetColor( int nSlot ) const
839 return m_Info[ nSlot ].m_pConVarState->GetColor();
842 //-----------------------------------------------------------------------------
843 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
844 //-----------------------------------------------------------------------------
845 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetString( int nSlot ) const
847 Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
848 return m_Info[ nSlot ].m_pConVarState->m_Value.m_pszString;
852 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, const char *pValue )
854 m_Info[ nSlot ].m_pConVar->SetValue( pValue );
857 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, float flValue )
859 m_Info[ nSlot ].m_pConVar->SetValue( flValue );
862 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, int nValue )
864 m_Info[ nSlot ].m_pConVar->SetValue( nValue );
867 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, Color value )
869 m_Info[ nSlot ].m_pConVar->SetValue( value );
872 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, bool bValue )
874 m_Info[ nSlot ].m_pConVar->SetValue( bValue ? 1 : 0 );
877 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetDefault() const
879 return m_Info[ 0 ].m_pConVarState->m_pszDefaultValue;
882 //-----------------------------------------------------------------------------
883 // Called by the framework to register ConCommands with the ICVar
884 //-----------------------------------------------------------------------------
885 void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
886 void ConVar_Unregister( );
889 //-----------------------------------------------------------------------------
891 //-----------------------------------------------------------------------------
892 void ConVar_PrintDescription( const ConCommandBase *pVar );
895 //-----------------------------------------------------------------------------
896 // Purpose: Utility class to quickly allow ConCommands to call member methods
897 //-----------------------------------------------------------------------------
898 #pragma warning (disable : 4355 )
901 class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
903 typedef ConCommand BaseClass;
904 typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
905 typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
908 CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
909 int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
910 BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
914 m_CompletionFunc = completionFunc;
917 ~CConCommandMemberAccessor()
922 void SetOwner( T* pOwner )
927 virtual void CommandCallback( const CCommand &command )
929 Assert( m_pOwner && m_Func );
930 (m_pOwner->*m_Func)( command );
933 virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
935 Assert( m_pOwner && m_CompletionFunc );
936 return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
941 FnMemberCommandCallback_t m_Func;
942 FnMemberCommandCompletionCallback_t m_CompletionFunc;
945 #pragma warning ( default : 4355 )
948 //-----------------------------------------------------------------------------
949 // Purpose: Utility macros to quicky generate a simple console command
950 //-----------------------------------------------------------------------------
951 #define CON_COMMAND( name, description ) \
952 static void name( const CCommand &args ); \
953 static ConCommand name##_command( #name, name, description ); \
954 static void name( const CCommand &args )
957 #define CON_COMMAND_SHARED( name, description ) \
958 static void name( const CCommand &args ); \
959 static ConCommand name##_command_client( #name "_client", name, description ); \
960 static void name( const CCommand &args )
962 #define CON_COMMAND_SHARED( name, description ) \
963 static void name( const CCommand &args ); \
964 static ConCommand name##_command( #name, name, description ); \
965 static void name( const CCommand &args )
969 #define CON_COMMAND_F( name, description, flags ) \
970 static void name( const CCommand &args ); \
971 static ConCommand name##_command( #name, name, description, flags ); \
972 static void name( const CCommand &args )
975 #define CON_COMMAND_F_SHARED( name, description, flags ) \
976 static void name( const CCommand &args ); \
977 static ConCommand name##_command_client( #name "_client", name, description, flags ); \
978 static void name( const CCommand &args )
980 #define CON_COMMAND_F_SHARED( name, description, flags ) \
981 static void name( const CCommand &args ); \
982 static ConCommand name##_command( #name, name, description, flags ); \
983 static void name( const CCommand &args )
987 #define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
988 static void name( const CCommand &args ); \
989 static ConCommand name##_command( #name, name, description, flags, completion ); \
990 static void name( const CCommand &args )
993 #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
994 static void name( const CCommand &args ); \
995 static ConCommand name##_command_client( #name "_client", name, description, flags, completion ); \
996 static void name( const CCommand &args )
998 #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
999 static void name( const CCommand &args ); \
1000 static ConCommand name##_command( #name, name, description, flags, completion ); \
1001 static void name( const CCommand &args )
1005 #define CON_COMMAND_EXTERN( name, _funcname, description ) \
1006 void _funcname( const CCommand &args ); \
1007 static ConCommand name##_command( #name, _funcname, description ); \
1008 void _funcname( const CCommand &args )
1010 #define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
1011 void _funcname( const CCommand &args ); \
1012 static ConCommand name##_command( #name, _funcname, description, flags ); \
1013 void _funcname( const CCommand &args )
1015 #define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
1016 void _funcname( const CCommand &args ); \
1017 friend class CCommandMemberInitializer_##_funcname; \
1018 class CCommandMemberInitializer_##_funcname \
1021 CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
1023 m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
1026 CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
1029 CCommandMemberInitializer_##_funcname m_##_funcname##_register; \