Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
6.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef ICVAR_H
  7. #define ICVAR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "appframework/IAppSystem.h"
  12. #include "tier1/iconvar.h"
  13. class ConCommandBase;
  14. class ConCommand;
  15. class ConVar;
  16. class Color;
  17. //-----------------------------------------------------------------------------
  18. // ConVars/ComCommands are marked as having a particular DLL identifier
  19. //-----------------------------------------------------------------------------
  20. typedef int CVarDLLIdentifier_t;
  21. //-----------------------------------------------------------------------------
  22. // Used to display console messages
  23. //-----------------------------------------------------------------------------
  24. abstract_class IConsoleDisplayFunc
  25. {
  26. public:
  27. virtual void ColorPrint( const Color& clr, const char *pMessage ) = 0;
  28. virtual void Print( const char *pMessage ) = 0;
  29. virtual void DPrint( const char *pMessage ) = 0;
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Applications can implement this to modify behavior in ICvar
  33. //-----------------------------------------------------------------------------
  34. #define CVAR_QUERY_INTERFACE_VERSION "VCvarQuery001"
  35. abstract_class ICvarQuery : public IAppSystem
  36. {
  37. public:
  38. // Can these two convars be aliased?
  39. virtual bool AreConVarsLinkable( const ConVar *child, const ConVar *parent ) = 0;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Purpose: DLL interface to ConVars/ConCommands
  43. //-----------------------------------------------------------------------------
  44. abstract_class ICvar : public IAppSystem
  45. {
  46. public:
  47. // Allocate a unique DLL identifier
  48. virtual CVarDLLIdentifier_t AllocateDLLIdentifier() = 0;
  49. // Register, unregister commands
  50. virtual void RegisterConCommand( ConCommandBase *pCommandBase ) = 0;
  51. virtual void UnregisterConCommand( ConCommandBase *pCommandBase ) = 0;
  52. virtual void UnregisterConCommands( CVarDLLIdentifier_t id ) = 0;
  53. // If there is a +<varname> <value> on the command line, this returns the value.
  54. // Otherwise, it returns NULL.
  55. virtual const char* GetCommandLineValue( const char *pVariableName ) = 0;
  56. // Try to find the cvar pointer by name
  57. virtual ConCommandBase *FindCommandBase( const char *name ) = 0;
  58. virtual const ConCommandBase *FindCommandBase( const char *name ) const = 0;
  59. virtual ConVar *FindVar ( const char *var_name ) = 0;
  60. virtual const ConVar *FindVar ( const char *var_name ) const = 0;
  61. virtual ConCommand *FindCommand( const char *name ) = 0;
  62. virtual const ConCommand *FindCommand( const char *name ) const = 0;
  63. // Get first ConCommandBase to allow iteration
  64. virtual ConCommandBase *GetCommands( void ) = 0;
  65. virtual const ConCommandBase *GetCommands( void ) const = 0;
  66. // Install a global change callback (to be called when any convar changes)
  67. virtual void InstallGlobalChangeCallback( FnChangeCallback_t callback ) = 0;
  68. virtual void RemoveGlobalChangeCallback( FnChangeCallback_t callback ) = 0;
  69. virtual void CallGlobalChangeCallbacks( ConVar *var, const char *pOldString, float flOldValue ) = 0;
  70. // Install a console printer
  71. virtual void InstallConsoleDisplayFunc( IConsoleDisplayFunc* pDisplayFunc ) = 0;
  72. virtual void RemoveConsoleDisplayFunc( IConsoleDisplayFunc* pDisplayFunc ) = 0;
  73. virtual void ConsoleColorPrintf( const Color& clr, PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 3, 4 ) = 0;
  74. virtual void ConsolePrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 2, 3 ) = 0;
  75. virtual void ConsoleDPrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 2, 3 ) = 0;
  76. // Reverts cvars which contain a specific flag
  77. virtual void RevertFlaggedConVars( int nFlag ) = 0;
  78. // Method allowing the engine ICvarQuery interface to take over
  79. // A little hacky, owing to the fact the engine is loaded
  80. // well after ICVar, so we can't use the standard connect pattern
  81. virtual void InstallCVarQuery( ICvarQuery *pQuery ) = 0;
  82. #if defined( _X360 )
  83. virtual void PublishToVXConsole( ) = 0;
  84. #endif
  85. virtual bool IsMaterialThreadSetAllowed( ) const = 0;
  86. virtual void QueueMaterialThreadSetValue( ConVar *pConVar, const char *pValue ) = 0;
  87. virtual void QueueMaterialThreadSetValue( ConVar *pConVar, int nValue ) = 0;
  88. virtual void QueueMaterialThreadSetValue( ConVar *pConVar, float flValue ) = 0;
  89. virtual bool HasQueuedMaterialThreadConVarSets() const = 0;
  90. virtual int ProcessQueuedMaterialThreadConVarSets() = 0;
  91. protected: class ICVarIteratorInternal;
  92. public:
  93. /// Iteration over all cvars.
  94. /// (THIS IS A SLOW OPERATION AND YOU SHOULD AVOID IT.)
  95. /// usage:
  96. /// { ICvar::Iterator iter(g_pCVar);
  97. /// for ( iter.SetFirst() ; iter.IsValid() ; iter.Next() )
  98. /// {
  99. /// ConCommandBase *cmd = iter.Get();
  100. /// }
  101. /// }
  102. /// The Iterator class actually wraps the internal factory methods
  103. /// so you don't need to worry about new/delete -- scope takes care
  104. // of it.
  105. /// We need an iterator like this because we can't simply return a
  106. /// pointer to the internal data type that contains the cvars --
  107. /// it's a custom, protected class with unusual semantics and is
  108. /// prone to change.
  109. class Iterator
  110. {
  111. public:
  112. inline Iterator(ICvar *icvar);
  113. inline ~Iterator(void);
  114. inline void SetFirst( void );
  115. inline void Next( void );
  116. inline bool IsValid( void );
  117. inline ConCommandBase *Get( void );
  118. private:
  119. ICVarIteratorInternal *m_pIter;
  120. };
  121. protected:
  122. // internals for ICVarIterator
  123. class ICVarIteratorInternal
  124. {
  125. public:
  126. // warning: delete called on 'ICvar::ICVarIteratorInternal' that is abstract but has non-virtual destructor [-Wdelete-non-virtual-dtor]
  127. virtual ~ICVarIteratorInternal() {}
  128. virtual void SetFirst( void ) = 0;
  129. virtual void Next( void ) = 0;
  130. virtual bool IsValid( void ) = 0;
  131. virtual ConCommandBase *Get( void ) = 0;
  132. };
  133. virtual ICVarIteratorInternal *FactoryInternalIterator( void ) = 0;
  134. friend class Iterator;
  135. };
  136. inline ICvar::Iterator::Iterator(ICvar *icvar)
  137. {
  138. m_pIter = icvar->FactoryInternalIterator();
  139. }
  140. inline ICvar::Iterator::~Iterator( void )
  141. {
  142. delete m_pIter;
  143. }
  144. inline void ICvar::Iterator::SetFirst( void )
  145. {
  146. m_pIter->SetFirst();
  147. }
  148. inline void ICvar::Iterator::Next( void )
  149. {
  150. m_pIter->Next();
  151. }
  152. inline bool ICvar::Iterator::IsValid( void )
  153. {
  154. return m_pIter->IsValid();
  155. }
  156. inline ConCommandBase * ICvar::Iterator::Get( void )
  157. {
  158. return m_pIter->Get();
  159. }
  160. #define CVAR_INTERFACE_VERSION "VEngineCvar004"
  161. //-----------------------------------------------------------------------------
  162. // These global names are defined by tier1.h, duplicated here so you
  163. // don't have to include tier1.h
  164. //-----------------------------------------------------------------------------
  165. // These are marked DLL_EXPORT for Linux.
  166. DLL_EXPORT ICvar *cvar;
  167. extern ICvar *g_pCVar;
  168. #endif // ICVAR_H