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.

311 lines
8.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "shareddefs.h"
  8. #include "materialsystem/imesh.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "view.h"
  11. #include "iviewrender.h"
  12. #include "view_shared.h"
  13. #include "texture_group_names.h"
  14. #include "tier0/icommandline.h"
  15. #include "keyvalues.h"
  16. #include "ScreenSpaceEffects.h"
  17. #include "materialsystem/imaterialsystemhardwareconfig.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. class C_EnvScreenOverlay : public C_BaseEntity
  24. {
  25. DECLARE_CLASS( C_EnvScreenOverlay, C_BaseEntity );
  26. public:
  27. DECLARE_CLIENTCLASS();
  28. void PreDataUpdate( DataUpdateType_t updateType );
  29. void PostDataUpdate( DataUpdateType_t updateType );
  30. void HandleOverlaySwitch( void );
  31. void StartOverlays( void );
  32. void StopOverlays( void );
  33. void StartCurrentOverlay( void );
  34. void ClientThink( void );
  35. protected:
  36. char m_iszOverlayNames[ MAX_SCREEN_OVERLAYS ][255];
  37. float m_flOverlayTimes[ MAX_SCREEN_OVERLAYS ];
  38. float m_flStartTime;
  39. int m_iDesiredOverlay;
  40. bool m_bIsActive;
  41. bool m_bWasActive;
  42. int m_iCachedDesiredOverlay;
  43. int m_iCurrentOverlay;
  44. float m_flCurrentOverlayTime;
  45. };
  46. IMPLEMENT_CLIENTCLASS_DT( C_EnvScreenOverlay, DT_EnvScreenOverlay, CEnvScreenOverlay )
  47. RecvPropArray( RecvPropString( RECVINFO( m_iszOverlayNames[0]) ), m_iszOverlayNames ),
  48. RecvPropArray( RecvPropFloat( RECVINFO( m_flOverlayTimes[0] ) ), m_flOverlayTimes ),
  49. RecvPropFloat( RECVINFO( m_flStartTime ) ),
  50. RecvPropInt( RECVINFO( m_iDesiredOverlay ) ),
  51. RecvPropBool( RECVINFO( m_bIsActive ) ),
  52. END_RECV_TABLE()
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. // Input : updateType -
  56. //-----------------------------------------------------------------------------
  57. void C_EnvScreenOverlay::PreDataUpdate( DataUpdateType_t updateType )
  58. {
  59. BaseClass::PreDataUpdate( updateType );
  60. m_bWasActive = m_bIsActive;
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. //-----------------------------------------------------------------------------
  65. void C_EnvScreenOverlay::PostDataUpdate( DataUpdateType_t updateType )
  66. {
  67. BaseClass::PostDataUpdate( updateType );
  68. // If we have a start time now, start the overlays going
  69. if ( m_bIsActive && m_flStartTime > 0 && view->GetScreenOverlayMaterial() == NULL )
  70. {
  71. StartOverlays();
  72. }
  73. if ( m_flStartTime == -1 )
  74. {
  75. StopOverlays();
  76. }
  77. HandleOverlaySwitch();
  78. if ( updateType == DATA_UPDATE_CREATED &&
  79. CommandLine()->FindParm( "-makereslists" ) )
  80. {
  81. for ( int i = 0; i < MAX_SCREEN_OVERLAYS; ++i )
  82. {
  83. if ( m_iszOverlayNames[ i ] && m_iszOverlayNames[ i ][ 0 ] )
  84. {
  85. materials->FindMaterial( m_iszOverlayNames[ i ], TEXTURE_GROUP_CLIENT_EFFECTS, false );
  86. }
  87. }
  88. }
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void C_EnvScreenOverlay::StopOverlays( void )
  94. {
  95. SetNextClientThink( CLIENT_THINK_NEVER );
  96. if ( m_bWasActive && !m_bIsActive )
  97. {
  98. view->SetScreenOverlayMaterial( NULL );
  99. }
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. void C_EnvScreenOverlay::StartOverlays( void )
  105. {
  106. m_iCurrentOverlay = 0;
  107. m_flCurrentOverlayTime = 0;
  108. m_iCachedDesiredOverlay = 0;
  109. SetNextClientThink( CLIENT_THINK_ALWAYS );
  110. StartCurrentOverlay();
  111. HandleOverlaySwitch();
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose:
  115. //-----------------------------------------------------------------------------
  116. void C_EnvScreenOverlay::HandleOverlaySwitch( void )
  117. {
  118. if( m_iCachedDesiredOverlay != m_iDesiredOverlay )
  119. {
  120. m_iCurrentOverlay = m_iDesiredOverlay;
  121. m_iCachedDesiredOverlay = m_iDesiredOverlay;
  122. StartCurrentOverlay();
  123. }
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. void C_EnvScreenOverlay::StartCurrentOverlay( void )
  129. {
  130. if ( m_iCurrentOverlay == MAX_SCREEN_OVERLAYS || !m_iszOverlayNames[m_iCurrentOverlay] || !m_iszOverlayNames[m_iCurrentOverlay][0] )
  131. {
  132. // Hit the end of our overlays, so stop.
  133. m_flStartTime = 0;
  134. StopOverlays();
  135. return;
  136. }
  137. if ( m_flOverlayTimes[m_iCurrentOverlay] == -1 )
  138. m_flCurrentOverlayTime = -1;
  139. else
  140. m_flCurrentOverlayTime = gpGlobals->curtime + m_flOverlayTimes[m_iCurrentOverlay];
  141. // Bring up the current overlay
  142. IMaterial *pMaterial = materials->FindMaterial( m_iszOverlayNames[m_iCurrentOverlay], TEXTURE_GROUP_CLIENT_EFFECTS, false );
  143. if ( !IsErrorMaterial( pMaterial ) )
  144. {
  145. view->SetScreenOverlayMaterial( pMaterial );
  146. }
  147. else
  148. {
  149. Warning("env_screenoverlay couldn't find overlay %s.\n", m_iszOverlayNames[m_iCurrentOverlay] );
  150. StopOverlays();
  151. }
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. //-----------------------------------------------------------------------------
  156. void C_EnvScreenOverlay::ClientThink( void )
  157. {
  158. // If the current overlay's run out, go to the next one
  159. if ( m_flCurrentOverlayTime != -1 && m_flCurrentOverlayTime < gpGlobals->curtime )
  160. {
  161. m_iCurrentOverlay++;
  162. StartCurrentOverlay();
  163. }
  164. }
  165. // Effect types
  166. enum
  167. {
  168. SCREENEFFECT_EP2_ADVISOR_STUN,
  169. SCREENEFFECT_EP1_INTRO,
  170. SCREENEFFECT_EP2_GROGGY,
  171. };
  172. // ============================================================================
  173. // Screenspace effect
  174. // ============================================================================
  175. class C_EnvScreenEffect : public C_BaseEntity
  176. {
  177. DECLARE_CLASS( C_EnvScreenEffect, C_BaseEntity );
  178. public:
  179. DECLARE_CLIENTCLASS();
  180. virtual void ReceiveMessage( int classID, bf_read &msg );
  181. private:
  182. float m_flDuration;
  183. int m_nType;
  184. };
  185. IMPLEMENT_CLIENTCLASS_DT( C_EnvScreenEffect, DT_EnvScreenEffect, CEnvScreenEffect )
  186. RecvPropFloat( RECVINFO( m_flDuration ) ),
  187. RecvPropInt( RECVINFO( m_nType ) ),
  188. END_RECV_TABLE()
  189. //-----------------------------------------------------------------------------
  190. // Purpose:
  191. // Input : classID -
  192. // &msg -
  193. //-----------------------------------------------------------------------------
  194. void C_EnvScreenEffect::ReceiveMessage( int classID, bf_read &msg )
  195. {
  196. // Make sure our IDs match
  197. if ( classID != GetClientClass()->m_ClassID )
  198. {
  199. // Message is for subclass
  200. BaseClass::ReceiveMessage( classID, msg );
  201. return;
  202. }
  203. int messageType = msg.ReadByte();
  204. switch( messageType )
  205. {
  206. // Effect turning on
  207. case 0: // FIXME: Declare
  208. {
  209. // Create a keyvalue block to set these params
  210. KeyValues *pKeys = new KeyValues( "keys" );
  211. if ( pKeys == NULL )
  212. return;
  213. if ( m_nType == SCREENEFFECT_EP1_INTRO )
  214. {
  215. // Set our keys
  216. pKeys->SetFloat( "duration", m_flDuration );
  217. pKeys->SetInt( "fadeout", 0 );
  218. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "episodic_intro", pKeys );
  219. g_pScreenSpaceEffects->EnableScreenSpaceEffect( "episodic_intro" );
  220. }
  221. else if ( m_nType == SCREENEFFECT_EP2_ADVISOR_STUN )
  222. {
  223. // Set our keys
  224. pKeys->SetFloat( "duration", m_flDuration );
  225. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "episodic_stun", pKeys );
  226. g_pScreenSpaceEffects->EnableScreenSpaceEffect( "episodic_stun" );
  227. }
  228. else if ( m_nType == SCREENEFFECT_EP2_GROGGY )
  229. {
  230. // Set our keys
  231. pKeys->SetFloat( "duration", m_flDuration );
  232. pKeys->SetInt( "fadeout", 0 );
  233. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "ep2_groggy", pKeys );
  234. g_pScreenSpaceEffects->EnableScreenSpaceEffect( "ep2_groggy" );
  235. }
  236. pKeys->deleteThis();
  237. }
  238. break;
  239. // Effect turning off
  240. case 1: // FIXME: Declare
  241. if ( m_nType == SCREENEFFECT_EP1_INTRO )
  242. {
  243. // Create a keyvalue block to set these params
  244. KeyValues *pKeys = new KeyValues( "keys" );
  245. if ( pKeys == NULL )
  246. return;
  247. // Set our keys
  248. pKeys->SetFloat( "duration", m_flDuration );
  249. pKeys->SetInt( "fadeout", 1 );
  250. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "episodic_intro", pKeys );
  251. }
  252. else if ( m_nType == SCREENEFFECT_EP2_ADVISOR_STUN )
  253. {
  254. g_pScreenSpaceEffects->DisableScreenSpaceEffect( "episodic_stun" );
  255. }
  256. else if ( m_nType == SCREENEFFECT_EP2_GROGGY )
  257. {
  258. // Create a keyvalue block to set these params
  259. KeyValues *pKeys = new KeyValues( "keys" );
  260. if ( pKeys == NULL )
  261. return;
  262. // Set our keys
  263. pKeys->SetFloat( "duration", m_flDuration );
  264. pKeys->SetInt( "fadeout", 1 );
  265. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "ep2_groggy", pKeys );
  266. }
  267. break;
  268. }
  269. }