aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/particles/particle_system.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/particles/particle_system.h')
-rw-r--r--src/libjin/graphics/particles/particle_system.h195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/libjin/graphics/particles/particle_system.h b/src/libjin/graphics/particles/particle_system.h
new file mode 100644
index 0000000..83351a9
--- /dev/null
+++ b/src/libjin/graphics/particles/particle_system.h
@@ -0,0 +1,195 @@
+#ifndef __JE_PARTICLE_EMMITTER_H__
+#define __JE_PARTICLE_EMMITTER_H__
+
+#include <vector>
+
+#include "../../common/temporary.h"
+#include "../../game/gameobject.h"
+
+#include "../sprite.h"
+
+#include "particle_emitter.h"
+#include "particle_pool.h"
+#include "particle.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ ///
+ /// Definition of particle system.
+ ///
+ struct ParticleSystemDef
+ {
+ ParticleSystemDef() {}
+ uint maxParticleCount = 1; ///< Max count of particles in pool. 1 by default.
+ ParticleEmitterDef emitterDef; ///< Particle emitter definition.
+ ParticleDef particleDef; ///< Particle definition.
+ };
+
+ ///
+ /// Particle emitter, handle all particles it emitts.
+ ///
+ class ParticleSystem : public Renderable, public Game::GameObject
+ {
+ public:
+ ///
+ /// Particle system constructor
+ ///
+ /// @param def Definition of particle system.
+ ///
+ ParticleSystem(const ParticleSystemDef& def);
+
+ ///
+ ///
+ ///
+ ParticleSystem(uint maxCount = 64);
+
+ ///
+ ///
+ ///
+ ParticleSystem(const std::string & config);
+
+ ///
+ /// Particle system destructor.
+ ///
+ ~ParticleSystem();
+
+ ///
+ ///
+ ///
+ void setDefinition(const ParticleSystemDef& def);
+
+ ///
+ /// Load definition from config.
+ ///
+ void setDefinition(const std::string& config);
+
+ ///
+ /// Update particle system and all alive particles.
+ ///
+ void update(float dt);
+
+ ///
+ /// Render particle system.
+ ///
+ void render();
+
+ ///
+ /// Set particle system position.
+ ///
+ void setPosition(float x, float y);
+
+ ///
+ /// Set scale.
+ ///
+ void setScale(float sx, float sy);
+
+ ///
+ /// Pause particle spawn.
+ ///
+ void pause(bool isPause);
+
+ ///
+ /// Clear all particles.
+ ///
+ void clear();
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+ // Particle Emitter modification.
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+
+ void setEmitRate(float floor, float ceil);
+ void setEmitRate(float rate);
+
+ void setEmitForce(float floor, float ceil);
+ void setEmitForce(float force);
+
+ void setEmitDirection(float floor, float ceil);
+ void setEmitDirection(float dir);
+
+ void setEmitPosition(const Math::Vector2<float>& floor, const Math::Vector2<float>& ceil);
+ void setEmitPosition(const Math::Vector2<float>& position);
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+ // Particle modification.
+ //////////////////////////////////////////////////////////////////////////////////////////////////
+
+ void setParticleLife(float floor, float ceil);
+ void setParticleLife(float time);
+
+ void setParticleLinearAccelaration(Math::Vector2<float> ac);
+
+ void setParticleRadialAccelaration(float ra);
+
+ void setParticleAngularSpeed(float floor, float ceil);
+ void setParticleAngularSpeed(float speed);
+
+ void setParticleSpritesMode(SpriteMode mode);
+ void addParticleSprite(const Sprite* sprite);
+ void addParticleSprites(uint count, ...);
+ void addParticleSprites(const std::vector<const Sprite*>& sprs);
+ void removeParticleSprite(uint i);
+
+ void enableParticleBlendAdditive(bool enable);
+
+ void setParticleScale(float scale);
+ void addParticleScalePoint(float scale, float t);
+ void removeParticleScalePoint(uint i);
+
+ void setParticleColor(Color tint);
+ void addParticleColorPoint(Color tint, float t);
+ void removeParticleColorPoint(uint i);
+
+ void setParticleTransparency(float transparency);
+ void addParticleTransparencyPoint(float transparency, float t);
+ void removeParticleTransparencyPoint(uint i);
+
+ private:
+ friend class ParticleEmitter;
+
+ ///
+ /// Particle system position.
+ ///
+ Math::Vector2<float> mPosition;
+
+ ///
+ ///
+ ///
+ Particle* claim();
+
+ ///
+ ///
+ ///
+ void recycle(int i, Particle* p);
+
+ ///
+ /// Particle system definition.
+ ///
+ ParticleSystemDef mDef;
+
+ ///
+ /// Particle emitter.
+ ///
+ ParticleEmitter mEmitter;
+
+ ///
+ /// Particle pool.
+ ///
+ ParticlePool mParticlePool;
+
+ ///
+ /// Alive particles, that means these particles could join to the life cycle loop.
+ ///
+ std::vector<Particle*> mAliveParticles;
+
+ };
+
+ } // namespace Particles
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file