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.

166 lines
4.8 KiB

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