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.

169 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "particlemgr.h"
  9. #include "particle_prototype.h"
  10. #include "particle_util.h"
  11. #include "c_te_particlesystem.h"
  12. #include "fx.h"
  13. #include "fx_quad.h"
  14. #include "c_te_effect_dispatch.h"
  15. #include "view.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. #define THUMPER_DUST_LIFETIME 2.0f
  19. #define THUMPER_MAX_PARTICLES 24
  20. extern IPhysicsSurfaceProps *physprops;
  21. class ThumperDustEmitter : public CSimpleEmitter
  22. {
  23. public:
  24. ThumperDustEmitter( const char *pDebugName ) : CSimpleEmitter( pDebugName ) {}
  25. static ThumperDustEmitter *Create( const char *pDebugName )
  26. {
  27. return new ThumperDustEmitter( pDebugName );
  28. }
  29. void UpdateVelocity( SimpleParticle *pParticle, float timeDelta )
  30. {
  31. // Float up when lifetime is half gone.
  32. pParticle->m_vecVelocity[2] -= ( 8.0f * timeDelta );
  33. // FIXME: optimize this....
  34. pParticle->m_vecVelocity *= ExponentialDecay( 0.9, 0.03, timeDelta );
  35. }
  36. virtual float UpdateRoll( SimpleParticle *pParticle, float timeDelta )
  37. {
  38. pParticle->m_flRoll += pParticle->m_flRollDelta * timeDelta;
  39. pParticle->m_flRollDelta += pParticle->m_flRollDelta * ( timeDelta * -4.0f );
  40. //Cap the minimum roll
  41. if ( fabs( pParticle->m_flRollDelta ) < 0.25f )
  42. {
  43. pParticle->m_flRollDelta = ( pParticle->m_flRollDelta > 0.0f ) ? 0.25f : -0.25f;
  44. }
  45. return pParticle->m_flRoll;
  46. }
  47. virtual float UpdateAlpha( const SimpleParticle *pParticle )
  48. {
  49. return (pParticle->m_uchStartAlpha/255.0f) + ( (float)(pParticle->m_uchEndAlpha/255.0f) - (float)(pParticle->m_uchStartAlpha/255.0f) ) * (pParticle->m_flLifetime / pParticle->m_flDieTime);
  50. }
  51. private:
  52. ThumperDustEmitter( const ThumperDustEmitter & );
  53. };
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. // Input : bNewEntity - whether or not to start a new entity
  57. //-----------------------------------------------------------------------------
  58. void FX_ThumperDust( const CEffectData &data )
  59. {
  60. Vector vecDustColor;
  61. vecDustColor.x = 0.85f;
  62. vecDustColor.y = 0.75f;
  63. vecDustColor.z = 0.52f;
  64. CSmartPtr<ThumperDustEmitter> pSimple = ThumperDustEmitter::Create( "thumperdust" );
  65. C_BaseEntity *pEnt = C_BaseEntity::Instance( data.m_hEntity );
  66. if ( pEnt )
  67. {
  68. Vector vWorldMins, vWorldMaxs;
  69. float scale = pEnt->CollisionProp()->BoundingRadius();
  70. vWorldMins[0] = data.m_vOrigin[0] - scale;
  71. vWorldMins[1] = data.m_vOrigin[1] - scale;
  72. vWorldMins[2] = data.m_vOrigin[2] - scale;
  73. vWorldMaxs[0] = data.m_vOrigin[0] + scale;
  74. vWorldMaxs[1] = data.m_vOrigin[1] + scale;
  75. vWorldMaxs[2] = data.m_vOrigin[2] + scale;
  76. pSimple->GetBinding().SetBBox( vWorldMins, vWorldMaxs, true );
  77. }
  78. pSimple->SetSortOrigin( data.m_vOrigin );
  79. pSimple->SetNearClip( 32, 64 );
  80. SimpleParticle *pParticle = NULL;
  81. Vector offset;
  82. //int numPuffs = IsXbox() ? THUMPER_MAX_PARTICLES/2 : THUMPER_MAX_PARTICLES;
  83. int numPuffs = THUMPER_MAX_PARTICLES;
  84. float flYaw = 0;
  85. float flIncr = (2*M_PI) / (float) numPuffs; // Radians
  86. Vector forward;
  87. Vector vecColor;
  88. int i = 0;
  89. float flScale = MIN( data.m_flScale, 255 );
  90. // Setup the color for these particles
  91. engine->ComputeLighting( data.m_vOrigin, NULL, true, vecColor );
  92. VectorLerp( vecColor, vecDustColor, 0.5, vecColor );
  93. vecColor *= 255;
  94. for ( i = 0; i < numPuffs; i++ )
  95. {
  96. flYaw += flIncr;
  97. SinCos( flYaw, &forward.y, &forward.x );
  98. forward.z = 0.0f;
  99. offset = ( RandomVector( -4.0f, 4.0f ) + data.m_vOrigin ) + ( forward * 128.0f );
  100. pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof(SimpleParticle), g_Mat_DustPuff[random->RandomInt(0,1)], offset );
  101. if ( pParticle != NULL )
  102. {
  103. pParticle->m_flLifetime = 0.0f;
  104. pParticle->m_flDieTime = 1.5f;
  105. Vector dir = (offset - data.m_vOrigin);
  106. float length = dir.Length();
  107. VectorNormalize( dir );
  108. pParticle->m_vecVelocity = dir * ( length * 2.0f );
  109. pParticle->m_vecVelocity[2] = data.m_flScale / 3;
  110. pParticle->m_uchColor[0] = vecColor[0];
  111. pParticle->m_uchColor[1] = vecColor[1];
  112. pParticle->m_uchColor[2] = vecColor[2];
  113. pParticle->m_uchStartAlpha = random->RandomInt( 64, 96 );
  114. pParticle->m_uchEndAlpha = 0;
  115. pParticle->m_uchStartSize = flScale * 0.25f;
  116. pParticle->m_uchEndSize = flScale * 0.5f;
  117. pParticle->m_flRoll = random->RandomInt( 0, 360 );
  118. pParticle->m_flRollDelta = random->RandomFloat( -6.0f, 6.0f );
  119. }
  120. }
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. // Input : &data -
  125. //-----------------------------------------------------------------------------
  126. void ThumperDustCallback( const CEffectData &data )
  127. {
  128. FX_ThumperDust( data );
  129. }
  130. DECLARE_CLIENT_EFFECT( "ThumperDust", ThumperDustCallback );