ParticleSystem.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PARTICLE_SYSTEM_H_
  23. #define _PARTICLE_SYSTEM_H_
  24. #ifndef _ANIMATION_CONTROLLER_H_
  25. #include "2d/assets/AnimationController.h"
  26. #endif
  27. //-----------------------------------------------------------------------------
  28. class ParticleSystem
  29. {
  30. public:
  31. /// Particle node.
  32. struct ParticleNode
  33. {
  34. /// Particle Node Linkages.
  35. ParticleNode* mPreviousNode;
  36. ParticleNode* mNextNode;
  37. /// Suppress Movement.
  38. bool mSuppressMovement;
  39. /// Particle Components.
  40. F32 mParticleLifetime;
  41. F32 mParticleAge;
  42. Vector2 mPosition;
  43. Vector2 mVelocity;
  44. F32 mOrientationAngle;
  45. Vector2 mRenderOOBB[4];
  46. U32 mImageFrame;
  47. b2Transform mTransform;
  48. AnimationController mAnimationController;
  49. /// Render Properties.
  50. Vector2 mRenderSize;
  51. F32 mRenderSpeed;
  52. F32 mRenderSpin;
  53. F32 mRenderFixedForce;
  54. F32 mRenderRandomMotion;
  55. /// Base Properties.
  56. Vector2 mSize;
  57. F32 mSpeed;
  58. F32 mSpin;
  59. F32 mFixedForce;
  60. F32 mRandomMotion;
  61. ColorF mColor;
  62. /// Interpolated Tick Position.
  63. Vector2 mPreTickPosition;
  64. Vector2 mPostTickPosition;
  65. Vector2 mRenderTickPosition;
  66. };
  67. private:
  68. const U32 mParticlePoolBlockSize;
  69. Vector<ParticleNode*> mParticlePool;
  70. ParticleNode* mpFreeParticleNodes;
  71. U32 mActiveParticleCount;
  72. public:
  73. static void Init( void );
  74. static void destroy( void );
  75. static ParticleSystem* Instance;
  76. ParticleSystem();
  77. ~ParticleSystem();
  78. ParticleNode* createParticle( void );
  79. void freeParticle( ParticleNode* pParticleNode );
  80. inline U32 getActiveParticleCount( void ) const { return mActiveParticleCount; };
  81. inline U32 getAllocatedParticleCount( void ) const { return (U32)mParticlePool.size() * mParticlePoolBlockSize; }
  82. };
  83. #endif // _PARTICLE_SYSTEM_H_