Update CS:GO team score 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;
52 struct CCommandContext
54 CCommandContext( int index )
70 //-----------------------------------------------------------------------------
71 // Any executable that wants to use ConVars need to implement one of
72 // these to hook up access to console variables.
73 //-----------------------------------------------------------------------------
74 class IConCommandBaseAccessor
77 // Flags is a combination of FCVAR flags in cvar.h.
78 // hOut is filled in with a handle to the variable.
79 virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
83 //-----------------------------------------------------------------------------
84 // Helper method for console development
85 //-----------------------------------------------------------------------------
87 void ConVar_PublishToVXConsole();
91 //-----------------------------------------------------------------------------
92 // Called when a ConCommand needs to execute
93 //-----------------------------------------------------------------------------
94 typedef void ( *FnCommandCallbackV1_t )( void );
95 typedef void ( *FnCommandCallback_t )( const CCommandContext &context, const CCommand &command );
97 #define COMMAND_COMPLETION_MAXITEMS 64
98 #define COMMAND_COMPLETION_ITEM_LENGTH 64
100 //-----------------------------------------------------------------------------
101 // Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
102 //-----------------------------------------------------------------------------
103 typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
109 class ICommandCallback
112 virtual void CommandCallback( const CCommand &command ) = 0;
115 class ICommandCallback2
118 virtual void CommandCallback( const CCommandContext &context, const CCommand &command ) = 0;
121 class ICommandCompletionCallback
124 virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
127 //-----------------------------------------------------------------------------
128 // Purpose: The base console invoked command/cvar interface
129 //-----------------------------------------------------------------------------
134 friend class ConCommand;
135 friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
136 friend void ConVar_PublishToVXConsole();
138 // FIXME: Remove when ConVar changes are done
139 friend class CDefaultCvar;
142 ConCommandBase( void );
143 ConCommandBase( const char *pName, const char *pHelpString = 0,
146 virtual ~ConCommandBase( void );
148 virtual bool IsCommand( void ) const;
151 virtual bool IsFlagSet( int flag ) const;
153 virtual void AddFlags( int flags );
155 virtual void RemoveFlags( int flags );
157 virtual int GetFlags() const;
159 // Return name of cvar
160 virtual const char *GetName( void ) const;
162 // Return help text for cvar
163 virtual const char *GetHelpText( void ) const;
165 // Deal with next pointer
166 const ConCommandBase *GetNext( void ) const;
167 ConCommandBase *GetNext( void );
169 virtual bool IsRegistered( void ) const;
171 // Returns the DLL identifier
172 virtual CVarDLLIdentifier_t GetDLLIdentifier() const;
175 virtual void Create( const char *pName, const char *pHelpString = 0,
178 // Used internally by OneTimeInit to initialize/shutdown
182 // Internal copy routine ( uses new operator from correct module )
183 char *CopyString( const char *from );
186 // Next ConVar in chain
187 // Prior to register, it points to the next convar in the DLL.
188 // Once registered, though, m_pNext is reset to point to the next
189 // convar in the global list
190 ConCommandBase *m_pNext;
192 // Has the cvar been added to the global list?
196 const char *m_pszName;
197 const char *m_pszHelpString;
203 // ConVars add themselves to this list for the executable.
204 // Then ConVar_Register runs through all the console variables
205 // and registers them into a global list stored in vstdlib.dll
206 static ConCommandBase *s_pConCommandBases;
208 // ConVars in this executable use this 'global' to access values.
209 static IConCommandBaseAccessor *s_pAccessor;
211 inline void SetFlags(int flags)
218 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
225 CCommand( int nArgC, const char **ppArgV );
226 bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
230 const char **ArgV() const;
231 const char *ArgS() const; // All args that occur after the 0th arg, in string form
232 const char *GetCommandString() const; // The entire command in string form, including the 0th arg
233 const char *operator[]( int nIndex ) const; // Gets at arguments
234 const char *Arg( int nIndex ) const; // Gets at arguments
236 // Helper functions to parse arguments to commands.
237 const char* FindArg( const char *pName ) const;
238 int FindArgInt( const char *pName, int nDefaultVal ) const;
240 static int MaxCommandLength();
241 static characterset_t* DefaultBreakSet();
246 COMMAND_MAX_ARGC = 64,
247 COMMAND_MAX_LENGTH = 512,
252 char m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
253 char m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
254 const char* m_ppArgv[ COMMAND_MAX_ARGC ];
257 inline int CCommand::MaxCommandLength()
259 return COMMAND_MAX_LENGTH - 1;
262 inline int CCommand::ArgC() const
267 inline const char **CCommand::ArgV() const
269 return m_nArgc ? (const char**)m_ppArgv : NULL;
272 inline const char *CCommand::ArgS() const
274 return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
277 inline const char *CCommand::GetCommandString() const
279 return m_nArgc ? m_pArgSBuffer : "";
282 inline const char *CCommand::Arg( int nIndex ) const
284 // FIXME: Many command handlers appear to not be particularly careful
285 // about checking for valid argc range. For now, we're going to
286 // do the extra check and return an empty string if it's out of range
287 if ( nIndex < 0 || nIndex >= m_nArgc )
289 return m_ppArgv[nIndex];
292 inline const char *CCommand::operator[]( int nIndex ) const
294 return Arg( nIndex );
298 //-----------------------------------------------------------------------------
299 // Purpose: The console invoked command
300 //-----------------------------------------------------------------------------
301 class ConCommand : public ConCommandBase
306 typedef ConCommandBase BaseClass;
308 ConCommand( const char *pName, FnCommandCallbackV1_t callback,
309 const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
310 ConCommand( const char *pName, FnCommandCallback_t callback,
311 const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
312 ConCommand( const char *pName, ICommandCallback *pCallback,
313 const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
314 ConCommand( const char *pName, ICommandCallback2 *pCallback,
315 const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
317 virtual ~ConCommand( void );
319 virtual bool IsCommand( void ) const;
321 virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
323 virtual bool CanAutoComplete( void );
325 // Invoke the function
326 virtual void Dispatch( const CCommandContext &context, const CCommand &command );
329 // NOTE: To maintain backward compat, we have to be very careful:
330 // All public virtual methods must appear in the same order always
331 // since engine code will be calling into this code, which *does not match*
332 // in the mod code; it's using slightly different, but compatible versions
333 // of this class. Also: Be very careful about adding new fields to this class.
334 // Those fields will not exist in the version of this class that is instanced
337 // Call this function when executing the command
340 FnCommandCallbackV1_t m_fnCommandCallbackV1;
341 FnCommandCallback_t m_fnCommandCallback;
342 ICommandCallback *m_pCommandCallback;
343 ICommandCallback2 *m_pCommandCallback2;
348 FnCommandCompletionCallback m_fnCompletionCallback;
349 ICommandCompletionCallback *m_pCommandCompletionCallback;
352 bool m_bHasCompletionCallback : 1;
353 bool m_bUsingNewCommandCallback : 1;
354 bool m_bUsingCommandCallbackInterface : 1;
355 bool m_bUsingCommandCallbackInterface2 : 1;
357 inline FnCommandCallback_t GetCallback() const
359 return m_fnCommandCallback;
364 //-----------------------------------------------------------------------------
365 // Purpose: A console variable
366 //-----------------------------------------------------------------------------
367 class ConVar : public ConCommandBase, public IConVar
370 friend class ConVarRef;
371 friend class SplitScreenConVarRef;
374 typedef ConCommandBase BaseClass;
376 ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
378 ConVar( const char *pName, const char *pDefaultValue, int flags,
379 const char *pHelpString );
380 ConVar( const char *pName, const char *pDefaultValue, int flags,
381 const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
382 ConVar( const char *pName, const char *pDefaultValue, int flags,
383 const char *pHelpString, FnChangeCallback_t callback );
384 ConVar( const char *pName, const char *pDefaultValue, int flags,
385 const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
386 FnChangeCallback_t callback );
388 virtual ~ConVar( void );
390 virtual bool IsFlagSet( int flag ) const;
391 virtual const char* GetHelpText( void ) const;
392 virtual bool IsRegistered( void ) const;
393 virtual const char *GetName( void ) const;
394 // Return name of command (usually == GetName(), except in case of FCVAR_SS_ADDED vars
395 virtual const char *GetBaseName( void ) const;
396 virtual int GetSplitScreenPlayerSlot() const;
398 virtual void AddFlags( int flags );
399 virtual int GetFlags() const;
400 virtual bool IsCommand( void ) const;
402 // Install a change callback (there shouldn't already be one....)
403 void InstallChangeCallback( FnChangeCallback_t callback, bool bInvoke = true );
404 void RemoveChangeCallback( FnChangeCallback_t callbackToRemove );
406 int GetChangeCallbackCount() const { return m_pParent->m_fnChangeCallbacks.Count(); }
407 FnChangeCallback_t GetChangeCallback( int slot ) const { return m_pParent->m_fnChangeCallbacks[ slot ]; }
410 FORCEINLINE_CVAR float GetFloat( void ) const;
411 FORCEINLINE_CVAR int GetInt( void ) const;
412 FORCEINLINE_CVAR Color GetColor( void ) const;
413 FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
414 FORCEINLINE_CVAR char const *GetString( void ) const;
416 // Compiler driven selection for template use
417 template <typename T> T Get( void ) const;
418 template <typename T> T Get( T * ) const;
420 // Any function that allocates/frees memory needs to be virtual or else you'll have crashes
421 // from alloc/free across dll/exe boundaries.
423 // These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
424 virtual void SetValue( const char *value );
425 virtual void SetValue( float value );
426 virtual void SetValue( int value );
427 virtual void SetValue( Color value );
429 // Reset to default value
432 // True if it has a min/max setting
436 bool GetMin( float& minVal ) const;
437 bool GetMax( float& maxVal ) const;
439 float GetMinValue() const;
440 float GetMaxValue() const;
442 const char *GetDefault( void ) const;
455 FORCEINLINE_CVAR CVValue_t &GetRawValue()
459 FORCEINLINE_CVAR const CVValue_t &GetRawValue() const
465 bool InternalSetColorFromString( const char *value );
466 // Called by CCvar when the value of a var is changing.
467 virtual void InternalSetValue(const char *value);
468 // For CVARs marked FCVAR_NEVER_AS_STRING
469 virtual void InternalSetFloatValue( float fNewValue );
470 virtual void InternalSetIntValue( int nValue );
471 virtual void InternalSetColorValue( Color value );
473 virtual bool ClampValue( float& value );
474 virtual void ChangeStringValue( const char *tempVal, float flOldValue );
476 virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0,
477 const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
478 bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
480 // Used internally by OneTimeInit to initialize.
487 // This either points to "this" or it points to the original declaration of a ConVar.
488 // This allows ConVars to exist in separate modules, and they all use the first one to be declared.
489 // m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
493 const char *m_pszDefaultValue;
503 // Call this function when ConVar changes
504 CUtlVector< FnChangeCallback_t > m_fnChangeCallbacks;
506 inline void SetMin(bool set, float min=0.0)
511 inline void SetMax(bool set, float max=0.0)
519 //-----------------------------------------------------------------------------
520 // Purpose: Return ConVar value as a float
522 //-----------------------------------------------------------------------------
523 FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
525 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
526 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
528 return m_pParent->m_Value.m_fValue;
531 //-----------------------------------------------------------------------------
532 // Purpose: Return ConVar value as an int
534 //-----------------------------------------------------------------------------
535 FORCEINLINE_CVAR int ConVar::GetInt( void ) const
537 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
538 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
540 return m_pParent->m_Value.m_nValue;
543 //-----------------------------------------------------------------------------
544 // Purpose: Return ConVar value as a color
546 //-----------------------------------------------------------------------------
547 FORCEINLINE_CVAR Color ConVar::GetColor( void ) const
549 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
550 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
552 unsigned char *pColorElement = ((unsigned char *)&m_pParent->m_Value.m_nValue);
553 return Color( pColorElement[0], pColorElement[1], pColorElement[2], pColorElement[3] );
557 //-----------------------------------------------------------------------------
559 template <> FORCEINLINE_CVAR float ConVar::Get<float>( void ) const { return GetFloat(); }
560 template <> FORCEINLINE_CVAR int ConVar::Get<int>( void ) const { return GetInt(); }
561 template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( void ) const { return GetBool(); }
562 template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( void ) const { return GetString(); }
563 template <> FORCEINLINE_CVAR float ConVar::Get<float>( float *p ) const { return ( *p = GetFloat() ); }
564 template <> FORCEINLINE_CVAR int ConVar::Get<int>( int *p ) const { return ( *p = GetInt() ); }
565 template <> FORCEINLINE_CVAR bool ConVar::Get<bool>( bool *p ) const { return ( *p = GetBool() ); }
566 template <> FORCEINLINE_CVAR const char * ConVar::Get<const char *>( char const **p ) const { return ( *p = GetString() ); }
568 //-----------------------------------------------------------------------------
569 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
570 // Output : const char *
571 //-----------------------------------------------------------------------------
572 FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
574 #ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
575 Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
577 if ( m_nFlags & FCVAR_NEVER_AS_STRING )
578 return "FCVAR_NEVER_AS_STRING";
580 char const *str = m_pParent->m_Value.m_pszString;
581 return str ? str : "";
584 class CSplitScreenAddedConVar : public ConVar
586 typedef ConVar BaseClass;
588 CSplitScreenAddedConVar( int nSplitScreenSlot, const char *pName, const ConVar *pBaseVar ) :
592 pBaseVar->GetDefault(),
593 // Keep basevar flags, except remove _SS and add _SS_ADDED instead
594 ( pBaseVar->GetFlags() & ~FCVAR_SS ) | FCVAR_SS_ADDED,
595 pBaseVar->GetHelpText(),
597 pBaseVar->GetMinValue(),
599 pBaseVar->GetMaxValue()
601 m_pBaseVar( pBaseVar ),
602 m_nSplitScreenSlot( nSplitScreenSlot )
604 for ( int i = 0; i < pBaseVar->GetChangeCallbackCount(); ++i )
606 InstallChangeCallback( pBaseVar->GetChangeCallback( i ), false );
608 Assert( nSplitScreenSlot >= 1 );
609 Assert( nSplitScreenSlot < MAX_SPLITSCREEN_CLIENTS );
610 Assert( m_pBaseVar );
611 Assert( IsFlagSet( FCVAR_SS_ADDED ) );
612 Assert( !IsFlagSet( FCVAR_SS ) );
615 const ConVar *GetBaseVar() const;
616 virtual const char *GetBaseName() const;
617 void SetSplitScreenPlayerSlot( int nSlot );
618 virtual int GetSplitScreenPlayerSlot() const;
622 const ConVar *m_pBaseVar;
623 int m_nSplitScreenSlot;
626 FORCEINLINE_CVAR const ConVar *CSplitScreenAddedConVar::GetBaseVar() const
628 Assert( m_pBaseVar );
632 FORCEINLINE_CVAR const char *CSplitScreenAddedConVar::GetBaseName() const
634 Assert( m_pBaseVar );
635 return m_pBaseVar->GetName();
638 FORCEINLINE_CVAR void CSplitScreenAddedConVar::SetSplitScreenPlayerSlot( int nSlot )
640 m_nSplitScreenSlot = nSlot;
643 FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const
645 return m_nSplitScreenSlot;
648 //-----------------------------------------------------------------------------
649 // Used to read/write convars that already exist (replaces the FindVar method)
650 //-----------------------------------------------------------------------------
654 ConVarRef( const char *pName );
655 ConVarRef( const char *pName, bool bIgnoreMissing );
656 ConVarRef( IConVar *pConVar );
658 void Init( const char *pName, bool bIgnoreMissing );
659 bool IsValid() const;
660 bool IsFlagSet( int nFlags ) const;
661 IConVar *GetLinkedConVar();
664 float GetFloat( void ) const;
665 int GetInt( void ) const;
666 Color GetColor( void ) const;
667 bool GetBool() const { return !!GetInt(); }
668 const char *GetString( void ) const;
670 void SetValue( const char *pValue );
671 void SetValue( float flValue );
672 void SetValue( int nValue );
673 void SetValue( Color value );
674 void SetValue( bool bValue );
676 const char *GetName() const;
678 const char *GetDefault() const;
680 const char *GetBaseName() const;
682 int GetSplitScreenPlayerSlot() const;
685 // High-speed method to read convar data
687 ConVar *m_pConVarState;
691 //-----------------------------------------------------------------------------
692 // Did we find an existing convar of that name?
693 //-----------------------------------------------------------------------------
694 FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
696 return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
699 FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
704 FORCEINLINE_CVAR const char *ConVarRef::GetName() const
706 return m_pConVar->GetName();
709 FORCEINLINE_CVAR const char *ConVarRef::GetBaseName() const
711 return m_pConVar->GetBaseName();
714 FORCEINLINE_CVAR int ConVarRef::GetSplitScreenPlayerSlot() const
716 return m_pConVar->GetSplitScreenPlayerSlot();
719 //-----------------------------------------------------------------------------
720 // Purpose: Return ConVar value as a float
721 //-----------------------------------------------------------------------------
722 FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
724 return m_pConVarState->m_Value.m_fValue;
727 //-----------------------------------------------------------------------------
728 // Purpose: Return ConVar value as an int
729 //-----------------------------------------------------------------------------
730 FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
732 return m_pConVarState->m_Value.m_nValue;
735 //-----------------------------------------------------------------------------
736 // Purpose: Return ConVar value as a color
737 //-----------------------------------------------------------------------------
738 FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const
740 return m_pConVarState->GetColor();
743 //-----------------------------------------------------------------------------
744 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
745 //-----------------------------------------------------------------------------
746 FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
748 Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
749 return m_pConVarState->m_Value.m_pszString;
753 FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
755 m_pConVar->SetValue( pValue );
758 FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
760 m_pConVar->SetValue( flValue );
763 FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
765 m_pConVar->SetValue( nValue );
768 FORCEINLINE_CVAR void ConVarRef::SetValue( Color value )
770 m_pConVar->SetValue( value );
773 FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
775 m_pConVar->SetValue( bValue ? 1 : 0 );
778 FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
780 return m_pConVarState->m_pszDefaultValue;
783 //-----------------------------------------------------------------------------
784 // Helper for referencing splitscreen convars (i.e., "name" and "name2")
785 //-----------------------------------------------------------------------------
786 class SplitScreenConVarRef
789 SplitScreenConVarRef( const char *pName );
790 SplitScreenConVarRef( const char *pName, bool bIgnoreMissing );
791 SplitScreenConVarRef( IConVar *pConVar );
793 void Init( const char *pName, bool bIgnoreMissing );
794 bool IsValid() const;
795 bool IsFlagSet( int nFlags ) const;
798 float GetFloat( int nSlot ) const;
799 int GetInt( int nSlot ) const;
800 Color GetColor( int nSlot ) const;
801 bool GetBool( int nSlot ) const { return !!GetInt( nSlot ); }
802 const char *GetString( int nSlot ) const;
804 void SetValue( int nSlot, const char *pValue );
805 void SetValue( int nSlot, float flValue );
806 void SetValue( int nSlot, int nValue );
807 void SetValue( int nSlot, Color value );
808 void SetValue( int nSlot, bool bValue );
810 const char *GetName( int nSlot ) const;
812 const char *GetDefault() const;
814 const char *GetBaseName() const;
820 ConVar *m_pConVarState;
823 cv_t m_Info[ MAX_SPLITSCREEN_CLIENTS ];
826 //-----------------------------------------------------------------------------
827 // Did we find an existing convar of that name?
828 //-----------------------------------------------------------------------------
829 FORCEINLINE_CVAR bool SplitScreenConVarRef::IsFlagSet( int nFlags ) const
831 return ( m_Info[ 0 ].m_pConVar->IsFlagSet( nFlags ) != 0 );
834 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetName( int nSlot ) const
836 return m_Info[ nSlot ].m_pConVar->GetName();
839 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetBaseName() const
841 return m_Info[ 0 ].m_pConVar->GetBaseName();
844 //-----------------------------------------------------------------------------
845 // Purpose: Return ConVar value as a float
846 //-----------------------------------------------------------------------------
847 FORCEINLINE_CVAR float SplitScreenConVarRef::GetFloat( int nSlot ) const
849 return m_Info[ nSlot ].m_pConVarState->m_Value.m_fValue;
852 //-----------------------------------------------------------------------------
853 // Purpose: Return ConVar value as an int
854 //-----------------------------------------------------------------------------
855 FORCEINLINE_CVAR int SplitScreenConVarRef::GetInt( int nSlot ) const
857 return m_Info[ nSlot ].m_pConVarState->m_Value.m_nValue;
860 //-----------------------------------------------------------------------------
861 // Purpose: Return ConVar value as an int
862 //-----------------------------------------------------------------------------
863 FORCEINLINE_CVAR Color SplitScreenConVarRef::GetColor( int nSlot ) const
865 return m_Info[ nSlot ].m_pConVarState->GetColor();
868 //-----------------------------------------------------------------------------
869 // Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
870 //-----------------------------------------------------------------------------
871 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetString( int nSlot ) const
873 Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
874 return m_Info[ nSlot ].m_pConVarState->m_Value.m_pszString;
878 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, const char *pValue )
880 m_Info[ nSlot ].m_pConVar->SetValue( pValue );
883 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, float flValue )
885 m_Info[ nSlot ].m_pConVar->SetValue( flValue );
888 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, int nValue )
890 m_Info[ nSlot ].m_pConVar->SetValue( nValue );
893 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, Color value )
895 m_Info[ nSlot ].m_pConVar->SetValue( value );
898 FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, bool bValue )
900 m_Info[ nSlot ].m_pConVar->SetValue( bValue ? 1 : 0 );
903 FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetDefault() const
905 return m_Info[ 0 ].m_pConVarState->m_pszDefaultValue;
908 //-----------------------------------------------------------------------------
909 // Called by the framework to register ConCommands with the ICVar
910 //-----------------------------------------------------------------------------
911 void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
912 void ConVar_Unregister( );
915 //-----------------------------------------------------------------------------
917 //-----------------------------------------------------------------------------
918 void ConVar_PrintDescription( const ConCommandBase *pVar );
921 //-----------------------------------------------------------------------------
922 // Purpose: Utility class to quickly allow ConCommands to call member methods
923 //-----------------------------------------------------------------------------
925 #pragma warning (disable : 4355 )
929 class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
931 typedef ConCommand BaseClass;
932 typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
933 typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
936 CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
937 int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
938 BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
942 m_CompletionFunc = completionFunc;
945 ~CConCommandMemberAccessor()
950 void SetOwner( T* pOwner )
955 virtual void CommandCallback( const CCommand &command )
957 Assert( m_pOwner && m_Func );
958 (m_pOwner->*m_Func)( command );
961 virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
963 Assert( m_pOwner && m_CompletionFunc );
964 return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
969 FnMemberCommandCallback_t m_Func;
970 FnMemberCommandCompletionCallback_t m_CompletionFunc;
974 #pragma warning ( default : 4355 )
977 //-----------------------------------------------------------------------------
978 // Purpose: Utility macros to quicky generate a simple console command
979 //-----------------------------------------------------------------------------
980 #define CON_COMMAND( name, description ) \
981 static void name( const CCommandContext &context, const CCommand &args ); \
982 static ConCommand name##_command( #name, name, description ); \
983 static void name( const CCommandContext &context, const CCommand &args )
986 #define CON_COMMAND_SHARED( name, description ) \
987 static void name( const CCommandContext &context, const CCommand &args ); \
988 static ConCommand name##_command_client( #name "_client", name, description ); \
989 static void name( const CCommandContext &context, const CCommand &args )
991 #define CON_COMMAND_SHARED( name, description ) \
992 static void name( const CCommandContext &context, const CCommand &args ); \
993 static ConCommand name##_command( #name, name, description ); \
994 static void name( const CCommandContext &context, const CCommand &args )
998 #define CON_COMMAND_F( name, description, flags ) \
999 static void name( const CCommandContext &context, const CCommand &args ); \
1000 static ConCommand name##_command( #name, name, description, flags ); \
1001 static void name( const CCommandContext &context, const CCommand &args )
1004 #define CON_COMMAND_F_SHARED( name, description, flags ) \
1005 static void name( const CCommandContext &context, const CCommand &args ); \
1006 static ConCommand name##_command_client( #name "_client", name, description, flags ); \
1007 static void name( const CCommandContext &context, const CCommand &args )
1009 #define CON_COMMAND_F_SHARED( name, description, flags ) \
1010 static void name( const CCommandContext &context, const CCommand &args ); \
1011 static ConCommand name##_command( #name, name, description, flags ); \
1012 static void name( const CCommandContext &context, const CCommand &args )
1016 #define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
1017 static void name( const CCommandContext &context, const CCommand &args ); \
1018 static ConCommand name##_command( #name, name, description, flags, completion ); \
1019 static void name( const CCommandContext &context, const CCommand &args )
1022 #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
1023 static void name( const CCommandContext &context, const CCommand &args ); \
1024 static ConCommand name##_command_client( #name "_client", name, description, flags, completion ); \
1025 static void name( const CCommandContext &context, const CCommand &args )
1027 #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
1028 static void name( const CCommandContext &context, const CCommand &args ); \
1029 static ConCommand name##_command( #name, name, description, flags, completion ); \
1030 static void name( const CCommandContext &context, const CCommand &args )
1034 #define CON_COMMAND_EXTERN( name, _funcname, description ) \
1035 void _funcname( const CCommandContext &context, const CCommand &args ); \
1036 static ConCommand name##_command( #name, _funcname, description ); \
1037 void _funcname( const CCommandContext &context, const CCommand &args )
1039 #define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
1040 void _funcname( const CCommandContext &context, const CCommand &args ); \
1041 static ConCommand name##_command( #name, _funcname, description, flags ); \
1042 void _funcname( const CCommandContext &context, const CCommand &args )
1044 #define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
1045 void _funcname( const CCommandContext &context, const CCommand &args ); \
1046 friend class CCommandMemberInitializer_##_funcname; \
1047 class CCommandMemberInitializer_##_funcname \
1050 CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
1052 m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
1055 CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
1058 CCommandMemberInitializer_##_funcname m_##_funcname##_register; \