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.

219 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "fx.h"
  9. #include "particlemgr.h"
  10. #include "particle_prototype.h"
  11. #include "particle_util.h"
  12. #include "c_te_particlesystem.h"
  13. #include "particles_ez.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. #define DUST_STARTSIZE 16
  17. #define DUST_ENDSIZE 48
  18. #define DUST_RADIUS 32.0f
  19. #define DUST_STARTALPHA 0.3f
  20. #define DUST_ENDALPHA 0.0f
  21. #define DUST_LIFETIME 2.0f
  22. static Vector g_AntlionDustColor( 0.3f, 0.25f, 0.2f );
  23. extern IPhysicsSurfaceProps *physprops;
  24. class CAntlionDustEmitter : public CSimpleEmitter
  25. {
  26. public:
  27. static CAntlionDustEmitter *Create( const char *debugname )
  28. {
  29. return new CAntlionDustEmitter( debugname );
  30. }
  31. void UpdateVelocity( SimpleParticle *pParticle, float timeDelta )
  32. {
  33. //FIXME: Incorrect
  34. pParticle->m_vecVelocity *= 0.9f;
  35. }
  36. private:
  37. CAntlionDustEmitter( const char *pDebugName ) : CSimpleEmitter( pDebugName ) {}
  38. CAntlionDustEmitter( const CAntlionDustEmitter & ); // not defined, not accessible
  39. };
  40. //==================================================
  41. // C_TEAntlionDust
  42. //==================================================
  43. class C_TEAntlionDust: public C_TEParticleSystem
  44. {
  45. public:
  46. DECLARE_CLASS( C_TEAntlionDust, C_TEParticleSystem );
  47. DECLARE_CLIENTCLASS();
  48. C_TEAntlionDust();
  49. virtual ~C_TEAntlionDust();
  50. //C_BaseEntity
  51. public:
  52. virtual void PostDataUpdate( DataUpdateType_t updateType );
  53. virtual bool ShouldDraw() { return true; }
  54. //IParticleEffect
  55. public:
  56. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  57. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  58. public:
  59. PMaterialHandle m_MaterialHandle;
  60. Vector m_vecOrigin;
  61. QAngle m_vecAngles;
  62. bool m_bBlockedSpawner;
  63. protected:
  64. void GetDustColor( Vector &color );
  65. };
  66. // Expose to the particle app.
  67. EXPOSE_PROTOTYPE_EFFECT( AntlionDust, C_TEAntlionDust );
  68. IMPLEMENT_CLIENTCLASS_EVENT_DT( C_TEAntlionDust, DT_TEAntlionDust, CTEAntlionDust )
  69. RecvPropVector(RECVINFO( m_vecOrigin )),
  70. RecvPropVector(RECVINFO( m_vecAngles )),
  71. RecvPropBool(RECVINFO( m_bBlockedSpawner )),
  72. END_RECV_TABLE()
  73. //==================================================
  74. // C_TEAntlionDust
  75. //==================================================
  76. C_TEAntlionDust::C_TEAntlionDust()
  77. {
  78. m_MaterialHandle = INVALID_MATERIAL_HANDLE;
  79. m_vecOrigin.Init();
  80. m_vecAngles.Init();
  81. m_bBlockedSpawner = false;
  82. }
  83. C_TEAntlionDust::~C_TEAntlionDust()
  84. {
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. // Input : bNewEntity - whether or not to start a new entity
  89. //-----------------------------------------------------------------------------
  90. void C_TEAntlionDust::PostDataUpdate( DataUpdateType_t updateType )
  91. {
  92. // This style of creating dust emitters is now deprecated; we use the simple particle singleton exclusively.
  93. /*
  94. CSmartPtr<CAntlionDustEmitter> pDustEmitter = CAntlionDustEmitter::Create( "TEAntlionDust" );
  95. Assert( pDustEmitter );
  96. if ( pDustEmitter == NULL )
  97. return;
  98. pDustEmitter->SetSortOrigin( m_vecOrigin );
  99. pDustEmitter->SetNearClip( 32, 64 );
  100. pDustEmitter->GetBinding().SetBBox( m_vecOrigin - Vector( 32, 32, 32 ), m_vecOrigin + Vector( 32, 32, 32 ) );
  101. */
  102. Vector offset;
  103. Vector vecColor;
  104. GetDustColor( vecColor );
  105. int iParticleCount = 16;
  106. if ( m_bBlockedSpawner == true )
  107. {
  108. iParticleCount = 8;
  109. }
  110. //Spawn the dust
  111. SimpleParticle particle;
  112. for ( int i = 0; i < iParticleCount; i++ )
  113. {
  114. //Offset this dust puff's origin
  115. offset[0] = random->RandomFloat( -DUST_RADIUS, DUST_RADIUS );
  116. offset[1] = random->RandomFloat( -DUST_RADIUS, DUST_RADIUS );
  117. offset[2] = random->RandomFloat( -16, 8 );
  118. offset += m_vecOrigin;
  119. particle.m_Pos = offset;
  120. particle.m_flDieTime = random->RandomFloat( 0.75f, 1.25f );
  121. particle.m_flLifetime = 0.0f;
  122. Vector dir = particle.m_Pos - m_vecOrigin;
  123. particle.m_vecVelocity = dir * random->RandomFloat( 0.5f, 1.0f );
  124. dir.z = fabs(dir.z);
  125. float colorRamp = random->RandomFloat( 0.5f, 1.0f );
  126. Vector color = vecColor*colorRamp;
  127. color[0] = clamp( color[0], 0.0f, 1.0f );
  128. color[1] = clamp( color[1], 0.0f, 1.0f );
  129. color[2] = clamp( color[2], 0.0f, 1.0f );
  130. color *= 255;
  131. particle.m_uchColor[0] = color[0];
  132. particle.m_uchColor[1] = color[1];
  133. particle.m_uchColor[2] = color[2];
  134. particle.m_uchStartAlpha= random->RandomFloat( 64, 128 );
  135. particle.m_uchEndAlpha = 0;
  136. particle.m_uchStartSize = random->RandomInt( 16, 32 );
  137. particle.m_uchEndSize = particle.m_uchStartSize * 3;
  138. particle.m_flRoll = random->RandomInt( 0, 360 );
  139. particle.m_flRollDelta = random->RandomFloat( -0.2f, 0.2f );
  140. // Though it appears there are two particle handle entries in g_Mat_DustPuff, in fact
  141. // only the one present at index 0 actually draws. Trying to spawn a particle with
  142. // the other material will give you no particle at all. Therefore while instead of this:
  143. // AddSimpleParticle( &particle, g_Mat_DustPuff[random->RandomInt(0,1) );
  144. // we have to do this:
  145. AddSimpleParticle( &particle, g_Mat_DustPuff[0] );
  146. }
  147. }
  148. void GetColorForSurface( trace_t *trace, Vector *color );
  149. //-----------------------------------------------------------------------------
  150. // Purpose:
  151. // Input : &color -
  152. //-----------------------------------------------------------------------------
  153. void C_TEAntlionDust::GetDustColor( Vector &color )
  154. {
  155. trace_t tr;
  156. UTIL_TraceLine( m_vecOrigin+Vector(0,0,1), m_vecOrigin+Vector(0,0,-32),
  157. MASK_SOLID_BRUSHONLY, NULL, COLLISION_GROUP_NONE, &tr );
  158. if ( tr.fraction < 1.0f )
  159. {
  160. GetColorForSurface( &tr, &color );
  161. }
  162. else
  163. {
  164. //Fill in a fallback
  165. color = g_AntlionDustColor;
  166. }
  167. }
  168. void C_TEAntlionDust::RenderParticles( CParticleRenderIterator *pIterator )
  169. {
  170. }
  171. void C_TEAntlionDust::SimulateParticles( CParticleSimulateIterator *pIterator )
  172. {
  173. }