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.

430 lines
10 KiB

  1. //===== Copyright � 1996-2005, 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. explicit 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. // Purpose: High drag, non color changing particle
  216. //-----------------------------------------------------------------------------
  217. class CDustFollower : public CSimpleEmitter
  218. {
  219. public:
  220. explicit CDustFollower( const char *pDebugName ) : CSimpleEmitter( pDebugName ) {}
  221. //Create
  222. static CDustFollower *Create( const char *pDebugName )
  223. {
  224. return new CDustFollower( pDebugName );
  225. }
  226. //Alpha
  227. virtual float UpdateAlpha( const SimpleParticle *pParticle )
  228. {
  229. return ( ((float)pParticle->m_uchStartAlpha/255.0f) * sin( M_PI * (pParticle->m_flLifetime / pParticle->m_flDieTime) ) );
  230. }
  231. virtual void UpdateVelocity( SimpleParticle *pParticle, float timeDelta )
  232. {
  233. pParticle->m_vecVelocity = pParticle->m_vecVelocity * ExponentialDecay( 0.3, timeDelta );
  234. }
  235. //Roll
  236. virtual float UpdateRoll( SimpleParticle *pParticle, float timeDelta )
  237. {
  238. pParticle->m_flRoll += pParticle->m_flRollDelta * timeDelta;
  239. pParticle->m_flRollDelta *= ExponentialDecay( 0.5, timeDelta );
  240. return pParticle->m_flRoll;
  241. }
  242. private:
  243. CDustFollower( const CDustFollower & );
  244. };
  245. //==================================================
  246. // C_DustTrail
  247. //==================================================
  248. class C_DustTrail : public C_BaseParticleEntity, public IPrototypeAppEffect
  249. {
  250. public:
  251. DECLARE_CLASS( C_DustTrail, C_BaseParticleEntity );
  252. DECLARE_CLIENTCLASS();
  253. C_DustTrail();
  254. virtual ~C_DustTrail();
  255. public:
  256. // Enable/disable emission.
  257. void SetEmit(bool bEmit);
  258. // Change the spawn rate.
  259. void SetSpawnRate(float rate);
  260. // C_BaseEntity.
  261. public:
  262. virtual void OnDataChanged(DataUpdateType_t updateType);
  263. virtual void CleanupToolRecordingState( KeyValues *msg );
  264. // IPrototypeAppEffect.
  265. public:
  266. virtual void Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs);
  267. // IParticleEffect.
  268. public:
  269. virtual void Update(float fTimeDelta);
  270. virtual void RenderParticles( CParticleRenderIterator *pIterator );
  271. virtual void SimulateParticles( CParticleSimulateIterator *pIterator );
  272. public:
  273. // Effect parameters. These will assume default values but you can change them.
  274. float m_SpawnRate; // How many particles per second.
  275. Vector m_Color;
  276. float m_Opacity;
  277. float m_ParticleLifetime; // How long do the particles live?
  278. float m_StartEmitTime; // When did I start emitting particles?
  279. float m_StopEmitTime; // When do I stop emitting particles? (-1 = never)
  280. float m_MinSpeed; // Speed range.
  281. float m_MaxSpeed;
  282. float m_MinDirectedSpeed; // Directed speed range.
  283. float m_MaxDirectedSpeed;
  284. float m_StartSize; // Size ramp.
  285. float m_EndSize;
  286. float m_SpawnRadius;
  287. Vector m_VelocityOffset; // Emit the particles in a certain direction.
  288. bool m_bEmit; // Keep emitting particles?
  289. private:
  290. C_DustTrail( const C_DustTrail & );
  291. #define DUSTTRAIL_MATERIALS 16
  292. PMaterialHandle m_MaterialHandle[DUSTTRAIL_MATERIALS];
  293. TimedEvent m_ParticleSpawn;
  294. CParticleMgr *m_pParticleMgr;
  295. CSmartPtr<CSimpleEmitter> m_pDustEmitter;
  296. };
  297. #endif