diff --git a/src/framework/graphics/declarations.h b/src/framework/graphics/declarations.h index 132d6343..9b0c3391 100644 --- a/src/framework/graphics/declarations.h +++ b/src/framework/graphics/declarations.h @@ -35,8 +35,12 @@ class FrameBuffer; class Shader; class ShaderProgram; class PainterShaderProgram; +class Particle; +class ParticleEmitter; +class ParticleSystem; typedef std::weak_ptr TextureWeakPtr; +typedef std::weak_ptr ParticleSystemWeakPtr; typedef std::shared_ptr TexturePtr; typedef std::shared_ptr AnimatedTexturePtr; @@ -47,6 +51,9 @@ typedef std::shared_ptr FrameBufferPtr; typedef std::shared_ptr ShaderPtr; typedef std::shared_ptr ShaderProgramPtr; typedef std::shared_ptr PainterShaderProgramPtr; +typedef std::shared_ptr ParticlePtr; +typedef std::shared_ptr ParticleEmitterPtr; +typedef std::shared_ptr ParticleSystemPtr; typedef std::vector ShaderList; #endif diff --git a/src/framework/graphics/particleemitter.cpp b/src/framework/graphics/particleemitter.cpp index 7c637ed5..d35d5f06 100644 --- a/src/framework/graphics/particleemitter.cpp +++ b/src/framework/graphics/particleemitter.cpp @@ -78,8 +78,10 @@ void Particle::update() m_rect.moveTo((int)m_pos.x, (int)m_pos.y); } -ParticleEmitter::ParticleEmitter() +ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent) { + m_parent = parent; + m_position = Point(0, 0); m_duration = -1; m_burstRate = 1; m_burstCount = 32; @@ -228,6 +230,7 @@ void ParticleEmitter::update() // every burst created at same position. float pRadius = Fw::randomRange(m_pMinPositionRadius, m_pMaxPositionRadius); float pAngle = Fw::randomRange(m_pMinPositionAngle, m_pMaxPositionAngle); + Point pPosition = m_position + Point(pRadius * cos(pAngle), pRadius * sin(pAngle)); for(int p = 0; p < m_burstCount; ++p) { diff --git a/src/framework/graphics/particleemitter.h b/src/framework/graphics/particleemitter.h index 6eb4f084..822eb298 100644 --- a/src/framework/graphics/particleemitter.h +++ b/src/framework/graphics/particleemitter.h @@ -23,6 +23,7 @@ #ifndef PARTICLEEMITTER_H #define PARTICLEEMITTER_H +#include "declarations.h" #include #include #include @@ -49,12 +50,11 @@ private: double m_lastUpdateTime; bool m_finished; }; -typedef std::shared_ptr ParticlePtr; class ParticleEmitter { public: - ParticleEmitter(); + ParticleEmitter(const ParticleSystemPtr& parent); bool load(const OTMLNodePtr& node); @@ -64,6 +64,8 @@ public: bool hasFinished() { return m_finished; } private: + ParticleSystemWeakPtr m_parent; + // self related Point m_position; int m_duration; @@ -95,6 +97,5 @@ private: Color m_pColor; TexturePtr m_pTexture; }; -typedef std::shared_ptr ParticleEmitterPtr; #endif diff --git a/src/framework/graphics/particlemanager.h b/src/framework/graphics/particlemanager.h index 6b22a03b..4b93ba74 100644 --- a/src/framework/graphics/particlemanager.h +++ b/src/framework/graphics/particlemanager.h @@ -23,6 +23,7 @@ #ifndef PARTICLEMANAGER_H #define PARTICLEMANAGER_H +#include "declarations.h" #include "particlesystem.h" class ParticleManager { diff --git a/src/framework/graphics/particlesystem.cpp b/src/framework/graphics/particlesystem.cpp index 6b0f5a5a..fc4a83f5 100644 --- a/src/framework/graphics/particlesystem.cpp +++ b/src/framework/graphics/particlesystem.cpp @@ -21,12 +21,14 @@ */ #include "particlesystem.h" +#include +#include bool ParticleSystem::load(const OTMLNodePtr& node) { for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "Emitter") { - ParticleEmitterPtr emitter = ParticleEmitterPtr(new ParticleEmitter); + ParticleEmitterPtr emitter = ParticleEmitterPtr(new ParticleEmitter(shared_from_this())); emitter->load(childNode); m_emitters.push_back(emitter); } diff --git a/src/framework/graphics/particlesystem.h b/src/framework/graphics/particlesystem.h index e4add03e..a0000211 100644 --- a/src/framework/graphics/particlesystem.h +++ b/src/framework/graphics/particlesystem.h @@ -23,6 +23,7 @@ #ifndef PARTICLESYSTEM_H #define PARTICLESYSTEM_H +#include "declarations.h" #include "particleemitter.h" class Affector { @@ -37,7 +38,7 @@ public: } }; -class ParticleSystem { +class ParticleSystem : public std::enable_shared_from_this { public: bool load(const OTMLNodePtr& node); @@ -48,6 +49,5 @@ private: std::list m_emitters; std::list m_affectors; }; -typedef std::shared_ptr ParticleSystemPtr; #endif