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.

337 lines
9.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: provide client-side access to the new particle system, with similar
  4. // usage to CSimpleEmitter
  5. //
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #ifndef PARTICLES_NEW_H
  9. #define PARTICLES_NEW_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "particlemgr.h"
  14. #include "particles/particles.h"
  15. #include "particlesphererenderer.h"
  16. #include "smartptr.h"
  17. #include "particles_simple.h"
  18. #include "tier1/utlobjectreference.h"
  19. //-----------------------------------------------------------------------------
  20. // Particle effect
  21. //-----------------------------------------------------------------------------
  22. class CNewParticleEffect : public IParticleEffect, public CParticleCollection, public CDefaultClientRenderable
  23. {
  24. public:
  25. DECLARE_CLASS_NOBASE( CNewParticleEffect );
  26. DECLARE_REFERENCED_CLASS( CNewParticleEffect );
  27. public:
  28. friend class CRefCountAccessor;
  29. // list management
  30. CNewParticleEffect *m_pNext;
  31. CNewParticleEffect *m_pPrev;
  32. // Call this before adding a bunch of particles to give it a rough estimate of where
  33. // your particles are for sorting amongst other translucent entities.
  34. void SetSortOrigin( const Vector &vSortOrigin );
  35. bool ShouldDraw( void );
  36. virtual bool IsTransparent( void );
  37. virtual bool IsTwoPass( void );
  38. virtual bool UsesPowerOfTwoFrameBufferTexture( void );
  39. virtual bool UsesFullFrameBufferTexture( void );
  40. const QAngle& GetRenderAngles( void );
  41. const matrix3x4_t& RenderableToWorldTransform();
  42. void GetRenderBounds( Vector& mins, Vector& maxs );
  43. // check if the new bounds of the particle system needs its client-leaf info needs to be updated
  44. void DetectChanges( void );
  45. const Vector &GetRenderOrigin( void );
  46. PMaterialHandle GetPMaterial( const char *name );
  47. bool RecalculateBoundingBox();
  48. Particle* AddParticle( unsigned int particleSize, PMaterialHandle material, const Vector &origin );
  49. const char *GetEffectName();
  50. void SetDontRemove( bool bSet );
  51. void SetDrawn( bool bDrawn );
  52. void SetFirstFrameFlag( bool bFirst );
  53. void SetNeedsBBoxUpdate( bool bNeedsUpdate );
  54. void SetAutoUpdateBBox( bool bNeedsUpdate );
  55. void SetRemoveFlag( void );
  56. bool GetRemoveFlag( void );
  57. bool GetFirstFrameFlag( void );
  58. bool GetNeedsBBoxUpdate( void );
  59. bool GetAutoUpdateBBox( void );
  60. bool ShouldPerformCullCheck() const;
  61. void MarkShouldPerformCullCheck( bool bEnable );
  62. CBaseEntity *GetOwner( void ) { return m_hOwner; }
  63. void SetOwner( CBaseEntity *pOwner ) { m_hOwner = pOwner; }
  64. CNewParticleEffect* ReplaceWith( const char *pParticleSystemName );
  65. static CSmartPtr<CNewParticleEffect> Create( CBaseEntity *pOwner, const char *pParticleSystemName,
  66. const char *pDebugName = NULL );
  67. static CSmartPtr<CNewParticleEffect> Create( CBaseEntity *pOwner, CParticleSystemDefinition *pDef,
  68. const char *pDebugName = NULL );
  69. virtual int DrawModel( int flags );
  70. void DebugDrawBbox ( bool bCulled );
  71. // CParticleCollection overrides
  72. public:
  73. void StopEmission( bool bInfiniteOnly = false, bool bRemoveAllParticles = false, bool bWakeOnStop = false );
  74. void SetDormant( bool bDormant );
  75. void SetControlPoint( int nWhichPoint, const Vector &v );
  76. void SetControlPointEntity( int nWhichPoint, CBaseEntity *pEntity );
  77. void SetControlPointOrientation( int nWhichPoint, const Quaternion &q );
  78. void SetControlPointOrientation( int nWhichPoint, const Vector &forward, const Vector &right, const Vector &up );
  79. void SetControlPointForwardVector( int nWhichPoint, const Vector &v );
  80. void SetControlPointUpVector( int nWhichPoint, const Vector &v );
  81. void SetControlPointRightVector( int nWhichPoint, const Vector &v );
  82. void SetIsViewModelEffect ( bool bIsViewModelEffect ) { m_bViewModelEffect = bIsViewModelEffect; }
  83. bool GetIsViewModelEffect () { return m_bViewModelEffect; }
  84. FORCEINLINE EHANDLE const &GetControlPointEntity( int nWhichPoint )
  85. {
  86. return m_hControlPointOwners[ nWhichPoint ];
  87. }
  88. // IParticleEffect overrides
  89. public:
  90. virtual void SimulateParticles( CParticleSimulateIterator *pIterator )
  91. {
  92. }
  93. virtual void RenderParticles( CParticleRenderIterator *pIterator )
  94. {
  95. }
  96. virtual void SetParticleCullRadius( float radius );
  97. virtual void NotifyRemove( void );
  98. virtual const Vector & GetSortOrigin( void );
  99. // virtual void NotifyDestroyParticle( Particle* pParticle );
  100. virtual void Update( float flTimeDelta );
  101. // All Create() functions should call this so the effect deletes itself
  102. // when it is removed from the particle manager.
  103. void SetDynamicallyAllocated( bool bDynamic = true );
  104. virtual bool ShouldSimulate() const { return m_bSimulate; }
  105. virtual void SetShouldSimulate( bool bSim ) { m_bSimulate = bSim; }
  106. int AllocateToolParticleEffectId();
  107. int GetToolParticleEffectId() const;
  108. CNewParticleEffect( CBaseEntity *pOwner, const char *pEffectName );
  109. CNewParticleEffect( CBaseEntity *pOwner, CParticleSystemDefinition *pEffect );
  110. virtual ~CNewParticleEffect();
  111. protected:
  112. // Returns nonzero if Release() has been called.
  113. int IsReleased();
  114. // Used to track down bugs.
  115. const char *m_pDebugName;
  116. bool m_bDontRemove : 1;
  117. bool m_bRemove : 1;
  118. bool m_bDrawn : 1;
  119. bool m_bNeedsBBoxUpdate : 1;
  120. bool m_bIsFirstFrame : 1;
  121. bool m_bAutoUpdateBBox : 1;
  122. bool m_bAllocated : 1;
  123. bool m_bSimulate : 1;
  124. bool m_bShouldPerformCullCheck : 1;
  125. int m_nToolParticleEffectId;
  126. Vector m_vSortOrigin;
  127. EHANDLE m_hOwner;
  128. EHANDLE m_hControlPointOwners[MAX_PARTICLE_CONTROL_POINTS];
  129. // holds the min/max bounds used to manage this thing in the client leaf system
  130. Vector m_LastMin;
  131. Vector m_LastMax;
  132. bool m_bViewModelEffect;
  133. private:
  134. // Update the reference count.
  135. void AddRef();
  136. void Release();
  137. void RecordControlPointOrientation( int nWhichPoint );
  138. void Construct();
  139. int m_RefCount; // When this goes to zero and the effect has no more active
  140. // particles, (and it's dynamically allocated), it will delete itself.
  141. CNewParticleEffect( const CNewParticleEffect & ); // not defined, not accessible
  142. };
  143. //-----------------------------------------------------------------------------
  144. // Inline methods
  145. //-----------------------------------------------------------------------------
  146. inline int CNewParticleEffect::GetToolParticleEffectId() const
  147. {
  148. return m_nToolParticleEffectId;
  149. }
  150. inline int CNewParticleEffect::AllocateToolParticleEffectId()
  151. {
  152. m_nToolParticleEffectId = ParticleMgr()->AllocateToolParticleEffectId();
  153. return m_nToolParticleEffectId;
  154. }
  155. // Call this before adding a bunch of particles to give it a rough estimate of where
  156. // your particles are for sorting amongst other translucent entities.
  157. inline void CNewParticleEffect::SetSortOrigin( const Vector &vSortOrigin )
  158. {
  159. m_vSortOrigin = vSortOrigin;
  160. }
  161. inline const Vector &CNewParticleEffect::GetSortOrigin( void )
  162. {
  163. return m_vSortOrigin;
  164. }
  165. inline bool CNewParticleEffect::ShouldDraw( void )
  166. {
  167. return true;
  168. }
  169. inline bool CNewParticleEffect::IsTransparent( void )
  170. {
  171. return CParticleCollection::IsTranslucent();
  172. }
  173. inline const QAngle& CNewParticleEffect::GetRenderAngles( void )
  174. {
  175. return vec3_angle;
  176. }
  177. inline const matrix3x4_t & CNewParticleEffect::RenderableToWorldTransform()
  178. {
  179. static matrix3x4_t mat;
  180. SetIdentityMatrix( mat );
  181. PositionMatrix( GetRenderOrigin(), mat );
  182. return mat;
  183. }
  184. inline Vector const &CNewParticleEffect::GetRenderOrigin( void )
  185. {
  186. return m_vSortOrigin;
  187. }
  188. inline PMaterialHandle CNewParticleEffect::GetPMaterial(const char *name)
  189. {
  190. //!!
  191. Assert( 0 );
  192. return NULL;
  193. }
  194. inline Particle* CNewParticleEffect::AddParticle( unsigned int particleSize, PMaterialHandle material, const Vector &origin )
  195. {
  196. //!!
  197. Assert( 0 );
  198. return NULL;
  199. }
  200. inline const char *CNewParticleEffect::GetEffectName()
  201. {
  202. return GetName();
  203. }
  204. inline void CNewParticleEffect::SetDontRemove( bool bSet )
  205. {
  206. m_bDontRemove = bSet;
  207. }
  208. inline void CNewParticleEffect::SetDrawn( bool bDrawn )
  209. {
  210. m_bDrawn = bDrawn;
  211. }
  212. inline void CNewParticleEffect::SetFirstFrameFlag( bool bFirst )
  213. {
  214. m_bIsFirstFrame = bFirst;
  215. }
  216. inline void CNewParticleEffect::SetDynamicallyAllocated( bool bDynamic )
  217. {
  218. m_bAllocated = bDynamic;
  219. }
  220. inline void CNewParticleEffect::SetNeedsBBoxUpdate( bool bNeedsUpdate )
  221. {
  222. m_bNeedsBBoxUpdate = bNeedsUpdate;
  223. }
  224. inline void CNewParticleEffect::SetAutoUpdateBBox( bool bNeedsUpdate )
  225. {
  226. m_bAutoUpdateBBox = bNeedsUpdate;
  227. }
  228. inline void CNewParticleEffect::SetRemoveFlag( void )
  229. {
  230. m_bRemove = true;
  231. }
  232. inline bool CNewParticleEffect::GetRemoveFlag( void )
  233. {
  234. return m_bRemove;
  235. }
  236. inline bool CNewParticleEffect::GetFirstFrameFlag( void )
  237. {
  238. return m_bIsFirstFrame;
  239. }
  240. inline bool CNewParticleEffect::GetNeedsBBoxUpdate( void )
  241. {
  242. return m_bNeedsBBoxUpdate;
  243. }
  244. inline bool CNewParticleEffect::GetAutoUpdateBBox( void )
  245. {
  246. return m_bAutoUpdateBBox;
  247. }
  248. inline bool CNewParticleEffect::ShouldPerformCullCheck() const
  249. {
  250. return m_bShouldPerformCullCheck;
  251. }
  252. inline void CNewParticleEffect::MarkShouldPerformCullCheck( bool bEnable )
  253. {
  254. m_bShouldPerformCullCheck = bEnable;
  255. }
  256. inline CSmartPtr<CNewParticleEffect> CNewParticleEffect::Create( CBaseEntity *pOwner, const char *pParticleSystemName, const char *pDebugName )
  257. {
  258. CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, pParticleSystemName );
  259. pRet->m_pDebugName = pDebugName ? pDebugName : pParticleSystemName;
  260. pRet->SetDynamicallyAllocated( true );
  261. return pRet;
  262. }
  263. inline CSmartPtr<CNewParticleEffect> CNewParticleEffect::Create( CBaseEntity *pOwner, CParticleSystemDefinition *pDef, const char *pDebugName )
  264. {
  265. CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, pDef );
  266. pRet->m_pDebugName = pDebugName ? pDebugName : pDef->GetName();
  267. pRet->SetDynamicallyAllocated( true );
  268. return pRet;
  269. }
  270. //--------------------------------------------------------------------------------
  271. // If you use an HPARTICLEFFECT instead of a cnewparticleeffect *, you get a pointer
  272. // which will go to null when the effect is deleted
  273. //--------------------------------------------------------------------------------
  274. typedef CUtlReference<CNewParticleEffect> HPARTICLEFFECT;
  275. #endif // PARTICLES_NEW_H