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.

135 lines
5.3 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef PARTICLEPROPERTY_H
  7. #define PARTICLEPROPERTY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "smartptr.h"
  12. #include "globalvars_base.h"
  13. #include "particles_new.h"
  14. #include "particle_parse.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. class CBaseEntity;
  19. class CNewParticleEffect;
  20. // Argh: Server considers -1 to be an invalid attachment, whereas the client uses 0
  21. #ifdef CLIENT_DLL
  22. #define INVALID_PARTICLE_ATTACHMENT 0
  23. #else
  24. #define INVALID_PARTICLE_ATTACHMENT -1
  25. #endif
  26. struct ParticleControlPoint_t
  27. {
  28. ParticleControlPoint_t()
  29. {
  30. iControlPoint = 0;
  31. iAttachType = PATTACH_ABSORIGIN_FOLLOW;
  32. iAttachmentPoint = 0;
  33. vecOriginOffset = vec3_origin;
  34. matOffset.Invalidate();
  35. }
  36. int iControlPoint;
  37. ParticleAttachment_t iAttachType;
  38. int iAttachmentPoint;
  39. Vector vecOriginOffset;
  40. matrix3x4_t matOffset;
  41. EHANDLE hEntity;
  42. };
  43. struct ParticleEffectList_t
  44. {
  45. ParticleEffectList_t()
  46. {
  47. pParticleEffect = NULL;
  48. }
  49. CUtlVector<ParticleControlPoint_t> pControlPoints;
  50. CSmartPtr<CNewParticleEffect> pParticleEffect;
  51. };
  52. extern int GetAttachTypeFromString( const char *pszString );
  53. //-----------------------------------------------------------------------------
  54. // Encapsulates particle handling for an entity
  55. //-----------------------------------------------------------------------------
  56. class CParticleProperty
  57. {
  58. DECLARE_CLASS_NOBASE( CParticleProperty );
  59. DECLARE_EMBEDDED_NETWORKVAR();
  60. DECLARE_PREDICTABLE();
  61. DECLARE_DATADESC();
  62. public:
  63. CParticleProperty();
  64. ~CParticleProperty();
  65. void Init( CBaseEntity *pEntity );
  66. CBaseEntity *GetOuter( void ) { return m_pOuter; }
  67. int GetAllParticleEffectRenderables( IClientRenderable **pOutput, int iMaxOutput ); //gets a list of all renderables used by this particle property
  68. // Effect Creation
  69. CNewParticleEffect *Create( const char *pszParticleName, ParticleAttachment_t iAttachType, const char *pszAttachmentName );
  70. CNewParticleEffect *Create( const char *pszParticleName, ParticleAttachment_t iAttachType, int iAttachmentPoint = -1, Vector vecOriginOffset = vec3_origin, matrix3x4_t *vecOffsetMatrix = NULL );
  71. CNewParticleEffect *CreatePrecached( int nPrecacheIndex, ParticleAttachment_t iAttachType, int iAttachmentPoint = -1, Vector vecOriginOffset = vec3_origin, matrix3x4_t *vecOffsetMatrix = NULL );
  72. void AddControlPoint( CNewParticleEffect *pEffect, int iPoint, C_BaseEntity *pEntity, ParticleAttachment_t iAttachType, const char *pszAttachmentName = NULL, Vector vecOriginOffset = vec3_origin, matrix3x4_t *vecOffsetMatrix = NULL );
  73. void AddControlPoint( int iEffectIndex, int iPoint, C_BaseEntity *pEntity, ParticleAttachment_t iAttachType, int iAttachmentPoint = -1, Vector vecOriginOffset = vec3_origin, matrix3x4_t *vecOffsetMatrix = NULL );
  74. inline void SetControlPointParent( CNewParticleEffect *pEffect, int whichControlPoint, int parentIdx );
  75. void SetControlPointParent( int iEffectIndex, int whichControlPoint, int parentIdx );
  76. // Commands
  77. void StopEmission( CNewParticleEffect *pEffect = NULL, bool bWakeOnStop = false, bool bDestroyAsleepSystems = false, bool bForceRemoveInstantly = false, bool bPlayEndCap = false );
  78. void StopEmissionAndDestroyImmediately( CNewParticleEffect *pEffect = NULL );
  79. // kill all particle systems involving a given entity for their control points
  80. void StopParticlesInvolving( CBaseEntity *pEntity, bool bForceRemoveInstantly = false );
  81. void StopParticlesNamed( const char *pszEffectName, bool bForceRemoveInstantly = false, int nSplitScreenPlayerSlot = -1 ); ///< kills all particles using the given definition name
  82. // Particle System hooks
  83. void OnParticleSystemUpdated( CNewParticleEffect *pEffect, float flTimeDelta );
  84. void OnParticleSystemDeleted( CNewParticleEffect *pEffect );
  85. #ifdef CLIENT_DLL
  86. void OwnerSetDormantTo( bool bDormant );
  87. #endif
  88. // Used to replace a particle effect with a different one; attaches the control point updating to the new one
  89. void ReplaceParticleEffect( CNewParticleEffect *pOldEffect, CNewParticleEffect *pNewEffect );
  90. // Debugging
  91. void DebugPrintEffects( void );
  92. bool IsValidEffect( const CNewParticleEffect *pEffect ); //is this effect still alive?
  93. int FindEffect( CNewParticleEffect *pEffect );
  94. int FindEffect( const char *pEffectName );
  95. private:
  96. CNewParticleEffect *Create( CParticleSystemDefinition *pDef, ParticleAttachment_t iAttachType, int iAttachmentPoint, Vector vecOriginOffset, matrix3x4_t *matOffset = NULL );
  97. int GetParticleAttachment( C_BaseEntity *pEntity, const char *pszAttachmentName, const char *pszParticleName );
  98. void UpdateParticleEffect( ParticleEffectList_t *pEffect, bool bInitializing = false, int iOnlyThisControlPoint = -1 );
  99. void UpdateControlPoint( ParticleEffectList_t *pEffect, int iPoint, bool bInitializing );
  100. inline CNewParticleEffect *GetParticleEffectFromIdx( int idx );
  101. private:
  102. CBaseEntity *m_pOuter;
  103. CUtlVector<ParticleEffectList_t> m_ParticleEffects;
  104. int m_iDormancyChangedAtFrame;
  105. friend class CBaseEntity;
  106. };
  107. #include "particle_property_inlines.h"
  108. #endif // PARTICLEPROPERTY_H