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.

218 lines
8.3 KiB

  1. //========= Copyright � 1996-2007, Valve Corporation, All rights reserved. ====
  2. //
  3. // An entity that allows level designer control over the fog parameters.
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "postprocesscontroller.h"
  8. #include "entityinput.h"
  9. #include "entityoutput.h"
  10. #include "eventqueue.h"
  11. #include "player.h"
  12. #include "world.h"
  13. #include "ndebugoverlay.h"
  14. #include "triggers.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. CPostProcessSystem s_PostProcessSystem( "PostProcessSystem" );
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. CPostProcessSystem *PostProcessSystem( void )
  22. {
  23. return &s_PostProcessSystem;
  24. }
  25. LINK_ENTITY_TO_CLASS( postprocess_controller, CPostProcessController );
  26. BEGIN_DATADESC( CPostProcessController )
  27. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_FADE_TIME ], FIELD_FLOAT, "fadetime" ),
  28. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_LOCAL_CONTRAST_STRENGTH ], FIELD_FLOAT, "localcontraststrength" ),
  29. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_LOCAL_CONTRAST_EDGE_STRENGTH ], FIELD_FLOAT, "localcontrastedgestrength" ),
  30. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_VIGNETTE_START ], FIELD_TIME, "vignettestart" ),
  31. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_VIGNETTE_END ], FIELD_TIME, "vignetteend" ),
  32. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_VIGNETTE_BLUR_STRENGTH ], FIELD_FLOAT, "vignetteblurstrength" ),
  33. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_FADE_TO_BLACK_STRENGTH ], FIELD_FLOAT, "fadetoblackstrength" ),
  34. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_DEPTH_BLUR_FOCAL_DISTANCE ], FIELD_FLOAT, "depthblurfocaldistance" ),
  35. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_DEPTH_BLUR_STRENGTH ], FIELD_FLOAT, "depthblurstrength" ),
  36. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_SCREEN_BLUR_STRENGTH ], FIELD_FLOAT, "screenblurstrength" ),
  37. DEFINE_KEYFIELD( m_flPostProcessParameters[ PPPN_FILM_GRAIN_STRENGTH ], FIELD_FLOAT, "filmgrainstrength" ),
  38. // Inputs
  39. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFadeTime", InputSetFadeTime ),
  40. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetLocalContrastStrength", InputSetLocalContrastStrength ),
  41. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetLocalContrastEdgeStrength", InputSetLocalContrastEdgeStrength ),
  42. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetVignetteStart", InputSetVignetteStart ),
  43. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetVignetteEnd", InputSetVignetteEnd ),
  44. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetVignetteBlurStrength", InputSetVignetteBlurStrength ),
  45. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFadeToBlackStrength", InputSetFadeToBlackStrength ),
  46. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetDepthBlurFocalDistance", InputSetDepthBlurFocalDistance),
  47. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetDepthBlurStrength", InputSetDepthBlurStrength ),
  48. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetScreenBlurStrength", InputSetScreenBlurStrength ),
  49. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetFilmGrainStrength", InputSetFilmGrainStrength ),
  50. END_DATADESC()
  51. IMPLEMENT_SERVERCLASS_ST( CPostProcessController, DT_PostProcessController )
  52. SendPropArray3( SENDINFO_ARRAY3( m_flPostProcessParameters ), SendPropFloat( SENDINFO_ARRAY( m_flPostProcessParameters ) ) ),
  53. SendPropBool( SENDINFO(m_bMaster) ),
  54. END_SEND_TABLE()
  55. CPostProcessController::CPostProcessController()
  56. : m_bMaster( false )
  57. {
  58. }
  59. CPostProcessController::~CPostProcessController()
  60. {
  61. }
  62. void CPostProcessController::Spawn( void )
  63. {
  64. BaseClass::Spawn();
  65. m_bMaster = IsMaster();
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Activate!
  69. //-----------------------------------------------------------------------------
  70. void CPostProcessController::Activate( )
  71. {
  72. BaseClass::Activate();
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose:
  76. //-----------------------------------------------------------------------------
  77. int CPostProcessController::UpdateTransmitState()
  78. {
  79. return SetTransmitState( FL_EDICT_ALWAYS );
  80. }
  81. void CPostProcessController::InputSetFadeTime( inputdata_t &inputdata )
  82. {
  83. m_flPostProcessParameters.Set( PPPN_FADE_TIME, inputdata.value.Float() );
  84. }
  85. void CPostProcessController::InputSetLocalContrastStrength( inputdata_t &inputdata )
  86. {
  87. m_flPostProcessParameters.Set( PPPN_LOCAL_CONTRAST_STRENGTH, inputdata.value.Float() );
  88. }
  89. void CPostProcessController::InputSetLocalContrastEdgeStrength( inputdata_t &inputdata )
  90. {
  91. m_flPostProcessParameters.Set( PPPN_LOCAL_CONTRAST_EDGE_STRENGTH, inputdata.value.Float() );
  92. }
  93. void CPostProcessController::InputSetVignetteStart( inputdata_t &inputdata )
  94. {
  95. m_flPostProcessParameters.Set( PPPN_VIGNETTE_START, inputdata.value.Float() );
  96. }
  97. void CPostProcessController::InputSetVignetteEnd( inputdata_t &inputdata )
  98. {
  99. m_flPostProcessParameters.Set( PPPN_VIGNETTE_END, inputdata.value.Float() );
  100. }
  101. void CPostProcessController::InputSetVignetteBlurStrength( inputdata_t &inputdata )
  102. {
  103. m_flPostProcessParameters.Set( PPPN_VIGNETTE_BLUR_STRENGTH, inputdata.value.Float() );
  104. }
  105. void CPostProcessController::InputSetFadeToBlackStrength( inputdata_t &inputdata )
  106. {
  107. m_flPostProcessParameters.Set( PPPN_FADE_TO_BLACK_STRENGTH, inputdata.value.Float() );
  108. }
  109. void CPostProcessController::InputSetDepthBlurFocalDistance( inputdata_t &inputdata )
  110. {
  111. m_flPostProcessParameters.Set( PPPN_DEPTH_BLUR_FOCAL_DISTANCE, inputdata.value.Float() );
  112. }
  113. void CPostProcessController::InputSetDepthBlurStrength( inputdata_t &inputdata )
  114. {
  115. m_flPostProcessParameters.Set( PPPN_DEPTH_BLUR_STRENGTH, inputdata.value.Float() );
  116. }
  117. void CPostProcessController::InputSetScreenBlurStrength( inputdata_t &inputdata )
  118. {
  119. m_flPostProcessParameters.Set( PPPN_SCREEN_BLUR_STRENGTH, inputdata.value.Float() );
  120. }
  121. void CPostProcessController::InputSetFilmGrainStrength( inputdata_t &inputdata )
  122. {
  123. m_flPostProcessParameters.Set( PPPN_FILM_GRAIN_STRENGTH, inputdata.value.Float() );
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose: Clear out the PostProcess controller.
  127. //-----------------------------------------------------------------------------
  128. void CPostProcessSystem::LevelInitPreEntity( void )
  129. {
  130. m_hMasterController = NULL;
  131. ListenForGameEvent( "round_start" );
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose: Find the master controller. If no controller is
  135. // set as Master, use the first controller found.
  136. //-----------------------------------------------------------------------------
  137. void CPostProcessSystem::InitMasterController( void )
  138. {
  139. CPostProcessController *pPostProcessController = NULL;
  140. do
  141. {
  142. pPostProcessController = dynamic_cast<CPostProcessController*>( gEntList.FindEntityByClassname( pPostProcessController, "postprocess_controller" ) );
  143. if ( pPostProcessController )
  144. {
  145. if ( m_hMasterController.Get() == NULL )
  146. {
  147. m_hMasterController = pPostProcessController;
  148. }
  149. else
  150. {
  151. if ( pPostProcessController->IsMaster() )
  152. {
  153. m_hMasterController = pPostProcessController;
  154. }
  155. }
  156. }
  157. } while ( pPostProcessController );
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose: On a multiplayer map restart, re-find the master controller.
  161. //-----------------------------------------------------------------------------
  162. void CPostProcessSystem::FireGameEvent( IGameEvent *pEvent )
  163. {
  164. InitMasterController();
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose: On level load find the master PostProcess controller. If no controller is
  168. // set as Master, use the first PostProcess controller found.
  169. //-----------------------------------------------------------------------------
  170. void CPostProcessSystem::LevelInitPostEntity( void )
  171. {
  172. InitMasterController();
  173. // HACK: Singleplayer games don't get a call to CBasePlayer::Spawn on level transitions.
  174. // CBasePlayer::Activate is called before this is called so that's too soon to set up the PostProcess controller.
  175. // We don't have a hook similar to Activate that happens after LevelInitPostEntity
  176. // is called, or we could just do this in the player itself.
  177. if ( gpGlobals->maxClients == 1 )
  178. {
  179. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  180. if ( pPlayer && ( pPlayer->m_hPostProcessCtrl.Get() == NULL ) )
  181. {
  182. pPlayer->InitPostProcessController();
  183. }
  184. }
  185. }