diff --git a/modules/particle.otpa b/modules/particle.otpa index f738b850..9b5f316c 100644 --- a/modules/particle.otpa +++ b/modules/particle.otpa @@ -1,30 +1,92 @@ ParticleSystem + + // continuous fire, yellow Emitter position: 100 100 - duration: 9 + duration: 8 + delay: 0.1 burstRate: 0.03 - burstCount: 1 + burstCount: 5 + particle-min-duration: 0.6 + particle-max-duration: 0.8 + particle-position-radius: 0 + + particle-velocity: 96 + particle-min-velocity-angle: 310 + particle-max-velocity-angle: 340 + + particle-acceleration: 0 - particle-size: 8 8 + particle-size: 24 24 + particle-color: #ffff0044 + particle-texture: circle2.png + + // fire ball, up side, orange + Emitter + position: 100 100 + duration: 0.5 + delay: 0.1 + burstRate: 0.01 + burstCount: 6 + particle-min-duration: 0.1 + particle-max-duration: 0.3 particle-position-radius: 0 - particle-velocity-angle: 0 - particle-acceleration: 0 + + particle-velocity: 128 + particle-min-velocity-angle: 360 + particle-max-velocity-angle: 380 + + particle-acceleration: 512 + particle-acceleration-angle: 270 - particle-color: #22940684 + particle-size: 24 24 + particle-color: #ffa50044 particle-texture: circle2.png + + // fire ball, down side, orange + Emitter + position: 100 100 + duration: 0.5 + delay: 0.1 + burstRate: 0.01 + burstCount: 6 + particle-min-duration: 0.1 + particle-max-duration: 0.3 + particle-position-radius: 0 + + particle-velocity: 128 + particle-min-velocity-angle: 270 + particle-max-velocity-angle: 290 + + particle-acceleration: 512 + particle-acceleration-angle: 45 + + particle-size: 24 24 + particle-color: #ffa50044 + particle-texture: circle2.png + + // smoke Emitter position: 100 100 duration: 9 - burstRate: 1 - burstCount: 30 - - particle-size: 5 5 + burstRate: 0.03 + burstCount: 1 + particle-min-duration: 0.6 + particle-max-duration: 1 particle-position-radius: 0 - particle-velocity-angle: 0 - particle-acceleration-angle: 90 - particle-color: #ff0000ff + + particle-velocity: 64 + particle-min-velocity-angle: 290 + particle-max-velocity-angle: 360 + + particle-acceleration: 0 + + particle-size: 24 24 + particle-color: #cccccc22 particle-texture: circle2.png + + diff --git a/src/framework/application.cpp b/src/framework/application.cpp index 7afa00f4..aff7363f 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -111,6 +111,8 @@ void Application::init(const std::vector& args, int appFlags) if(m_appFlags & Fw::AppEnableModules) g_modules.discoverModulesPath(); + + g_particleManager.load("particle.otpa"); } diff --git a/src/framework/graphics/particleemitter.cpp b/src/framework/graphics/particleemitter.cpp index b3089f77..76f38e85 100644 --- a/src/framework/graphics/particleemitter.cpp +++ b/src/framework/graphics/particleemitter.cpp @@ -35,6 +35,7 @@ ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent) m_position = Point(0, 0); m_duration = -1; + m_delay = 0; m_burstRate = 1; m_burstCount = 32; m_currentBurst = 0; m_startTime = g_clock.time(); @@ -68,6 +69,8 @@ bool ParticleEmitter::load(const OTMLNodePtr& node) m_position = childNode->value(); else if(childNode->tag() == "duration") m_duration = childNode->value(); + else if(childNode->tag() == "delay") + m_delay = childNode->value(); else if(childNode->tag() == "burstRate") m_burstRate = childNode->value(); else if(childNode->tag() == "burstCount") @@ -158,6 +161,13 @@ void ParticleEmitter::update() { float elapsedTime = g_clock.timeElapsed(m_startTime); + // only start updating after delay + if(elapsedTime < m_delay) + return; + + // setup a new start time + elapsedTime -= m_delay; + // check if finished if(m_duration > 0 && elapsedTime > m_duration) { m_finished = true; diff --git a/src/framework/graphics/particleemitter.h b/src/framework/graphics/particleemitter.h index fefed036..e1dbf9a1 100644 --- a/src/framework/graphics/particleemitter.h +++ b/src/framework/graphics/particleemitter.h @@ -32,6 +32,7 @@ class ParticleEmitter { public: ParticleEmitter(const ParticleSystemPtr& parent); + ~ParticleEmitter() { dump << "ParticleEmitter deleted"; } bool load(const OTMLNodePtr& node); @@ -44,7 +45,7 @@ private: // self related Point m_position; - int m_duration; + float m_duration, m_delay; double m_startTime; bool m_finished; float m_burstRate; diff --git a/src/framework/graphics/particlemanager.cpp b/src/framework/graphics/particlemanager.cpp index b46786cc..86680ab5 100644 --- a/src/framework/graphics/particlemanager.cpp +++ b/src/framework/graphics/particlemanager.cpp @@ -35,7 +35,7 @@ bool ParticleManager::load(const std::string& filename) if(node->tag() == "ParticleSystem") { ParticleSystemPtr particleSystem = ParticleSystemPtr(new ParticleSystem); particleSystem->load(node); - m_particlesSystems.push_back(particleSystem); + m_particleSystems.push_back(particleSystem); } } return true; @@ -47,12 +47,21 @@ bool ParticleManager::load(const std::string& filename) void ParticleManager::render() { - for(auto it = m_particlesSystems.begin(), end = m_particlesSystems.end(); it != end; ++it) + for(auto it = m_particleSystems.begin(), end = m_particleSystems.end(); it != end; ++it) (*it)->render(); } void ParticleManager::update() { - for(auto it = m_particlesSystems.begin(), end = m_particlesSystems.end(); it != end; ++it) - (*it)->update(); + for(auto it = m_particleSystems.begin(), end = m_particleSystems.end(); it != end;) { + const ParticleSystemPtr& particleSystem = *it; + + if(particleSystem->hasFinished()) { + it = m_particleSystems.erase(it); + continue; + } + + particleSystem->update(); + ++it; + } } diff --git a/src/framework/graphics/particlemanager.h b/src/framework/graphics/particlemanager.h index 4b93ba74..d904f164 100644 --- a/src/framework/graphics/particlemanager.h +++ b/src/framework/graphics/particlemanager.h @@ -34,7 +34,7 @@ public: void update(); private: - std::list m_particlesSystems; + std::list m_particleSystems; }; extern ParticleManager g_particleManager; diff --git a/src/framework/graphics/particlesystem.cpp b/src/framework/graphics/particlesystem.cpp index 01d77c20..6355d482 100644 --- a/src/framework/graphics/particlesystem.cpp +++ b/src/framework/graphics/particlesystem.cpp @@ -22,8 +22,11 @@ #include "particle.h" #include "particlesystem.h" -#include -#include + +ParticleSystem::ParticleSystem() +{ + m_finished = false; +} bool ParticleSystem::load(const OTMLNodePtr& node) { @@ -50,6 +53,12 @@ void ParticleSystem::render() void ParticleSystem::update() { + // check if finished + if(m_particles.empty() && m_emitters.empty()) { + m_finished = true; + return; + } + // update emitters for(auto it = m_emitters.begin(), end = m_emitters.end(); it != end;) { const ParticleEmitterPtr& emitter = *it; diff --git a/src/framework/graphics/particlesystem.h b/src/framework/graphics/particlesystem.h index 934a14cc..221f9e92 100644 --- a/src/framework/graphics/particlesystem.h +++ b/src/framework/graphics/particlesystem.h @@ -40,6 +40,9 @@ public: class ParticleSystem : public std::enable_shared_from_this { public: + ParticleSystem(); + ~ParticleSystem() { dump << "ParticleSystem deleted"; } + bool load(const OTMLNodePtr& node); void addParticle(const ParticlePtr& particle); @@ -47,7 +50,10 @@ public: void render(); void update(); + bool hasFinished() { return m_finished; } + private: + bool m_finished; std::list m_particles; std::list m_emitters; std::list m_affectors;