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.

371 lines
11 KiB

  1. //===== Copyright (c) 1996-2006, 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. friend class CParticleSystemQuery;
  30. // list management
  31. CNewParticleEffect *m_pNext;
  32. CNewParticleEffect *m_pPrev;
  33. // Call this before adding a bunch of particles to give it a rough estimate of where
  34. // your particles are for sorting amongst other translucent entities.
  35. void SetSortOrigin( const Vector &vSortOrigin );
  36. bool ShouldDraw( void );
  37. virtual int GetRenderFlags( void );
  38. const QAngle& GetRenderAngles( void );
  39. const matrix3x4_t& RenderableToWorldTransform();
  40. void GetRenderBounds( Vector& mins, Vector& maxs );
  41. virtual bool ShouldDrawForSplitScreenUser( int nSlot );
  42. // check if the new bounds of the particle system needs its client-leaf info needs to be updated
  43. void DetectChanges( void );
  44. const Vector &GetRenderOrigin( void );
  45. PMaterialHandle GetPMaterial( const char *name );
  46. bool RecalculateBoundingBox();
  47. Particle* AddParticle( unsigned int particleSize, PMaterialHandle material, const Vector &origin );
  48. const char *GetEffectName();
  49. void SetDontRemove( bool bSet );
  50. void SetDrawn( bool bDrawn );
  51. void SetFirstFrameFlag( bool bFirst );
  52. void SetNeedsBBoxUpdate( bool bNeedsUpdate );
  53. void SetAutoUpdateBBox( bool bNeedsUpdate );
  54. void SetRemoveFlag( void );
  55. bool GetRemoveFlag( void );
  56. bool GetFirstFrameFlag( void );
  57. bool GetNeedsBBoxUpdate( void );
  58. bool GetAutoUpdateBBox( void );
  59. bool ShouldPerformCullCheck() const;
  60. void MarkShouldPerformCullCheck( bool bEnable );
  61. CBaseEntity *GetOwner( void ) { return m_hOwner; }
  62. void SetOwner( CBaseEntity *pOwner );
  63. CNewParticleEffect* ReplaceWith( const char *pParticleSystemName );
  64. static CNewParticleEffect *Create( CBaseEntity *pOwner, const char *pParticleSystemName,
  65. const char *pDebugName = NULL );
  66. static CNewParticleEffect *Create( CBaseEntity *pOwner, CParticleSystemDefinition *pDef,
  67. const char *pDebugName = NULL );
  68. static CNewParticleEffect *CreatePrecached( CBaseEntity *pOwner, int nPrecacheIndex,
  69. const char *pDebugName = NULL );
  70. static CNewParticleEffect *CreateOrAggregate( CBaseEntity *pOwner, const char *pParticleSystemName,
  71. Vector const &vecAggregatePosition, const char *pDebugName = NULL,
  72. int nSplitScreenUser = -1 );
  73. static CNewParticleEffect *CreateOrAggregate( CBaseEntity *pOwner, CParticleSystemDefinition *pDef,
  74. Vector const &vecAggregatePosition, const char *pDebugName = NULL,
  75. int nSplitScreenUser = -1 );
  76. static CNewParticleEffect *CreateOrAggregatePrecached( CBaseEntity *pOwner, int nPrecacheIndex,
  77. Vector const &vecAggregatePosition,
  78. const char *pDebugName = NULL,
  79. int nSplitScreenUser = -1 );
  80. static void RemoveParticleEffect( int nPrecacheIndex );
  81. virtual int DrawModel( int flags, const RenderableInstance_t &instance );
  82. bool SetupBones( matrix3x4a_t *pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime );
  83. void SetDrawOnlyForSplitScreenUser( int nSlot );
  84. // CParticleCollection overrides
  85. public:
  86. void StopEmission( bool bInfiniteOnly = false, bool bRemoveAllParticles = false, bool bWakeOnStop = false, bool bPlayEndCap = false );
  87. void SetDormant( bool bDormant );
  88. void SetControlPoint( int nWhichPoint, const Vector &v );
  89. void SetControlPointEntity( int nWhichPoint, CBaseEntity *pEntity );
  90. void SetControlPointOrientation( int nWhichPoint, const Quaternion &q );
  91. void SetControlPointOrientation( int nWhichPoint, const Vector &forward, const Vector &right, const Vector &up );
  92. void SetControlPointForwardVector( int nWhichPoint, const Vector &v );
  93. void SetControlPointUpVector( int nWhichPoint, const Vector &v );
  94. void SetControlPointRightVector( int nWhichPoint, const Vector &v );
  95. FORCEINLINE EHANDLE const &GetControlPointEntity( int nWhichPoint )
  96. {
  97. return m_hControlPointOwners[ nWhichPoint ];
  98. }
  99. // IParticleEffect overrides
  100. public:
  101. virtual void SimulateParticles( CParticleSimulateIterator *pIterator )
  102. {
  103. }
  104. virtual void RenderParticles( CParticleRenderIterator *pIterator )
  105. {
  106. }
  107. virtual void SetParticleCullRadius( float radius );
  108. virtual void NotifyRemove( void );
  109. virtual const Vector & GetSortOrigin( void );
  110. // virtual void NotifyDestroyParticle( Particle* pParticle );
  111. virtual void Update( float flTimeDelta );
  112. // All Create() functions should call this so the effect deletes itself
  113. // when it is removed from the particle manager.
  114. void SetDynamicallyAllocated( bool bDynamic = true );
  115. virtual bool ShouldSimulate() const { return m_bSimulate; }
  116. virtual void SetShouldSimulate( bool bSim ) { m_bSimulate = bSim; }
  117. void SetToolRecording( bool bRecord );
  118. int AllocateToolParticleEffectId();
  119. int GetToolParticleEffectId() const;
  120. virtual ~CNewParticleEffect();
  121. protected:
  122. CNewParticleEffect( CBaseEntity *pOwner, const char *pEffectName );
  123. CNewParticleEffect( CBaseEntity *pOwner, CParticleSystemDefinition *pEffect );
  124. CNewParticleEffect( CBaseEntity *pOwner, int nPrecacheIndex );
  125. // Returns nonzero if Release() has been called.
  126. int IsReleased();
  127. // Used to track down bugs.
  128. const char *m_pDebugName;
  129. bool m_bDontRemove : 1;
  130. bool m_bRemove : 1;
  131. bool m_bDrawn : 1;
  132. bool m_bNeedsBBoxUpdate : 1;
  133. bool m_bIsFirstFrame : 1;
  134. bool m_bAutoUpdateBBox : 1;
  135. bool m_bAllocated : 1;
  136. bool m_bSimulate : 1;
  137. bool m_bRecord : 1;
  138. bool m_bShouldPerformCullCheck : 1;
  139. // if a particle system is created through the non-aggregation entry point, we can't aggregate into it
  140. bool m_bDisableAggregation : 1;
  141. int m_nToolParticleEffectId;
  142. Vector m_vSortOrigin;
  143. EHANDLE m_hOwner;
  144. EHANDLE m_hControlPointOwners[MAX_PARTICLE_CONTROL_POINTS];
  145. // holds the min/max bounds used to manage this thing in the client leaf system
  146. Vector m_LastMin;
  147. Vector m_LastMax;
  148. int m_nSplitScreenUser; // -1 means don't care
  149. Vector m_vecAggregationCenter; // origin for aggregation if aggregation enabled
  150. private:
  151. // Update the reference count.
  152. void AddRef();
  153. void Release();
  154. void RecordControlPointOrientation( int nWhichPoint );
  155. void Construct();
  156. void RecordCreation();
  157. int m_RefCount; // When this goes to zero and the effect has no more active
  158. // particles, (and it's dynamically allocated), it will delete itself.
  159. matrix3x4a_t m_DrawModelMatrix;
  160. CNewParticleEffect( const CNewParticleEffect & ); // not defined, not accessible
  161. };
  162. //-----------------------------------------------------------------------------
  163. // Inline methods
  164. //-----------------------------------------------------------------------------
  165. inline int CNewParticleEffect::GetToolParticleEffectId() const
  166. {
  167. return m_nToolParticleEffectId;
  168. }
  169. inline int CNewParticleEffect::AllocateToolParticleEffectId()
  170. {
  171. m_nToolParticleEffectId = ParticleMgr()->AllocateToolParticleEffectId();
  172. return m_nToolParticleEffectId;
  173. }
  174. // Call this before adding a bunch of particles to give it a rough estimate of where
  175. // your particles are for sorting amongst other translucent entities.
  176. inline void CNewParticleEffect::SetSortOrigin( const Vector &vSortOrigin )
  177. {
  178. m_vSortOrigin = vSortOrigin;
  179. }
  180. inline const Vector &CNewParticleEffect::GetSortOrigin( void )
  181. {
  182. return m_vSortOrigin;
  183. }
  184. inline bool CNewParticleEffect::ShouldDraw( void )
  185. {
  186. return true;
  187. }
  188. inline const QAngle& CNewParticleEffect::GetRenderAngles( void )
  189. {
  190. return vec3_angle;
  191. }
  192. inline const matrix3x4_t & CNewParticleEffect::RenderableToWorldTransform()
  193. {
  194. static matrix3x4_t mat;
  195. SetIdentityMatrix( mat );
  196. PositionMatrix( GetRenderOrigin(), mat );
  197. return mat;
  198. }
  199. inline Vector const &CNewParticleEffect::GetRenderOrigin( void )
  200. {
  201. return m_vSortOrigin;
  202. }
  203. inline PMaterialHandle CNewParticleEffect::GetPMaterial(const char *name)
  204. {
  205. //!!
  206. Assert( 0 );
  207. return NULL;
  208. }
  209. inline Particle* CNewParticleEffect::AddParticle( unsigned int particleSize, PMaterialHandle material, const Vector &origin )
  210. {
  211. //!!
  212. Assert( 0 );
  213. return NULL;
  214. }
  215. inline const char *CNewParticleEffect::GetEffectName()
  216. {
  217. return GetName();
  218. }
  219. inline void CNewParticleEffect::SetDontRemove( bool bSet )
  220. {
  221. m_bDontRemove = bSet;
  222. }
  223. inline void CNewParticleEffect::SetDrawn( bool bDrawn )
  224. {
  225. m_bDrawn = bDrawn;
  226. }
  227. inline void CNewParticleEffect::SetFirstFrameFlag( bool bFirst )
  228. {
  229. m_bIsFirstFrame = bFirst;
  230. }
  231. inline void CNewParticleEffect::SetDynamicallyAllocated( bool bDynamic )
  232. {
  233. m_bAllocated = bDynamic;
  234. }
  235. inline void CNewParticleEffect::SetNeedsBBoxUpdate( bool bNeedsUpdate )
  236. {
  237. m_bNeedsBBoxUpdate = bNeedsUpdate;
  238. }
  239. inline void CNewParticleEffect::SetAutoUpdateBBox( bool bNeedsUpdate )
  240. {
  241. m_bAutoUpdateBBox = bNeedsUpdate;
  242. }
  243. inline void CNewParticleEffect::SetRemoveFlag( void )
  244. {
  245. m_bRemove = true;
  246. }
  247. inline bool CNewParticleEffect::GetRemoveFlag( void )
  248. {
  249. return m_bRemove;
  250. }
  251. inline bool CNewParticleEffect::GetFirstFrameFlag( void )
  252. {
  253. return m_bIsFirstFrame;
  254. }
  255. inline bool CNewParticleEffect::GetNeedsBBoxUpdate( void )
  256. {
  257. return m_bNeedsBBoxUpdate;
  258. }
  259. inline bool CNewParticleEffect::GetAutoUpdateBBox( void )
  260. {
  261. return m_bAutoUpdateBBox;
  262. }
  263. inline bool CNewParticleEffect::ShouldPerformCullCheck() const
  264. {
  265. return m_bShouldPerformCullCheck;
  266. }
  267. inline void CNewParticleEffect::MarkShouldPerformCullCheck( bool bEnable )
  268. {
  269. m_bShouldPerformCullCheck = bEnable;
  270. }
  271. inline CNewParticleEffect *CNewParticleEffect::Create( CBaseEntity *pOwner, const char *pParticleSystemName, const char *pDebugName )
  272. {
  273. CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, pParticleSystemName );
  274. pRet->m_pDebugName = pDebugName;
  275. pRet->SetDynamicallyAllocated( true );
  276. return pRet;
  277. }
  278. inline CNewParticleEffect *CNewParticleEffect::Create( CBaseEntity *pOwner, CParticleSystemDefinition *pDef, const char *pDebugName )
  279. {
  280. CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, pDef );
  281. pRet->m_pDebugName = pDebugName;
  282. pRet->SetDynamicallyAllocated( true );
  283. return pRet;
  284. }
  285. inline CNewParticleEffect *CNewParticleEffect::CreatePrecached( CBaseEntity *pOwner, int nPrecacheIndex, const char *pDebugName )
  286. {
  287. CNewParticleEffect *pRet = new CNewParticleEffect( pOwner, nPrecacheIndex );
  288. pRet->m_pDebugName = pDebugName;
  289. pRet->SetDynamicallyAllocated( true );
  290. return pRet;
  291. }
  292. //--------------------------------------------------------------------------------
  293. // If you use an HPARTICLEFFECT instead of a cnewparticleeffect *, you get a pointer
  294. // which will go to null when the effect is deleted
  295. //--------------------------------------------------------------------------------
  296. typedef CUtlReference<CNewParticleEffect> HPARTICLEFFECT;
  297. #endif // PARTICLES_NEW_H