Counter Strike : Global Offensive Source Code
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.

214 lines
7.4 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, PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 3, 4 ) = 0;
  73. virtual void ConsolePrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 2, 3 ) = 0;
  74. virtual void ConsoleDPrintf( PRINTF_FORMAT_STRING const char *pFormat, ... ) const FMTFUNCTION( 2, 3 ) = 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 ) RESTRICT;
  121. inline void Next( void ) RESTRICT;
  122. inline bool IsValid( void ) RESTRICT;
  123. inline ConCommandBase *Get( void ) RESTRICT;
  124. private:
  125. ICVarIteratorInternal *m_pIter;
  126. };
  127. protected:
  128. // internals for ICVarIterator
  129. class ICVarIteratorInternal
  130. {
  131. public:
  132. // This should be a virtual destructor to avoid undefined behavior and many warnings, but doing so
  133. // causes plugins to break. It's not worth the trouble at this point.
  134. //virtual ~ICVarIteratorInternal() {}
  135. virtual void SetFirst( void ) RESTRICT = 0;
  136. virtual void Next( void ) RESTRICT = 0;
  137. virtual bool IsValid( void ) RESTRICT = 0;
  138. virtual ConCommandBase *Get( void ) RESTRICT = 0;
  139. };
  140. virtual ICVarIteratorInternal *FactoryInternalIterator( void ) = 0;
  141. friend class Iterator;
  142. };
  143. inline ICvar::Iterator::Iterator(ICvar *icvar)
  144. {
  145. m_pIter = icvar->FactoryInternalIterator();
  146. }
  147. inline ICvar::Iterator::~Iterator( void )
  148. {
  149. delete m_pIter;
  150. }
  151. inline void ICvar::Iterator::SetFirst( void ) RESTRICT
  152. {
  153. m_pIter->SetFirst();
  154. }
  155. inline void ICvar::Iterator::Next( void ) RESTRICT
  156. {
  157. m_pIter->Next();
  158. }
  159. inline bool ICvar::Iterator::IsValid( void ) RESTRICT
  160. {
  161. return m_pIter->IsValid();
  162. }
  163. inline ConCommandBase * ICvar::Iterator::Get( void ) RESTRICT
  164. {
  165. return m_pIter->Get();
  166. }
  167. //-----------------------------------------------------------------------------
  168. // These global names are defined by tier1.h, duplicated here so you
  169. // don't have to include tier1.h
  170. //-----------------------------------------------------------------------------
  171. // These are marked DLL_EXPORT for Linux.
  172. DECLARE_TIER1_INTERFACE( ICvar, cvar );
  173. DECLARE_TIER1_INTERFACE( ICvar, g_pCVar );
  174. #endif // ICVAR_H