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.

327 lines
9.2 KiB

  1. //========= Copyright 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. if( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 80 )
  216. {
  217. return;
  218. }
  219. // Set our keys
  220. pKeys->SetFloat( "duration", m_flDuration );
  221. pKeys->SetInt( "fadeout", 0 );
  222. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "episodic_intro", pKeys );
  223. g_pScreenSpaceEffects->EnableScreenSpaceEffect( "episodic_intro" );
  224. }
  225. else if ( m_nType == SCREENEFFECT_EP2_ADVISOR_STUN )
  226. {
  227. // Set our keys
  228. pKeys->SetFloat( "duration", m_flDuration );
  229. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "episodic_stun", pKeys );
  230. g_pScreenSpaceEffects->EnableScreenSpaceEffect( "episodic_stun" );
  231. }
  232. else if ( m_nType == SCREENEFFECT_EP2_GROGGY )
  233. {
  234. if( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 80 )
  235. return;
  236. // Set our keys
  237. pKeys->SetFloat( "duration", m_flDuration );
  238. pKeys->SetInt( "fadeout", 0 );
  239. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "ep2_groggy", pKeys );
  240. g_pScreenSpaceEffects->EnableScreenSpaceEffect( "ep2_groggy" );
  241. }
  242. pKeys->deleteThis();
  243. }
  244. break;
  245. // Effect turning off
  246. case 1: // FIXME: Declare
  247. if ( m_nType == SCREENEFFECT_EP1_INTRO )
  248. {
  249. if( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 80 )
  250. {
  251. return;
  252. }
  253. // Create a keyvalue block to set these params
  254. KeyValues *pKeys = new KeyValues( "keys" );
  255. if ( pKeys == NULL )
  256. return;
  257. // Set our keys
  258. pKeys->SetFloat( "duration", m_flDuration );
  259. pKeys->SetInt( "fadeout", 1 );
  260. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "episodic_intro", pKeys );
  261. }
  262. else if ( m_nType == SCREENEFFECT_EP2_ADVISOR_STUN )
  263. {
  264. g_pScreenSpaceEffects->DisableScreenSpaceEffect( "episodic_stun" );
  265. }
  266. else if ( m_nType == SCREENEFFECT_EP2_GROGGY )
  267. {
  268. if( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() < 80 )
  269. {
  270. return;
  271. }
  272. // Create a keyvalue block to set these params
  273. KeyValues *pKeys = new KeyValues( "keys" );
  274. if ( pKeys == NULL )
  275. return;
  276. // Set our keys
  277. pKeys->SetFloat( "duration", m_flDuration );
  278. pKeys->SetInt( "fadeout", 1 );
  279. g_pScreenSpaceEffects->SetScreenSpaceEffectParams( "ep2_groggy", pKeys );
  280. }
  281. break;
  282. }
  283. }