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.

268 lines
6.3 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef C_FIRE_SMOKE_H
  9. #define C_FIRE_SMOKE_H
  10. #include "particles_simple.h"
  11. #include "tempent.h"
  12. #include "glow_overlay.h"
  13. #include "view.h"
  14. #include "particle_litsmokeemitter.h"
  15. #include "tier1/utlobjectreference.h"
  16. class CFireOverlay;
  17. class C_FireSprite : public C_Sprite
  18. {
  19. DECLARE_CLASS( C_FireSprite, C_Sprite );
  20. private:
  21. virtual int DrawModel( int flags, const RenderableInstance_t &instance )
  22. {
  23. if ( m_bFadeFromAbove )
  24. {
  25. // The sprites become less visible the more you look down or up at them
  26. Vector vToPos = GetLocalOrigin() - CurrentViewOrigin();
  27. VectorNormalize( vToPos );
  28. float fUpAmount = vToPos.z;
  29. int iAlpha = 255;
  30. if ( fUpAmount < -0.75f )
  31. iAlpha = 0;
  32. else if ( fUpAmount < -0.65f )
  33. iAlpha = 255 - (int)( ( fUpAmount + 0.65f ) * 10.0f * -255.0f );
  34. else if ( fUpAmount > 0.85f )
  35. iAlpha = 0;
  36. else if ( fUpAmount > 0.75f )
  37. iAlpha = 255 - (int)( ( fUpAmount - 0.75f ) * 10.0f * 255.0f );
  38. SetColor( iAlpha, iAlpha, iAlpha );
  39. }
  40. return BaseClass::DrawModel( flags, instance );
  41. }
  42. public:
  43. Vector m_vecMoveDir;
  44. bool m_bFadeFromAbove;
  45. };
  46. class C_FireFromAboveSprite : public C_Sprite
  47. {
  48. DECLARE_CLASS( C_FireFromAboveSprite, C_Sprite );
  49. virtual int DrawModel( int flags, const RenderableInstance_t &instance )
  50. {
  51. // The sprites become more visible the more you look down or up at them
  52. Vector vToPos = GetLocalOrigin() - CurrentViewOrigin();
  53. VectorNormalize( vToPos );
  54. float fUpAmount = vToPos.z;
  55. int iAlpha = 0;
  56. if ( fUpAmount < -0.85f )
  57. iAlpha = 255;
  58. else if ( fUpAmount < -0.65f )
  59. iAlpha = (int)( ( fUpAmount + 0.65f ) * 5.0f * -255.0f );
  60. else if ( fUpAmount > 0.75f )
  61. iAlpha = 255;
  62. else if ( fUpAmount > 0.55f )
  63. iAlpha = (int)( ( fUpAmount - 0.55f ) * 5.0f * 255.0f );
  64. SetColor( iAlpha, iAlpha, iAlpha );
  65. return BaseClass::DrawModel( flags, instance );
  66. }
  67. };
  68. #define NUM_CHILD_FLAMES 4
  69. #define SMOKE_RISE_RATE 92.0f
  70. #define SMOKE_LIFETIME 2.0f
  71. #define EMBER_LIFETIME 2.0f
  72. #define FLAME_CHILD_SPREAD 64.0f
  73. #define FLAME_SOURCE_HEIGHT 128.0f
  74. #define FLAME_FROM_ABOVE_SOURCE_HEIGHT 32.0f
  75. //==================================================
  76. // C_FireSmoke
  77. //==================================================
  78. //NOTENOTE: Mirrored in dlls/fire_smoke.h
  79. #define bitsFIRESMOKE_NONE 0x00000000
  80. #define bitsFIRESMOKE_ACTIVE 0x00000001
  81. #define bitsFIRESMOKE_SMOKE 0x00000002
  82. #define bitsFIRESMOKE_SMOKE_COLLISION 0x00000004
  83. #define bitsFIRESMOKE_GLOW 0x00000008
  84. #define bitsFIRESMOKE_VISIBLE_FROM_ABOVE 0x00000010
  85. #define OVERLAY_MAX_VISIBLE_RANGE 512.0f
  86. class C_FireSmoke : public C_BaseEntity
  87. {
  88. public:
  89. DECLARE_CLIENTCLASS();
  90. DECLARE_CLASS( C_FireSmoke, C_BaseEntity );
  91. C_FireSmoke();
  92. ~C_FireSmoke();
  93. void Start( void );
  94. void StartClientOnly( void );
  95. void RemoveClientOnly( void );
  96. protected:
  97. void Update( void );
  98. void UpdateAnimation( void );
  99. void UpdateScale( void );
  100. void UpdateFlames( void );
  101. void AddFlames( void );
  102. void SpawnSmoke( void );
  103. void FindClipPlane( void );
  104. //C_BaseEntity
  105. public:
  106. virtual void OnDataChanged( DataUpdateType_t updateType );
  107. virtual bool ShouldDraw();
  108. float GetScale( void ) const { return m_flScaleRegister; }
  109. //From the server
  110. public:
  111. float m_flStartScale;
  112. float m_flScale;
  113. float m_flScaleTime;
  114. int m_nFlags;
  115. int m_nFlameModelIndex;
  116. int m_nFlameFromAboveModelIndex;
  117. //Client-side only
  118. public:
  119. float m_flScaleRegister;
  120. float m_flScaleStart;
  121. float m_flScaleEnd;
  122. float m_flScaleTimeStart;
  123. float m_flScaleTimeEnd;
  124. float m_flChildFlameSpread;
  125. VPlane m_planeClip;
  126. float m_flClipPerc;
  127. bool m_bClipTested;
  128. bool m_bFadingOut;
  129. protected:
  130. void UpdateEffects( void );
  131. //CSmartPtr<CEmberEffect> m_pEmberEmitter;
  132. CSmartPtr<CLitSmokeEmitter> m_pSmokeEmitter;
  133. C_FireSprite m_entFlames[NUM_CHILD_FLAMES];
  134. C_FireFromAboveSprite m_entFlamesFromAbove[NUM_CHILD_FLAMES];
  135. float m_entFlameScales[NUM_CHILD_FLAMES];
  136. TimedEvent m_tParticleSpawn;
  137. CFireOverlay *m_pFireOverlay;
  138. // New Particle Fire Effect
  139. CUtlReference<CNewParticleEffect> m_hEffect;
  140. private:
  141. C_FireSmoke( const C_FireSmoke & );
  142. };
  143. //Fire overlay
  144. class CFireOverlay : public CGlowOverlay
  145. {
  146. public:
  147. //Constructor
  148. explicit CFireOverlay( C_FireSmoke *owner )
  149. {
  150. m_pOwner = owner;
  151. m_flScale = 0.0f;
  152. m_nGUID = random->RandomInt( -999999, 999999 );
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Purpose: Generate a flicker value
  156. // Output : scalar value
  157. //-----------------------------------------------------------------------------
  158. float GetFlickerScale( void )
  159. {
  160. float result;
  161. float time = Helper_GetTime() + m_nGUID;
  162. result = sin( time * 1000.0f );
  163. result += 0.5f * sin( time * 2000.0f );
  164. result -= 0.5f * cos( time * 8000.0f );
  165. return result;
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose: Update the overlay
  169. //-----------------------------------------------------------------------------
  170. virtual bool Update( void )
  171. {
  172. if ( m_pOwner == NULL )
  173. return false;
  174. float scale = m_pOwner->GetScale();
  175. float dscale = scale - m_flScale;
  176. m_vPos[2] += dscale * FLAME_SOURCE_HEIGHT;
  177. m_flScale = scale;
  178. scale *= 0.75f;
  179. float flickerScale = GetFlickerScale();
  180. float newScale = scale + ( scale * flickerScale * 0.1f );
  181. m_Sprites[0].m_flHorzSize = ( newScale * 0.2f ) + ( m_Sprites[0].m_flHorzSize * 0.8f );
  182. m_Sprites[0].m_flVertSize = m_Sprites[0].m_flHorzSize * 1.5f;
  183. float cameraDistance = ( CurrentViewOrigin() - (m_pOwner->GetAbsOrigin())).Length();
  184. C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
  185. if ( local )
  186. {
  187. cameraDistance *= local->GetFOVDistanceAdjustFactor();
  188. }
  189. if ( cameraDistance > OVERLAY_MAX_VISIBLE_RANGE )
  190. cameraDistance = OVERLAY_MAX_VISIBLE_RANGE;
  191. float alpha = 1.0f - ( cameraDistance / OVERLAY_MAX_VISIBLE_RANGE );
  192. Vector newColor = m_vBaseColors[0] + ( m_vBaseColors[0] * flickerScale * 0.5f );
  193. m_Sprites[0].m_vColor = ( newColor * 0.1f ) + ( m_Sprites[0].m_vColor * 0.9f ) * alpha;
  194. return true;
  195. }
  196. public:
  197. C_FireSmoke *m_pOwner;
  198. Vector m_vBaseColors[MAX_SUN_LAYERS];
  199. float m_flScale;
  200. int m_nGUID;
  201. };
  202. #endif // C_FIRE_SMOKE_H