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.

390 lines
8.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. // This defines the client-side SmokeTrail entity. It can also be used without
  9. // an entity, in which case you must pass calls to it and set its position each frame.
  10. #ifndef PARTICLE_SMOKETRAIL_H
  11. #define PARTICLE_SMOKETRAIL_H
  12. #include "particlemgr.h"
  13. #include "particle_prototype.h"
  14. #include "particle_util.h"
  15. #include "particles_simple.h"
  16. #include "c_baseentity.h"
  17. #include "baseparticleentity.h"
  18. #include "fx_trail.h"
  19. //
  20. // Smoke Trail
  21. //
  22. class C_SmokeTrail : public C_BaseParticleEntity, public IPrototypeAppEffect
  23. {
  24. public:
  25. DECLARE_CLASS( C_SmokeTrail, C_BaseParticleEntity );
  26. DECLARE_CLIENTCLASS();
  27. C_SmokeTrail();
  28. virtual ~C_SmokeTrail();
  29. public:
  30. //For attachments
  31. void GetAimEntOrigin( IClientEntity *pAttachedTo, Vector *pAbsOrigin, QAngle *pAbsAngles );
  32. // Enable/disable emission.
  33. void SetEmit(bool bEmit);
  34. // Change the spawn rate.
  35. void SetSpawnRate(float rate);
  36. // C_BaseEntity.
  37. public:
  38. virtual void OnDataChanged(DataUpdateType_t updateType);
  39. virtual void CleanupToolRecordingState( KeyValues *msg );
  40. // IPrototypeAppEffect.
  41. public:
  42. virtual void Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs);
  43. // IParticleEffect.
  44. public:
  45. virtual void Update(float fTimeDelta);
  46. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  47. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  48. public:
  49. // Effect parameters. These will assume default values but you can change them.
  50. float m_SpawnRate; // How many particles per second.
  51. Vector m_StartColor; // Fade between these colors.
  52. Vector m_EndColor;
  53. float m_Opacity;
  54. float m_ParticleLifetime; // How long do the particles live?
  55. float m_StopEmitTime; // When do I stop emitting particles? (-1 = never)
  56. float m_MinSpeed; // Speed range.
  57. float m_MaxSpeed;
  58. float m_MinDirectedSpeed; // Directed speed range.
  59. float m_MaxDirectedSpeed;
  60. float m_StartSize; // Size ramp.
  61. float m_EndSize;
  62. float m_SpawnRadius;
  63. Vector m_VelocityOffset; // Emit the particles in a certain direction.
  64. bool m_bEmit; // Keep emitting particles?
  65. int m_nAttachment;
  66. private:
  67. C_SmokeTrail( const C_SmokeTrail & );
  68. PMaterialHandle m_MaterialHandle[2];
  69. TimedEvent m_ParticleSpawn;
  70. CParticleMgr *m_pParticleMgr;
  71. CSmartPtr<CSimpleEmitter> m_pSmokeEmitter;
  72. };
  73. //==================================================
  74. // C_RocketTrail
  75. //==================================================
  76. class C_RocketTrail : public C_BaseParticleEntity, public IPrototypeAppEffect
  77. {
  78. public:
  79. DECLARE_CLASS( C_RocketTrail, C_BaseParticleEntity );
  80. DECLARE_CLIENTCLASS();
  81. C_RocketTrail();
  82. virtual ~C_RocketTrail();
  83. public:
  84. //For attachments
  85. void GetAimEntOrigin( IClientEntity *pAttachedTo, Vector *pAbsOrigin, QAngle *pAbsAngles );
  86. // Enable/disable emission.
  87. void SetEmit(bool bEmit);
  88. // Change the spawn rate.
  89. void SetSpawnRate(float rate);
  90. // C_BaseEntity.
  91. public:
  92. virtual void OnDataChanged(DataUpdateType_t updateType);
  93. // IPrototypeAppEffect.
  94. public:
  95. virtual void Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs);
  96. // IParticleEffect.
  97. public:
  98. virtual void Update(float fTimeDelta);
  99. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  100. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  101. public:
  102. // Effect parameters. These will assume default values but you can change them.
  103. float m_SpawnRate; // How many particles per second.
  104. Vector m_StartColor; // Fade between these colors.
  105. Vector m_EndColor;
  106. float m_Opacity;
  107. float m_ParticleLifetime; // How long do the particles live?
  108. float m_StopEmitTime; // When do I stop emitting particles? (-1 = never)
  109. float m_MinSpeed; // Speed range.
  110. float m_MaxSpeed;
  111. float m_StartSize; // Size ramp.
  112. float m_EndSize;
  113. float m_SpawnRadius;
  114. Vector m_VelocityOffset; // Emit the particles in a certain direction.
  115. bool m_bEmit; // Keep emitting particles?
  116. bool m_bDamaged; // Has been shot down (should be on fire, etc)
  117. int m_nAttachment;
  118. Vector m_vecLastPosition; // Last known position of the rocket
  119. float m_flFlareScale; // Size of the flare
  120. private:
  121. C_RocketTrail( const C_RocketTrail & );
  122. PMaterialHandle m_MaterialHandle[2];
  123. TimedEvent m_ParticleSpawn;
  124. CParticleMgr *m_pParticleMgr;
  125. CSmartPtr<CSimpleEmitter> m_pRocketEmitter;
  126. };
  127. class SporeSmokeEffect;
  128. //==================================================
  129. // SporeEffect
  130. //==================================================
  131. class SporeEffect : public CSimpleEmitter
  132. {
  133. public:
  134. SporeEffect( const char *pDebugName );
  135. static SporeEffect* Create( const char *pDebugName );
  136. virtual void UpdateVelocity( SimpleParticle *pParticle, float timeDelta );
  137. virtual Vector UpdateColor( const SimpleParticle *pParticle );
  138. virtual float UpdateAlpha( const SimpleParticle *pParticle );
  139. private:
  140. SporeEffect( const SporeEffect & );
  141. };
  142. //==================================================
  143. // C_SporeExplosion
  144. //==================================================
  145. class C_SporeExplosion : public C_BaseParticleEntity, public IPrototypeAppEffect
  146. {
  147. public:
  148. DECLARE_CLASS( C_SporeExplosion, C_BaseParticleEntity );
  149. DECLARE_CLIENTCLASS();
  150. C_SporeExplosion( void );
  151. virtual ~C_SporeExplosion( void );
  152. public:
  153. // C_BaseEntity
  154. public:
  155. virtual void OnDataChanged( DataUpdateType_t updateType );
  156. // IPrototypeAppEffect
  157. public:
  158. virtual void Start( CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs );
  159. // IParticleEffect
  160. public:
  161. virtual void Update( float fTimeDelta );
  162. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  163. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  164. public:
  165. float m_flSpawnRate;
  166. float m_flParticleLifetime;
  167. float m_flStartSize;
  168. float m_flEndSize;
  169. float m_flSpawnRadius;
  170. float m_flPreviousSpawnRate;
  171. bool m_bEmit;
  172. bool m_bDontRemove;
  173. private:
  174. C_SporeExplosion( const C_SporeExplosion & );
  175. void AddParticles( void );
  176. PMaterialHandle m_hMaterial;
  177. TimedEvent m_teParticleSpawn;
  178. SporeEffect *m_pSporeEffect;
  179. CParticleMgr *m_pParticleMgr;
  180. };
  181. //
  182. // Particle trail
  183. //
  184. class CSmokeParticle;
  185. class C_FireTrail : public C_ParticleTrail
  186. {
  187. public:
  188. DECLARE_CLASS( C_FireTrail, C_ParticleTrail );
  189. DECLARE_CLIENTCLASS();
  190. C_FireTrail( void );
  191. virtual ~C_FireTrail( void );
  192. virtual void Start( CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs );
  193. virtual void Update( float fTimeDelta );
  194. private:
  195. enum
  196. {
  197. // Smoke
  198. FTRAIL_SMOKE1,
  199. FTRAIL_SMOKE2,
  200. // Large flame
  201. FTRAIL_FLAME1,
  202. FTRAIL_FLAME2,
  203. FTRAIL_FLAME3,
  204. FTRAIL_FLAME4,
  205. FTRAIL_FLAME5,
  206. NUM_FTRAIL_MATERIALS
  207. };
  208. CSmartPtr<CSimpleEmitter> m_pTrailEmitter;
  209. CSmartPtr<CSmokeParticle> m_pSmokeEmitter;
  210. PMaterialHandle m_hMaterial[NUM_FTRAIL_MATERIALS];
  211. Vector m_vecLastPosition;
  212. C_FireTrail( const C_FireTrail & );
  213. };
  214. //==================================================
  215. // C_DustTrail
  216. //==================================================
  217. class C_DustTrail : public C_BaseParticleEntity, public IPrototypeAppEffect
  218. {
  219. public:
  220. DECLARE_CLASS( C_DustTrail, C_BaseParticleEntity );
  221. DECLARE_CLIENTCLASS();
  222. C_DustTrail();
  223. virtual ~C_DustTrail();
  224. public:
  225. // Enable/disable emission.
  226. void SetEmit(bool bEmit);
  227. // Change the spawn rate.
  228. void SetSpawnRate(float rate);
  229. // C_BaseEntity.
  230. public:
  231. virtual void OnDataChanged(DataUpdateType_t updateType);
  232. virtual void CleanupToolRecordingState( KeyValues *msg );
  233. // IPrototypeAppEffect.
  234. public:
  235. virtual void Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs);
  236. // IParticleEffect.
  237. public:
  238. virtual void Update(float fTimeDelta);
  239. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  240. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  241. public:
  242. // Effect parameters. These will assume default values but you can change them.
  243. float m_SpawnRate; // How many particles per second.
  244. Vector m_Color;
  245. float m_Opacity;
  246. float m_ParticleLifetime; // How long do the particles live?
  247. float m_StartEmitTime; // When did I start emitting particles?
  248. float m_StopEmitTime; // When do I stop emitting particles? (-1 = never)
  249. float m_MinSpeed; // Speed range.
  250. float m_MaxSpeed;
  251. float m_MinDirectedSpeed; // Directed speed range.
  252. float m_MaxDirectedSpeed;
  253. float m_StartSize; // Size ramp.
  254. float m_EndSize;
  255. float m_SpawnRadius;
  256. Vector m_VelocityOffset; // Emit the particles in a certain direction.
  257. bool m_bEmit; // Keep emitting particles?
  258. private:
  259. C_DustTrail( const C_DustTrail & );
  260. #define DUSTTRAIL_MATERIALS 16
  261. PMaterialHandle m_MaterialHandle[DUSTTRAIL_MATERIALS];
  262. TimedEvent m_ParticleSpawn;
  263. CParticleMgr *m_pParticleMgr;
  264. CSmartPtr<CSimpleEmitter> m_pDustEmitter;
  265. };
  266. #endif