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.

211 lines
7.0 KiB

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