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.

168 lines
5.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "particles_simple.h"
  14. #include "particlemgr.h"
  15. #include "c_pixel_visibility.h"
  16. #include "fx_fleck.h"
  17. #include "tier0/memdbgon.h"
  18. #define bitsPARTICLE_TRAIL_VELOCITY_DAMPEN 0x00000001 //Dampen the velocity as the particles move
  19. #define bitsPARTICLE_TRAIL_COLLIDE 0x00000002 //Do collision with simulation
  20. #define bitsPARTICLE_TRAIL_FADE 0x00000004 //Fade away
  21. #define bitsPARTICLE_TRAIL_FADE_IN 0x00000008 //Fade in
  22. class TrailParticle : public Particle
  23. {
  24. public:
  25. Vector m_vecVelocity;
  26. color32 m_color; // Particle color
  27. float m_flDieTime; // How long it lives for.
  28. float m_flLifetime; // How long it has been alive for so far.
  29. float m_flLength; // Length of the tail (in seconds!)
  30. float m_flWidth; // Width of the spark
  31. };
  32. inline void Color32ToFloat4( float colorOut[4], const color32 & colorIn )
  33. {
  34. colorOut[0] = colorIn.r * (1.0f/255.0f);
  35. colorOut[1] = colorIn.g * (1.0f/255.0f);
  36. colorOut[2] = colorIn.b * (1.0f/255.0f);
  37. colorOut[3] = colorIn.a * (1.0f/255.0f);
  38. }
  39. inline void FloatToColor32( color32 &out, float r, float g, float b, float a )
  40. {
  41. out.r = r * 255;
  42. out.g = g * 255;
  43. out.b = b * 255;
  44. out.a = a * 255;
  45. }
  46. inline void Float4ToColor32( color32 &out, float colorIn[4] )
  47. {
  48. out.r = colorIn[0] * 255;
  49. out.g = colorIn[1] * 255;
  50. out.b = colorIn[2] * 255;
  51. out.a = colorIn[3] * 255;
  52. }
  53. inline void Color32Init( color32 &out, int r, int g, int b, int a )
  54. {
  55. out.r = r;
  56. out.g = g;
  57. out.b = b;
  58. out.a = a;
  59. }
  60. //
  61. // CTrailParticles
  62. //
  63. class CTrailParticles : public CSimpleEmitter
  64. {
  65. DECLARE_CLASS( CTrailParticles, CSimpleEmitter );
  66. public:
  67. explicit CTrailParticles( const char *pDebugName );
  68. static CTrailParticles *Create( const char *pDebugName ) { return new CTrailParticles( pDebugName ); }
  69. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  70. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  71. //Setup for point emission
  72. virtual void Setup( const Vector &origin, const Vector *direction, float angularSpread, float minSpeed, float maxSpeed, float gravity, float dampen, int flags, bool bNotCollideable = false );
  73. void SetFlag( int flags ) { m_fFlags |= flags; }
  74. void SetVelocityDampen( float dampen ) { m_flVelocityDampen = dampen; }
  75. void SetGravity( float gravity ) { m_ParticleCollision.SetGravity( gravity ); }
  76. void SetCollisionDamped( float dampen ) { m_ParticleCollision.SetCollisionDampen( dampen ); }
  77. void SetAngularCollisionDampen( float dampen ) { m_ParticleCollision.SetAngularCollisionDampen( dampen ); }
  78. CParticleCollision m_ParticleCollision;
  79. protected:
  80. int m_fFlags;
  81. float m_flVelocityDampen;
  82. private:
  83. CTrailParticles( const CTrailParticles & ); // not defined, not accessible
  84. };
  85. //
  86. // Sphere trails
  87. //
  88. class CSphereTrails : public CSimpleEmitter
  89. {
  90. DECLARE_CLASS( CSphereTrails, CSimpleEmitter );
  91. public:
  92. CSphereTrails( const char *pDebugName, const Vector &origin, float innerRadius, float outerRadius, float speed, int entityIndex, int attachment );
  93. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  94. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  95. virtual void Update( float flTimeDelta );
  96. virtual void StartRender();
  97. void AddStreaks( float count );
  98. Vector m_particleOrigin;
  99. float m_life;
  100. float m_outerRadius;
  101. float m_innerRadius;
  102. float m_effectSpeed;
  103. float m_streakSpeed;
  104. float m_count;
  105. float m_growth;
  106. int m_entityIndex;
  107. int m_attachment;
  108. PMaterialHandle m_hMaterial;
  109. Vector m_boneOrigin;
  110. float m_dieTime;
  111. private:
  112. CSphereTrails( const CSphereTrails & ); // not defined, not accessible
  113. };
  114. // Simple glow emitter won't draw any of it's particles until/unless the pixel visibility test succeeds
  115. class CSimpleGlowEmitter : public CSimpleEmitter
  116. {
  117. DECLARE_CLASS( CSimpleGlowEmitter, CSimpleEmitter );
  118. public:
  119. CSimpleGlowEmitter( const char *pDebugName, const Vector &sortOrigin, float flDeathTime );
  120. static CSimpleGlowEmitter *Create( const char *pDebugName, const Vector &sortOrigin, float flDeathTime );
  121. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  122. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  123. protected:
  124. bool WasTestedInView( unsigned char viewMask );
  125. bool IsVisibleInView( unsigned char viewMask );
  126. void SetTestedInView( unsigned char viewMask, bool bTested );
  127. void SetVisibleInView( unsigned char viewMask, bool bVisible );
  128. unsigned char CurrentViewMask() const;
  129. float m_flDeathTime; // How long it has been alive for so far.
  130. float m_startTime;
  131. pixelvis_handle_t m_queryHandle;
  132. private:
  133. unsigned char m_wasTested;
  134. unsigned char m_isVisible;
  135. private:
  136. CSimpleGlowEmitter( const CSimpleGlowEmitter & ); // not defined, not accessible
  137. };
  138. #include "tier0/memdbgoff.h"