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.

151 lines
4.5 KiB

  1. //========= Copyright � 1996-2005, 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 "precache_register.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. // Precache our effects
  14. PRECACHE_REGISTER_BEGIN( GLOBAL, PrecacheEffect_CS_MuzzleFlash )
  15. PRECACHE( MATERIAL, "effects/muzzleflashX" ) //.vmt
  16. PRECACHE( MATERIAL, "sprites/muzzleflash4" ) //.vmt
  17. PRECACHE_REGISTER_END()
  18. void TE_DynamicLight( IRecipientFilter& filter, float delay,
  19. const Vector* org, int r, int g, int b, int exponent, float radius, float time, float decay, int nLightIndex = LIGHT_INDEX_TE_DYNAMIC );
  20. void CS_MuzzleFlashCallback( const CEffectData &data )
  21. {
  22. CSmartPtr<CLocalSpaceEmitter> pEmitter =
  23. CLocalSpaceEmitter::Create( "CS_MuzzleFlash", data.m_hEntity, data.m_nAttachmentIndex, 0 );
  24. if ( !pEmitter )
  25. return;
  26. // SetBBox() manually on the particle system so it doesn't have to be recalculated more than once.
  27. Vector vCenter( 0.0f, 0.0f, 0.0f );
  28. C_BaseEntity *pEnt = data.GetEntity();
  29. if ( pEnt )
  30. {
  31. vCenter = pEnt->WorldSpaceCenter();
  32. }
  33. else
  34. {
  35. IClientRenderable *pRenderable = data.GetRenderable( );
  36. if ( pRenderable )
  37. {
  38. Vector vecMins, vecMaxs;
  39. pRenderable->GetRenderBoundsWorldspace( vecMins, vecMaxs );
  40. VectorAdd( vecMins, vecMaxs, vCenter );
  41. vCenter *= 0.5f;
  42. }
  43. }
  44. Assert( pEmitter );
  45. pEmitter->GetBinding().SetBBox( vCenter - Vector( 3, 3, 3 ), vCenter + Vector( 3, 3, 3 ) );
  46. // haxors - make the clip much shorter so the alpha is not
  47. // changed based on large clip distances
  48. pEmitter->SetNearClip( 0, 5 );
  49. PMaterialHandle hFlashMaterial = pEmitter->GetPMaterial( "sprites/muzzleflash4" );
  50. for( int i=0;i<3;i++ )
  51. {
  52. SimpleParticle *pParticle = (SimpleParticle *)pEmitter->AddParticle( sizeof( SimpleParticle ),
  53. hFlashMaterial,
  54. vec3_origin );
  55. if( pParticle )
  56. {
  57. pParticle->m_flLifetime = 0.0f;
  58. pParticle->m_flDieTime = 0.08f;
  59. pParticle->m_vecVelocity = vec3_origin;
  60. pParticle->m_uchColor[0] = 255;
  61. pParticle->m_uchColor[1] = 255;
  62. pParticle->m_uchColor[2] = 255;
  63. pParticle->m_uchStartAlpha = 80;
  64. pParticle->m_uchEndAlpha = 30;
  65. pParticle->m_uchStartSize = ( 3.0 + 3.0*i ) * data.m_flScale;
  66. pParticle->m_uchEndSize = pParticle->m_uchStartSize * 0.8;
  67. pParticle->m_flRoll = random->RandomInt( 0, 3 );
  68. pParticle->m_flRollDelta = 0.0f;
  69. }
  70. }
  71. // dynamic light temporary entity for the muzzle flash
  72. CPVSFilter filter(pEmitter->GetSortOrigin());
  73. TE_DynamicLight( filter, 0.0, &(pEmitter->GetSortOrigin()), 255, 192, 64, 5, 70, 0.05, 768 );
  74. }
  75. DECLARE_CLIENT_EFFECT( CS_MuzzleFlash, CS_MuzzleFlashCallback );
  76. // 'X' shaped muzzleflash used by certain weapons
  77. void CS_MuzzleFlashXCallback( const CEffectData &data )
  78. {
  79. CSmartPtr<CLocalSpaceEmitter> pEmitter =
  80. CLocalSpaceEmitter::Create( "CS_MuzzleFlashX", data.m_hEntity, data.m_nAttachmentIndex, 0 );
  81. // SetBBox() manually on the particle system so it doesn't have to be recalculated more than once.
  82. C_BaseEntity *pEnt = data.GetEntity();
  83. if ( pEnt )
  84. {
  85. Vector vCenter = pEnt->WorldSpaceCenter();
  86. pEmitter->GetBinding().SetBBox( vCenter - Vector( 3, 3, 3 ), vCenter + Vector( 3, 3, 3 ) );
  87. }
  88. Assert( pEmitter );
  89. // haxors - make the clip much shorter so the alpha is not
  90. // changed based on large clip distances
  91. pEmitter->SetNearClip( 0, 5 );
  92. PMaterialHandle hFlashMaterial = pEmitter->GetPMaterial( "effects/muzzleflashX" );
  93. SimpleParticle *pParticle = (SimpleParticle *)pEmitter->AddParticle( sizeof( SimpleParticle ),
  94. hFlashMaterial,
  95. vec3_origin );
  96. if( pParticle )
  97. {
  98. pParticle->m_flLifetime = 0.0f;
  99. pParticle->m_flDieTime = 0.08f;
  100. pParticle->m_vecVelocity = vec3_origin;
  101. pParticle->m_uchColor[0] = 255;
  102. pParticle->m_uchColor[1] = 255;
  103. pParticle->m_uchColor[2] = 255;
  104. pParticle->m_uchStartAlpha = 130;
  105. pParticle->m_uchEndAlpha = 80;
  106. pParticle->m_uchStartSize = 6.0f * data.m_flScale * random->RandomFloat( 0.9, 1.1 );
  107. pParticle->m_uchEndSize = pParticle->m_uchStartSize * 0.8;
  108. pParticle->m_flRoll = random->RandomFloat( -0.25, 0.25 );
  109. pParticle->m_flRollDelta = 0.0f;
  110. }
  111. // dynamic light temporary entity for the muzzle flash
  112. CPVSFilter filter(pEmitter->GetSortOrigin());
  113. TE_DynamicLight( filter, 0.0, &(pEmitter->GetSortOrigin()), 255, 192, 64, 5, 70, 0.05, 768 );
  114. }
  115. DECLARE_CLIENT_EFFECT( CS_MuzzleFlash_X, CS_MuzzleFlashXCallback );