( char const **p ) const { return ( *p = GetString() ); }
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
+// Output : const char *
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
+{
+#ifdef CONVAR_TEST_MATERIAL_THREAD_CONVARS
+ Assert( ThreadInMainThread() || IsFlagSet( FCVAR_MATERIAL_THREAD_MASK | FCVAR_ACCESSIBLE_FROM_THREADS ) );
+#endif
+ if ( m_nFlags & FCVAR_NEVER_AS_STRING )
+ return "FCVAR_NEVER_AS_STRING";
+
+ char const *str = m_pParent->m_Value.m_pszString;
+ return str ? str : "";
+}
+
+class CSplitScreenAddedConVar : public ConVar
+{
+ typedef ConVar BaseClass;
+public:
+ CSplitScreenAddedConVar( int nSplitScreenSlot, const char *pName, const ConVar *pBaseVar ) :
+ BaseClass
+ (
+ pName,
+ pBaseVar->GetDefault(),
+ // Keep basevar flags, except remove _SS and add _SS_ADDED instead
+ ( pBaseVar->GetFlags() & ~FCVAR_SS ) | FCVAR_SS_ADDED,
+ pBaseVar->GetHelpText(),
+ pBaseVar->HasMin(),
+ pBaseVar->GetMinValue(),
+ pBaseVar->HasMax(),
+ pBaseVar->GetMaxValue()
+ ),
+ m_pBaseVar( pBaseVar ),
+ m_nSplitScreenSlot( nSplitScreenSlot )
+ {
+ for ( int i = 0; i < pBaseVar->GetChangeCallbackCount(); ++i )
+ {
+ InstallChangeCallback( pBaseVar->GetChangeCallback( i ), false );
+ }
+ Assert( nSplitScreenSlot >= 1 );
+ Assert( nSplitScreenSlot < MAX_SPLITSCREEN_CLIENTS );
+ Assert( m_pBaseVar );
+ Assert( IsFlagSet( FCVAR_SS_ADDED ) );
+ Assert( !IsFlagSet( FCVAR_SS ) );
+ }
+
+ const ConVar *GetBaseVar() const;
+ virtual const char *GetBaseName() const;
+ void SetSplitScreenPlayerSlot( int nSlot );
+ virtual int GetSplitScreenPlayerSlot() const;
+
+protected:
+
+ const ConVar *m_pBaseVar;
+ int m_nSplitScreenSlot;
+};
+
+FORCEINLINE_CVAR const ConVar *CSplitScreenAddedConVar::GetBaseVar() const
+{
+ Assert( m_pBaseVar );
+ return m_pBaseVar;
+}
+
+FORCEINLINE_CVAR const char *CSplitScreenAddedConVar::GetBaseName() const
+{
+ Assert( m_pBaseVar );
+ return m_pBaseVar->GetName();
+}
+
+FORCEINLINE_CVAR void CSplitScreenAddedConVar::SetSplitScreenPlayerSlot( int nSlot )
+{
+ m_nSplitScreenSlot = nSlot;
+}
+
+FORCEINLINE_CVAR int CSplitScreenAddedConVar::GetSplitScreenPlayerSlot() const
+{
+ return m_nSplitScreenSlot;
+}
+
+//-----------------------------------------------------------------------------
+// Used to read/write convars that already exist (replaces the FindVar method)
+//-----------------------------------------------------------------------------
+class ConVarRef
+{
+public:
+ ConVarRef( const char *pName );
+ ConVarRef( const char *pName, bool bIgnoreMissing );
+ ConVarRef( IConVar *pConVar );
+
+ void Init( const char *pName, bool bIgnoreMissing );
+ bool IsValid() const;
+ bool IsFlagSet( int nFlags ) const;
+ IConVar *GetLinkedConVar();
+
+ // Get/Set value
+ float GetFloat( void ) const;
+ int GetInt( void ) const;
+ Color GetColor( void ) const;
+ bool GetBool() const { return !!GetInt(); }
+ const char *GetString( void ) const;
+
+ void SetValue( const char *pValue );
+ void SetValue( float flValue );
+ void SetValue( int nValue );
+ void SetValue( Color value );
+ void SetValue( bool bValue );
+
+ const char *GetName() const;
+
+ const char *GetDefault() const;
+
+ const char *GetBaseName() const;
+
+ int GetSplitScreenPlayerSlot() const;
+
+private:
+ // High-speed method to read convar data
+ IConVar *m_pConVar;
+ ConVar *m_pConVarState;
+};
+
+
+//-----------------------------------------------------------------------------
+// Did we find an existing convar of that name?
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
+{
+ return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
+}
+
+FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
+{
+ return m_pConVar;
+}
+
+FORCEINLINE_CVAR const char *ConVarRef::GetName() const
+{
+ return m_pConVar->GetName();
+}
+
+FORCEINLINE_CVAR const char *ConVarRef::GetBaseName() const
+{
+ return m_pConVar->GetBaseName();
+}
+
+FORCEINLINE_CVAR int ConVarRef::GetSplitScreenPlayerSlot() const
+{
+ return m_pConVar->GetSplitScreenPlayerSlot();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as a float
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
+{
+ return m_pConVarState->m_Value.m_fValue;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as an int
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
+{
+ return m_pConVarState->m_Value.m_nValue;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as a color
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR Color ConVarRef::GetColor( void ) const
+{
+ return m_pConVarState->GetColor();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
+{
+ Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
+ return m_pConVarState->m_Value.m_pszString;
+}
+
+
+FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
+{
+ m_pConVar->SetValue( pValue );
+}
+
+FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
+{
+ m_pConVar->SetValue( flValue );
+}
+
+FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
+{
+ m_pConVar->SetValue( nValue );
+}
+
+FORCEINLINE_CVAR void ConVarRef::SetValue( Color value )
+{
+ m_pConVar->SetValue( value );
+}
+
+FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
+{
+ m_pConVar->SetValue( bValue ? 1 : 0 );
+}
+
+FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
+{
+ return m_pConVarState->m_pszDefaultValue;
+}
+
+//-----------------------------------------------------------------------------
+// Helper for referencing splitscreen convars (i.e., "name" and "name2")
+//-----------------------------------------------------------------------------
+class SplitScreenConVarRef
+{
+public:
+ SplitScreenConVarRef( const char *pName );
+ SplitScreenConVarRef( const char *pName, bool bIgnoreMissing );
+ SplitScreenConVarRef( IConVar *pConVar );
+
+ void Init( const char *pName, bool bIgnoreMissing );
+ bool IsValid() const;
+ bool IsFlagSet( int nFlags ) const;
+
+ // Get/Set value
+ float GetFloat( int nSlot ) const;
+ int GetInt( int nSlot ) const;
+ Color GetColor( int nSlot ) const;
+ bool GetBool( int nSlot ) const { return !!GetInt( nSlot ); }
+ const char *GetString( int nSlot ) const;
+
+ void SetValue( int nSlot, const char *pValue );
+ void SetValue( int nSlot, float flValue );
+ void SetValue( int nSlot, int nValue );
+ void SetValue( int nSlot, Color value );
+ void SetValue( int nSlot, bool bValue );
+
+ const char *GetName( int nSlot ) const;
+
+ const char *GetDefault() const;
+
+ const char *GetBaseName() const;
+
+private:
+ struct cv_t
+ {
+ IConVar *m_pConVar;
+ ConVar *m_pConVarState;
+ };
+
+ cv_t m_Info[ MAX_SPLITSCREEN_CLIENTS ];
+};
+
+//-----------------------------------------------------------------------------
+// Did we find an existing convar of that name?
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR bool SplitScreenConVarRef::IsFlagSet( int nFlags ) const
+{
+ return ( m_Info[ 0 ].m_pConVar->IsFlagSet( nFlags ) != 0 );
+}
+
+FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetName( int nSlot ) const
+{
+ return m_Info[ nSlot ].m_pConVar->GetName();
+}
+
+FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetBaseName() const
+{
+ return m_Info[ 0 ].m_pConVar->GetBaseName();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as a float
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR float SplitScreenConVarRef::GetFloat( int nSlot ) const
+{
+ return m_Info[ nSlot ].m_pConVarState->m_Value.m_fValue;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as an int
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR int SplitScreenConVarRef::GetInt( int nSlot ) const
+{
+ return m_Info[ nSlot ].m_pConVarState->m_Value.m_nValue;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as an int
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR Color SplitScreenConVarRef::GetColor( int nSlot ) const
+{
+ return m_Info[ nSlot ].m_pConVarState->GetColor();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
+//-----------------------------------------------------------------------------
+FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetString( int nSlot ) const
+{
+ Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
+ return m_Info[ nSlot ].m_pConVarState->m_Value.m_pszString;
+}
+
+
+FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, const char *pValue )
+{
+ m_Info[ nSlot ].m_pConVar->SetValue( pValue );
+}
+
+FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, float flValue )
+{
+ m_Info[ nSlot ].m_pConVar->SetValue( flValue );
+}
+
+FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, int nValue )
+{
+ m_Info[ nSlot ].m_pConVar->SetValue( nValue );
+}
+
+FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, Color value )
+{
+ m_Info[ nSlot ].m_pConVar->SetValue( value );
+}
+
+FORCEINLINE_CVAR void SplitScreenConVarRef::SetValue( int nSlot, bool bValue )
+{
+ m_Info[ nSlot ].m_pConVar->SetValue( bValue ? 1 : 0 );
+}
+
+FORCEINLINE_CVAR const char *SplitScreenConVarRef::GetDefault() const
+{
+ return m_Info[ 0 ].m_pConVarState->m_pszDefaultValue;
+}
+
+//-----------------------------------------------------------------------------
+// Called by the framework to register ConCommands with the ICVar
+//-----------------------------------------------------------------------------
+void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
+void ConVar_Unregister( );
+
+
+//-----------------------------------------------------------------------------
+// Utility methods
+//-----------------------------------------------------------------------------
+void ConVar_PrintDescription( const ConCommandBase *pVar );
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Utility class to quickly allow ConCommands to call member methods
+//-----------------------------------------------------------------------------
+#ifdef _MSC_VER
+#pragma warning (disable : 4355 )
+#endif
+
+template< class T >
+class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
+{
+ typedef ConCommand BaseClass;
+ typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
+ typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
+
+public:
+ CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
+ int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
+ BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
+ {
+ m_pOwner = pOwner;
+ m_Func = callback;
+ m_CompletionFunc = completionFunc;
+ }
+
+ ~CConCommandMemberAccessor()
+ {
+ Shutdown();
+ }
+
+ void SetOwner( T* pOwner )
+ {
+ m_pOwner = pOwner;
+ }
+
+ virtual void CommandCallback( const CCommand &command )
+ {
+ Assert( m_pOwner && m_Func );
+ (m_pOwner->*m_Func)( command );
+ }
+
+ virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
+ {
+ Assert( m_pOwner && m_CompletionFunc );
+ return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
+ }
+
+private:
+ T* m_pOwner;
+ FnMemberCommandCallback_t m_Func;
+ FnMemberCommandCompletionCallback_t m_CompletionFunc;
+};
+
+#ifdef _MSC_VER
+#pragma warning ( default : 4355 )
+#endif
+
+//-----------------------------------------------------------------------------
+// Purpose: Utility macros to quicky generate a simple console command
+//-----------------------------------------------------------------------------
+#define CON_COMMAND( name, description ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command( #name, name, description ); \
+ static void name( const CCommand &args )
+
+#ifdef CLIENT_DLL
+ #define CON_COMMAND_SHARED( name, description ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command_client( #name "_client", name, description ); \
+ static void name( const CCommand &args )
+#else
+ #define CON_COMMAND_SHARED( name, description ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command( #name, name, description ); \
+ static void name( const CCommand &args )
+#endif
+
+
+#define CON_COMMAND_F( name, description, flags ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command( #name, name, description, flags ); \
+ static void name( const CCommand &args )
+
+#ifdef CLIENT_DLL
+ #define CON_COMMAND_F_SHARED( name, description, flags ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command_client( #name "_client", name, description, flags ); \
+ static void name( const CCommand &args )
+#else
+ #define CON_COMMAND_F_SHARED( name, description, flags ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command( #name, name, description, flags ); \
+ static void name( const CCommand &args )
+#endif
+
+
+#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command( #name, name, description, flags, completion ); \
+ static void name( const CCommand &args )
+
+#ifdef CLIENT_DLL
+ #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command_client( #name "_client", name, description, flags, completion ); \
+ static void name( const CCommand &args )
+#else
+ #define CON_COMMAND_F_COMPLETION_SHARED( name, description, flags, completion ) \
+ static void name( const CCommand &args ); \
+ static ConCommand name##_command( #name, name, description, flags, completion ); \
+ static void name( const CCommand &args )
+#endif
+
+
+#define CON_COMMAND_EXTERN( name, _funcname, description ) \
+ void _funcname( const CCommand &args ); \
+ static ConCommand name##_command( #name, _funcname, description ); \
+ void _funcname( const CCommand &args )
+
+#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
+ void _funcname( const CCommand &args ); \
+ static ConCommand name##_command( #name, _funcname, description, flags ); \
+ void _funcname( const CCommand &args )
+
+#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
+ void _funcname( const CCommand &args ); \
+ friend class CCommandMemberInitializer_##_funcname; \
+ class CCommandMemberInitializer_##_funcname \
+ { \
+ public: \
+ CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
+ { \
+ m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
+ } \
+ private: \
+ CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
+ }; \
+ \
+ CCommandMemberInitializer_##_funcname m_##_funcname##_register; \
+
+
+#endif // CONVAR_H
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy