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.

230 lines
5.7 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =====//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "cbase.h"
  7. #include "toolframework_client.h"
  8. #include "igamesystem.h"
  9. #include "tier1/keyvalues.h"
  10. #include "toolframework/iclientenginetools.h"
  11. #include "client_factorylist.h"
  12. #include "iviewrender.h"
  13. #include "materialsystem/imaterialvar.h"
  14. // NOTE: This has to be the last file included!
  15. #include "tier0/memdbgon.h"
  16. extern IViewRender *view;
  17. class CToolFrameworkClient : public CBaseGameSystemPerFrame
  18. {
  19. public:
  20. // Methods of IGameSystem
  21. virtual bool Init();
  22. virtual void LevelInitPreEntity();
  23. virtual void LevelInitPostEntity();
  24. virtual void LevelShutdownPreEntity();
  25. virtual void LevelShutdownPostEntity();
  26. virtual void PreRender();
  27. virtual void PostRender();
  28. public:
  29. // Other public methods
  30. void PostToolMessage( HTOOLHANDLE hEntity, KeyValues *msg );
  31. void AdjustEngineViewport( int& x, int& y, int& width, int& height );
  32. bool SetupEngineView( Vector &origin, QAngle &angles, float &fov );
  33. bool SetupAudioState( AudioState_t &audioState );
  34. bool IsThirdPersonCamera();
  35. IClientEngineTools *m_pTools;
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Singleton
  39. //-----------------------------------------------------------------------------
  40. static CToolFrameworkClient g_ToolFrameworkClient;
  41. #ifndef NO_TOOLFRAMEWORK
  42. bool ToolsEnabled()
  43. {
  44. return g_ToolFrameworkClient.m_pTools && g_ToolFrameworkClient.m_pTools->InToolMode();
  45. }
  46. #endif
  47. IGameSystem *ToolFrameworkClientSystem()
  48. {
  49. return &g_ToolFrameworkClient;
  50. }
  51. bool CToolFrameworkClient::Init()
  52. {
  53. factorylist_t list;
  54. FactoryList_Retrieve( list );
  55. m_pTools = ( IClientEngineTools * )list.appSystemFactory( VCLIENTENGINETOOLS_INTERFACE_VERSION, NULL );
  56. return ( m_pTools != NULL );
  57. }
  58. void CToolFrameworkClient::LevelInitPreEntity()
  59. {
  60. if ( m_pTools )
  61. {
  62. m_pTools->LevelInitPreEntityAllTools();
  63. }
  64. }
  65. void CToolFrameworkClient::LevelInitPostEntity()
  66. {
  67. if ( m_pTools )
  68. {
  69. m_pTools->LevelInitPostEntityAllTools();
  70. }
  71. }
  72. void CToolFrameworkClient::LevelShutdownPreEntity()
  73. {
  74. if ( m_pTools )
  75. {
  76. m_pTools->LevelShutdownPreEntityAllTools();
  77. }
  78. }
  79. void CToolFrameworkClient::LevelShutdownPostEntity()
  80. {
  81. if ( m_pTools )
  82. {
  83. m_pTools->LevelShutdownPostEntityAllTools();
  84. }
  85. }
  86. void CToolFrameworkClient::PreRender()
  87. {
  88. if ( m_pTools )
  89. {
  90. m_pTools->PreRenderAllTools();
  91. }
  92. }
  93. void CToolFrameworkClient::PostRender()
  94. {
  95. if ( m_pTools )
  96. {
  97. m_pTools->PostRenderAllTools();
  98. }
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Should we render with a 3rd person camera?
  102. //-----------------------------------------------------------------------------
  103. bool CToolFrameworkClient::IsThirdPersonCamera()
  104. {
  105. if ( !m_pTools )
  106. return false;
  107. return m_pTools->IsThirdPersonCamera( );
  108. }
  109. bool ToolFramework_IsThirdPersonCamera( )
  110. {
  111. return g_ToolFrameworkClient.IsThirdPersonCamera( );
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Posts a message to all tools
  115. //-----------------------------------------------------------------------------
  116. void CToolFrameworkClient::PostToolMessage( HTOOLHANDLE hEntity, KeyValues *msg )
  117. {
  118. if ( m_pTools )
  119. {
  120. m_pTools->PostToolMessage( hEntity, msg );
  121. }
  122. }
  123. void ToolFramework_PostToolMessage( HTOOLHANDLE hEntity, KeyValues *msg )
  124. {
  125. g_ToolFrameworkClient.PostToolMessage( hEntity, msg );
  126. }
  127. //-----------------------------------------------------------------------------
  128. // View manipulation
  129. //-----------------------------------------------------------------------------
  130. void CToolFrameworkClient::AdjustEngineViewport( int& x, int& y, int& width, int& height )
  131. {
  132. if ( m_pTools )
  133. {
  134. m_pTools->AdjustEngineViewport( x, y, width, height );
  135. }
  136. }
  137. void ToolFramework_AdjustEngineViewport( int& x, int& y, int& width, int& height )
  138. {
  139. g_ToolFrameworkClient.AdjustEngineViewport( x, y, width, height );
  140. }
  141. //-----------------------------------------------------------------------------
  142. // View manipulation
  143. //-----------------------------------------------------------------------------
  144. bool CToolFrameworkClient::SetupEngineView( Vector &origin, QAngle &angles, float &fov )
  145. {
  146. if ( !m_pTools )
  147. return false;
  148. return m_pTools->SetupEngineView( origin, angles, fov );
  149. }
  150. bool ToolFramework_SetupEngineView( Vector &origin, QAngle &angles, float &fov )
  151. {
  152. return g_ToolFrameworkClient.SetupEngineView( origin, angles, fov );
  153. }
  154. //-----------------------------------------------------------------------------
  155. // microphone manipulation
  156. //-----------------------------------------------------------------------------
  157. bool CToolFrameworkClient::SetupAudioState( AudioState_t &audioState )
  158. {
  159. if ( !m_pTools )
  160. return false;
  161. return m_pTools->SetupAudioState( audioState );
  162. }
  163. bool ToolFramework_SetupAudioState( AudioState_t &audioState )
  164. {
  165. return g_ToolFrameworkClient.SetupAudioState( audioState );
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Helper class to indicate ownership of effects
  169. //-----------------------------------------------------------------------------
  170. CRecordEffectOwner::CRecordEffectOwner( C_BaseEntity *pEntity, bool bIsViewModel )
  171. {
  172. m_bToolsEnabled = ToolsEnabled() && clienttools->IsInRecordingMode();
  173. if ( m_bToolsEnabled )
  174. {
  175. KeyValues *msg = new KeyValues( "EffectsOwner" );
  176. msg->SetInt( "viewModel", bIsViewModel );
  177. ToolFramework_PostToolMessage( pEntity ? pEntity->GetToolHandle() : HTOOLHANDLE_INVALID, msg );
  178. msg->deleteThis();
  179. }
  180. }
  181. CRecordEffectOwner::~CRecordEffectOwner()
  182. {
  183. if ( m_bToolsEnabled )
  184. {
  185. KeyValues *msg = new KeyValues( "EffectsOwner" );
  186. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  187. msg->deleteThis();
  188. }
  189. }