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.

210 lines
6.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef C_EFFECTS_H
  7. #define C_EFFECTS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cbase.h"
  12. #include "precipitation_shared.h"
  13. // Draw rain effects.
  14. void DrawPrecipitation();
  15. //-----------------------------------------------------------------------------
  16. // Precipitation particle type
  17. //-----------------------------------------------------------------------------
  18. class CPrecipitationParticle
  19. {
  20. public:
  21. Vector m_Pos;
  22. Vector m_Velocity;
  23. float m_SpawnTime; // Note: Tweak with this to change lifetime
  24. float m_Mass;
  25. float m_Ramp;
  26. float m_flMaxLifetime;
  27. int m_nSplitScreenPlayerSlot;
  28. };
  29. class CClient_Precipitation;
  30. static CUtlVector<CClient_Precipitation*> g_Precipitations;
  31. //===========
  32. // Snow fall
  33. //===========
  34. class CSnowFallManager;
  35. static CSnowFallManager *s_pSnowFallMgr[ MAX_SPLITSCREEN_PLAYERS ];
  36. bool SnowFallManagerCreate( CClient_Precipitation *pSnowEntity );
  37. void SnowFallManagerDestroy( void );
  38. class AshDebrisEffect : public CSimpleEmitter
  39. {
  40. public:
  41. explicit AshDebrisEffect( const char *pDebugName ) : CSimpleEmitter( pDebugName ) {}
  42. static AshDebrisEffect* Create( const char *pDebugName );
  43. virtual float UpdateAlpha( const SimpleParticle *pParticle );
  44. virtual float UpdateRoll( SimpleParticle *pParticle, float timeDelta );
  45. private:
  46. AshDebrisEffect( const AshDebrisEffect & );
  47. };
  48. //-----------------------------------------------------------------------------
  49. // Precipitation blocker entity
  50. //-----------------------------------------------------------------------------
  51. class C_PrecipitationBlocker : public C_BaseEntity
  52. {
  53. public:
  54. DECLARE_CLASS( C_PrecipitationBlocker, C_BaseEntity );
  55. DECLARE_CLIENTCLASS();
  56. C_PrecipitationBlocker();
  57. virtual ~C_PrecipitationBlocker();
  58. };
  59. //-----------------------------------------------------------------------------
  60. // Precipitation base entity
  61. //-----------------------------------------------------------------------------
  62. class CClient_Precipitation : public C_BaseEntity
  63. {
  64. class CPrecipitationEffect;
  65. friend class CClient_Precipitation::CPrecipitationEffect;
  66. public:
  67. DECLARE_CLASS( CClient_Precipitation, C_BaseEntity );
  68. DECLARE_CLIENTCLASS();
  69. CClient_Precipitation();
  70. virtual ~CClient_Precipitation();
  71. // Inherited from C_BaseEntity
  72. virtual void Precache( );
  73. virtual RenderableTranslucencyType_t ComputeTranslucencyType() { return RENDERABLE_IS_TRANSLUCENT; }
  74. void Render();
  75. // Computes where we're gonna emit
  76. bool ComputeEmissionArea( Vector& origin, Vector2D& size, C_BaseCombatCharacter *pCharacter );
  77. private:
  78. // Creates a single particle
  79. CPrecipitationParticle* CreateParticle();
  80. virtual void OnDataChanged( DataUpdateType_t updateType );
  81. virtual void ClientThink();
  82. void Simulate( float dt );
  83. // Renders the particle
  84. void RenderParticle( CPrecipitationParticle* pParticle, CMeshBuilder &mb );
  85. void CreateWaterSplashes();
  86. // Emits the actual particles
  87. void EmitParticles( float fTimeDelta );
  88. // Gets the tracer width and speed
  89. float GetWidth() const;
  90. float GetLength() const;
  91. float GetSpeed() const;
  92. // Gets the remaining lifetime of the particle
  93. float GetRemainingLifetime( CPrecipitationParticle* pParticle ) const;
  94. // Computes the wind vector
  95. static void ComputeWindVector( );
  96. // simulation methods
  97. bool SimulateRain( CPrecipitationParticle* pParticle, float dt );
  98. bool SimulateSnow( CPrecipitationParticle* pParticle, float dt );
  99. void CreateParticlePrecip( void );
  100. void InitializeParticlePrecip( void );
  101. void DispatchOuterParticlePrecip( int nSlot, C_BasePlayer *pPlayer, Vector vForward );
  102. void DispatchInnerParticlePrecip( int nSlot, C_BasePlayer *pPlayer, Vector vForward );
  103. void DestroyOuterParticlePrecip( int nSlot );
  104. void DestroyInnerParticlePrecip( int nSlot );
  105. void UpdateParticlePrecip( C_BasePlayer *pPlayer, int nSlot );
  106. float GetDensity() { return m_flDensity; }
  107. private:
  108. void CreateAshParticle( void );
  109. void CreateRainOrSnowParticle( const Vector &vSpawnPosition, const Vector &vEndPosition, const Vector &vVelocity ); // TERROR: adding end pos for lifetime calcs
  110. // Information helpful in creating and rendering particles
  111. IMaterial *m_MatHandle; // material used
  112. float m_Color[4]; // precip color
  113. float m_Lifetime; // Precip lifetime
  114. float m_InitialRamp; // Initial ramp value
  115. float m_Speed; // Precip speed
  116. float m_Width; // Tracer width
  117. float m_Remainder; // particles we should render next time
  118. PrecipitationType_t m_nPrecipType; // Precip type
  119. float m_flHalfScreenWidth; // Precalculated each frame.
  120. float m_flDensity;
  121. #ifdef INFESTED_DLL
  122. int m_nSnowDustAmount;
  123. #endif
  124. // Some state used in rendering and simulation
  125. // Used to modify the rain density and wind from the console
  126. static ConVar s_raindensity;
  127. static ConVar s_rainwidth;
  128. static ConVar s_rainlength;
  129. static ConVar s_rainspeed;
  130. static Vector s_WindVector; // Stores the wind speed vector
  131. CUtlLinkedList<CPrecipitationParticle> m_Particles;
  132. CUtlVector<Vector> m_Splashes;
  133. struct AshSplit_t
  134. {
  135. AshSplit_t() : m_bActiveAshEmitter( false ), m_vAshSpawnOrigin( 0, 0, 0 ), m_iAshCount( 0 )
  136. {
  137. }
  138. CSmartPtr<AshDebrisEffect> m_pAshEmitter;
  139. TimedEvent m_tAshParticleTimer;
  140. TimedEvent m_tAshParticleTraceTimer;
  141. bool m_bActiveAshEmitter;
  142. Vector m_vAshSpawnOrigin;
  143. int m_iAshCount;
  144. };
  145. protected:
  146. AshSplit_t m_Ash[ MAX_SPLITSCREEN_PLAYERS ];
  147. float m_flParticleInnerDist; //The distance at which to start drawing the inner system
  148. char *m_pParticleInnerNearDef; //Name of the first inner system
  149. char *m_pParticleInnerFarDef; //Name of the second inner system
  150. char *m_pParticleOuterDef; //Name of the outer system
  151. HPARTICLEFFECT m_pParticlePrecipInnerNear[ MAX_SPLITSCREEN_PLAYERS ];
  152. HPARTICLEFFECT m_pParticlePrecipInnerFar[ MAX_SPLITSCREEN_PLAYERS ];
  153. HPARTICLEFFECT m_pParticlePrecipOuter[ MAX_SPLITSCREEN_PLAYERS ];
  154. TimedEvent m_tParticlePrecipTraceTimer[ MAX_SPLITSCREEN_PLAYERS ];
  155. bool m_bActiveParticlePrecipEmitter[ MAX_SPLITSCREEN_PLAYERS ];
  156. bool m_bParticlePrecipInitialized;
  157. private:
  158. CClient_Precipitation( const CClient_Precipitation & ); // not defined, not accessible
  159. };
  160. #endif // C_EFFECTS_H