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.

162 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "particles_ez.h"
  8. #include "igamesystem.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. // Singletons for each type of particle system.
  12. // 0 = world, 1 = skybox
  13. static CSmartPtr<CSimpleEmitter> g_pSimpleSingleton[2];
  14. static CSmartPtr<CEmberEffect> g_pEmberSingleton[2];
  15. static CSmartPtr<CFireSmokeEffect> g_pFireSmokeSingleton[2];
  16. static CSmartPtr<CFireParticle> g_pFireSingleton[2];
  17. class CEZParticleInit : public CAutoGameSystem
  18. {
  19. public:
  20. CEZParticleInit() : CAutoGameSystem( "CEZParticleInit" )
  21. {
  22. }
  23. template< class T >
  24. CSmartPtr<T> InitSingleton( CSmartPtr<T> pEmitter )
  25. {
  26. if ( !pEmitter )
  27. {
  28. Error( "InitSingleton: pEmitter is NULL" );
  29. }
  30. pEmitter->GetBinding().SetDrawThruLeafSystem( false ); // Draw in DrawSingletons instead.
  31. pEmitter->SetSortOrigin( Vector( 0, 0, 0 ) );
  32. // Since we draw manually in DrawSingletons, we don't care about
  33. // the bbox, so don't waste cycles inserting it into the leaf system
  34. // when it's not going to draw through that anyway.
  35. // (TODO: SetDrawThruLeafSystem(false) should trigger this automatically
  36. // in CParticleMgr).
  37. pEmitter->GetBinding().SetBBox( Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
  38. return pEmitter;
  39. }
  40. virtual void LevelInitPreEntity()
  41. {
  42. g_pSimpleSingleton[0] = InitSingleton( CSimpleEmitter::Create( "Simple Particle Singleton" ) );
  43. g_pSimpleSingleton[1] = InitSingleton( CSimpleEmitter::Create( "Simple Particle Singleton [sky]" ) );
  44. g_pEmberSingleton[0] = InitSingleton( CEmberEffect::Create( "Ember Particle Singleton" ) );
  45. g_pEmberSingleton[1] = InitSingleton( CEmberEffect::Create( "Ember Particle Singleton [sky]" ) );
  46. g_pFireSmokeSingleton[0] = InitSingleton( CFireSmokeEffect::Create( "Fire Smoke Particle Singleton" ) );
  47. g_pFireSmokeSingleton[1] = InitSingleton( CFireSmokeEffect::Create( "Fire Smoke Particle Singleton [sky]" ) );
  48. g_pFireSingleton[0] = InitSingleton( CFireParticle::Create( "Fire Particle Singleton" ) );
  49. g_pFireSingleton[1] = InitSingleton( CFireParticle::Create( "Fire Particle Singleton [sky]" ) );
  50. }
  51. virtual void LevelShutdownPreEntity()
  52. {
  53. g_pSimpleSingleton[0] = g_pSimpleSingleton[1] = NULL;
  54. g_pEmberSingleton[0] = g_pEmberSingleton[1] = NULL;
  55. g_pFireSmokeSingleton[0] = g_pFireSmokeSingleton[1] = NULL;
  56. g_pFireSingleton[0] = g_pFireSingleton[1] = NULL;
  57. }
  58. };
  59. static CEZParticleInit g_EZParticleInit;
  60. template<class T>
  61. inline void CopyParticle( const T *pSrc, T *pDest )
  62. {
  63. if ( pDest )
  64. {
  65. // Copy the particle, but don't screw up the linked list it's in.
  66. Particle *pPrev = pDest->m_pPrev;
  67. Particle *pNext = pDest->m_pNext;
  68. PMaterialHandle pSubTexture = pDest->m_pSubTexture;
  69. *pDest = *pSrc;
  70. pDest->m_pPrev = pPrev;
  71. pDest->m_pNext = pNext;
  72. pDest->m_pSubTexture = pSubTexture;
  73. }
  74. }
  75. void AddSimpleParticle( const SimpleParticle *pParticle, PMaterialHandle hMaterial, bool bInSkybox )
  76. {
  77. if ( g_pSimpleSingleton[bInSkybox].IsValid() )
  78. {
  79. SimpleParticle *pNew = g_pSimpleSingleton[bInSkybox]->AddSimpleParticle( hMaterial, pParticle->m_Pos );
  80. CopyParticle( pParticle, pNew );
  81. }
  82. }
  83. void AddEmberParticle( const SimpleParticle *pParticle, PMaterialHandle hMaterial, bool bInSkybox )
  84. {
  85. if ( g_pEmberSingleton[bInSkybox].IsValid() )
  86. {
  87. SimpleParticle *pNew = g_pEmberSingleton[bInSkybox]->AddSimpleParticle( hMaterial, pParticle->m_Pos );
  88. CopyParticle( pParticle, pNew );
  89. }
  90. }
  91. void AddFireSmokeParticle( const SimpleParticle *pParticle, PMaterialHandle hMaterial, bool bInSkybox )
  92. {
  93. if ( g_pFireSmokeSingleton[bInSkybox].IsValid() )
  94. {
  95. SimpleParticle *pNew = g_pFireSmokeSingleton[bInSkybox]->AddSimpleParticle( hMaterial, pParticle->m_Pos );
  96. CopyParticle( pParticle, pNew );
  97. }
  98. }
  99. void AddFireParticle( const SimpleParticle *pParticle, PMaterialHandle hMaterial, bool bInSkybox )
  100. {
  101. if ( g_pFireSingleton[bInSkybox].IsValid() )
  102. {
  103. SimpleParticle *pNew = g_pFireSingleton[bInSkybox]->AddSimpleParticle( hMaterial, pParticle->m_Pos );
  104. CopyParticle( pParticle, pNew );
  105. }
  106. }
  107. void DrawParticleSingletons( bool bInSkybox )
  108. {
  109. if ( g_pSimpleSingleton[bInSkybox].IsValid() )
  110. {
  111. g_pSimpleSingleton[bInSkybox]->GetBinding().DrawModel( 1 );
  112. }
  113. if ( g_pEmberSingleton[bInSkybox].IsValid() )
  114. {
  115. g_pEmberSingleton[bInSkybox]->GetBinding().DrawModel( 1 );
  116. }
  117. if ( g_pFireSmokeSingleton[bInSkybox].IsValid() )
  118. {
  119. g_pFireSmokeSingleton[bInSkybox]->GetBinding().DrawModel( 1 );
  120. }
  121. if ( g_pFireSingleton[bInSkybox].IsValid() )
  122. {
  123. g_pFireSingleton[bInSkybox]->GetBinding().DrawModel( 1 );
  124. }
  125. }