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.

134 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "particles_simple.h"
  8. #include "particles_localspace.h"
  9. #include "c_te_effect_dispatch.h"
  10. #include "clienteffectprecachesystem.h"
  11. #include "fx.h"
  12. #include "r_efx.h"
  13. #include "dlight.h"
  14. #include "dod_shareddefs.h"
  15. // Precache our effects
  16. CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffect_DOD_MuzzleFlash )
  17. CLIENTEFFECT_MATERIAL( "sprites/effects/muzzleflash1" )
  18. CLIENTEFFECT_MATERIAL( "sprites/effects/muzzleflash2" )
  19. CLIENTEFFECT_REGISTER_END()
  20. ConVar cl_muzzleflash_dlight_1st( "cl_muzzleflash_dlight_1st", "1" );
  21. void TE_DynamicLight( IRecipientFilter& filter, float delay,
  22. const Vector* org, int r, int g, int b, int exponent, float radius, float time, float decay, int nLightIndex = LIGHT_INDEX_TE_DYNAMIC );
  23. void DOD_MuzzleFlashCallback( const CEffectData &data )
  24. {
  25. CSmartPtr<CLocalSpaceEmitter> pEmitter =
  26. CLocalSpaceEmitter::Create( "DOD_MuzzleFlash", data.m_hEntity, data.m_nAttachmentIndex, 0 );
  27. if ( !pEmitter )
  28. return;
  29. // SetBBox() manually on the particle system so it doesn't have to be recalculated more than once.
  30. Vector vCenter( 0.0f, 0.0f, 0.0f );
  31. C_BaseEntity *pEnt = data.GetEntity();
  32. if ( pEnt )
  33. {
  34. vCenter = pEnt->WorldSpaceCenter();
  35. }
  36. else
  37. {
  38. IClientRenderable *pRenderable = data.GetRenderable( );
  39. if ( pRenderable )
  40. {
  41. Vector vecMins, vecMaxs;
  42. pRenderable->GetRenderBoundsWorldspace( vecMins, vecMaxs );
  43. VectorAdd( vecMins, vecMaxs, vCenter );
  44. vCenter *= 0.5f;
  45. }
  46. }
  47. Assert( pEmitter );
  48. pEmitter->GetBinding().SetBBox( vCenter - Vector( 10, 10, 10 ), vCenter + Vector( 10, 10, 10 ) );
  49. // haxors - make the clip much shorter so the alpha is not
  50. // changed based on large clip distances
  51. pEmitter->SetNearClip( 0, 5 );
  52. Vector vFlashOffset = vec3_origin;
  53. Vector vForward(1,0,0);
  54. int i;
  55. if( data.m_nHitBox == DOD_MUZZLEFLASH_MG ) //Machine gun
  56. {
  57. SimpleParticle *pParticle = (SimpleParticle *)pEmitter->AddParticle( sizeof( SimpleParticle ),
  58. g_Mat_SMG_Muzzleflash[0],
  59. vFlashOffset );
  60. Assert( pParticle );
  61. if( pParticle )
  62. {
  63. pParticle->m_flLifetime = 0.0f;
  64. pParticle->m_flDieTime = 0.1f;
  65. pParticle->m_vecVelocity = Vector(0,0,0);
  66. pParticle->m_uchColor[0] = 255;
  67. pParticle->m_uchColor[1] = 255;
  68. pParticle->m_uchColor[2] = 255;
  69. pParticle->m_uchStartAlpha = 210.0f;
  70. pParticle->m_uchEndAlpha = 0;
  71. pParticle->m_uchStartSize = random->RandomFloat( 120, 130 ) * data.m_flMagnitude;
  72. pParticle->m_uchEndSize = pParticle->m_uchStartSize;
  73. pParticle->m_flRoll = 0;
  74. pParticle->m_flRollDelta = 0.0f;
  75. }
  76. }
  77. else
  78. {
  79. for( i=0;i<3;i++ )
  80. {
  81. //move the three sprites around
  82. vFlashOffset = vForward * ( (2-i)*6 + 10 );
  83. SimpleParticle *pParticle = (SimpleParticle *)pEmitter->AddParticle( sizeof( SimpleParticle ),
  84. g_Mat_SMG_Muzzleflash[1],
  85. vFlashOffset );
  86. Assert( pParticle );
  87. if( pParticle )
  88. {
  89. pParticle->m_flLifetime = 0.0f;
  90. pParticle->m_flDieTime = 0.1f;
  91. pParticle->m_vecVelocity = vec3_origin;
  92. pParticle->m_uchColor[0] = 255;
  93. pParticle->m_uchColor[1] = 255;
  94. pParticle->m_uchColor[2] = 255;
  95. pParticle->m_uchStartAlpha = 100.0f;
  96. pParticle->m_uchEndAlpha = 30;
  97. pParticle->m_uchStartSize = ( 15.0 + 20.0*i ) * data.m_flMagnitude;
  98. pParticle->m_uchEndSize = pParticle->m_uchStartSize;
  99. pParticle->m_flRoll = random->RandomInt( 0, 360 );
  100. pParticle->m_flRollDelta = 0.0f;
  101. }
  102. }
  103. }
  104. // dynamic light temporary entity for the muzzle flash
  105. if ( cl_muzzleflash_dlight_1st.GetBool() )
  106. {
  107. CPVSFilter filter(pEmitter->GetSortOrigin());
  108. TE_DynamicLight( filter, 0.0, &(pEmitter->GetSortOrigin()), 255, 192, 64, 5, 70, 0.05, 768 );
  109. }
  110. }
  111. DECLARE_CLIENT_EFFECT( "DOD_MuzzleFlash", DOD_MuzzleFlashCallback );