emitter delay and system deletion
This commit is contained in:
parent
9a5be9c4d8
commit
435161df62
|
@ -1,30 +1,92 @@
|
||||||
ParticleSystem
|
ParticleSystem
|
||||||
|
|
||||||
|
// continuous fire, yellow
|
||||||
|
Emitter
|
||||||
|
position: 100 100
|
||||||
|
duration: 8
|
||||||
|
delay: 0.1
|
||||||
|
burstRate: 0.03
|
||||||
|
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: 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: 128
|
||||||
|
particle-min-velocity-angle: 360
|
||||||
|
particle-max-velocity-angle: 380
|
||||||
|
|
||||||
|
particle-acceleration: 512
|
||||||
|
particle-acceleration-angle: 270
|
||||||
|
|
||||||
|
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
|
Emitter
|
||||||
position: 100 100
|
position: 100 100
|
||||||
duration: 9
|
duration: 9
|
||||||
burstRate: 0.03
|
burstRate: 0.03
|
||||||
burstCount: 1
|
burstCount: 1
|
||||||
|
|
||||||
|
particle-min-duration: 0.6
|
||||||
particle-size: 8 8
|
particle-max-duration: 1
|
||||||
|
|
||||||
particle-position-radius: 0
|
particle-position-radius: 0
|
||||||
particle-velocity-angle: 0
|
|
||||||
|
particle-velocity: 64
|
||||||
|
particle-min-velocity-angle: 290
|
||||||
|
particle-max-velocity-angle: 360
|
||||||
|
|
||||||
particle-acceleration: 0
|
particle-acceleration: 0
|
||||||
|
|
||||||
particle-color: #22940684
|
particle-size: 24 24
|
||||||
|
particle-color: #cccccc22
|
||||||
particle-texture: circle2.png
|
particle-texture: circle2.png
|
||||||
|
|
||||||
Emitter
|
|
||||||
position: 100 100
|
|
||||||
duration: 9
|
|
||||||
burstRate: 1
|
|
||||||
burstCount: 30
|
|
||||||
|
|
||||||
particle-size: 5 5
|
|
||||||
|
|
||||||
particle-position-radius: 0
|
|
||||||
particle-velocity-angle: 0
|
|
||||||
particle-acceleration-angle: 90
|
|
||||||
particle-color: #ff0000ff
|
|
||||||
particle-texture: circle2.png
|
|
||||||
|
|
|
@ -111,6 +111,8 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
|
||||||
|
|
||||||
if(m_appFlags & Fw::AppEnableModules)
|
if(m_appFlags & Fw::AppEnableModules)
|
||||||
g_modules.discoverModulesPath();
|
g_modules.discoverModulesPath();
|
||||||
|
|
||||||
|
g_particleManager.load("particle.otpa");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent)
|
||||||
|
|
||||||
m_position = Point(0, 0);
|
m_position = Point(0, 0);
|
||||||
m_duration = -1;
|
m_duration = -1;
|
||||||
|
m_delay = 0;
|
||||||
m_burstRate = 1; m_burstCount = 32;
|
m_burstRate = 1; m_burstCount = 32;
|
||||||
m_currentBurst = 0;
|
m_currentBurst = 0;
|
||||||
m_startTime = g_clock.time();
|
m_startTime = g_clock.time();
|
||||||
|
@ -68,6 +69,8 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
|
||||||
m_position = childNode->value<Point>();
|
m_position = childNode->value<Point>();
|
||||||
else if(childNode->tag() == "duration")
|
else if(childNode->tag() == "duration")
|
||||||
m_duration = childNode->value<float>();
|
m_duration = childNode->value<float>();
|
||||||
|
else if(childNode->tag() == "delay")
|
||||||
|
m_delay = childNode->value<float>();
|
||||||
else if(childNode->tag() == "burstRate")
|
else if(childNode->tag() == "burstRate")
|
||||||
m_burstRate = childNode->value<float>();
|
m_burstRate = childNode->value<float>();
|
||||||
else if(childNode->tag() == "burstCount")
|
else if(childNode->tag() == "burstCount")
|
||||||
|
@ -158,6 +161,13 @@ void ParticleEmitter::update()
|
||||||
{
|
{
|
||||||
float elapsedTime = g_clock.timeElapsed(m_startTime);
|
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
|
// check if finished
|
||||||
if(m_duration > 0 && elapsedTime > m_duration) {
|
if(m_duration > 0 && elapsedTime > m_duration) {
|
||||||
m_finished = true;
|
m_finished = true;
|
||||||
|
|
|
@ -32,6 +32,7 @@ class ParticleEmitter {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ParticleEmitter(const ParticleSystemPtr& parent);
|
ParticleEmitter(const ParticleSystemPtr& parent);
|
||||||
|
~ParticleEmitter() { dump << "ParticleEmitter deleted"; }
|
||||||
|
|
||||||
bool load(const OTMLNodePtr& node);
|
bool load(const OTMLNodePtr& node);
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ private:
|
||||||
|
|
||||||
// self related
|
// self related
|
||||||
Point m_position;
|
Point m_position;
|
||||||
int m_duration;
|
float m_duration, m_delay;
|
||||||
double m_startTime;
|
double m_startTime;
|
||||||
bool m_finished;
|
bool m_finished;
|
||||||
float m_burstRate;
|
float m_burstRate;
|
||||||
|
|
|
@ -35,7 +35,7 @@ bool ParticleManager::load(const std::string& filename)
|
||||||
if(node->tag() == "ParticleSystem") {
|
if(node->tag() == "ParticleSystem") {
|
||||||
ParticleSystemPtr particleSystem = ParticleSystemPtr(new ParticleSystem);
|
ParticleSystemPtr particleSystem = ParticleSystemPtr(new ParticleSystem);
|
||||||
particleSystem->load(node);
|
particleSystem->load(node);
|
||||||
m_particlesSystems.push_back(particleSystem);
|
m_particleSystems.push_back(particleSystem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -47,12 +47,21 @@ bool ParticleManager::load(const std::string& filename)
|
||||||
|
|
||||||
void ParticleManager::render()
|
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();
|
(*it)->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleManager::update()
|
void ParticleManager::update()
|
||||||
{
|
{
|
||||||
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)->update();
|
const ParticleSystemPtr& particleSystem = *it;
|
||||||
|
|
||||||
|
if(particleSystem->hasFinished()) {
|
||||||
|
it = m_particleSystems.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
particleSystem->update();
|
||||||
|
++it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<ParticleSystemPtr> m_particlesSystems;
|
std::list<ParticleSystemPtr> m_particleSystems;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ParticleManager g_particleManager;
|
extern ParticleManager g_particleManager;
|
||||||
|
|
|
@ -22,8 +22,11 @@
|
||||||
|
|
||||||
#include "particle.h"
|
#include "particle.h"
|
||||||
#include "particlesystem.h"
|
#include "particlesystem.h"
|
||||||
#include <framework/core/declarations.h>
|
|
||||||
#include <framework/ui/declarations.h>
|
ParticleSystem::ParticleSystem()
|
||||||
|
{
|
||||||
|
m_finished = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ParticleSystem::load(const OTMLNodePtr& node)
|
bool ParticleSystem::load(const OTMLNodePtr& node)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +53,12 @@ void ParticleSystem::render()
|
||||||
|
|
||||||
void ParticleSystem::update()
|
void ParticleSystem::update()
|
||||||
{
|
{
|
||||||
|
// check if finished
|
||||||
|
if(m_particles.empty() && m_emitters.empty()) {
|
||||||
|
m_finished = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// update emitters
|
// update emitters
|
||||||
for(auto it = m_emitters.begin(), end = m_emitters.end(); it != end;) {
|
for(auto it = m_emitters.begin(), end = m_emitters.end(); it != end;) {
|
||||||
const ParticleEmitterPtr& emitter = *it;
|
const ParticleEmitterPtr& emitter = *it;
|
||||||
|
|
|
@ -40,6 +40,9 @@ public:
|
||||||
|
|
||||||
class ParticleSystem : public std::enable_shared_from_this<ParticleSystem> {
|
class ParticleSystem : public std::enable_shared_from_this<ParticleSystem> {
|
||||||
public:
|
public:
|
||||||
|
ParticleSystem();
|
||||||
|
~ParticleSystem() { dump << "ParticleSystem deleted"; }
|
||||||
|
|
||||||
bool load(const OTMLNodePtr& node);
|
bool load(const OTMLNodePtr& node);
|
||||||
|
|
||||||
void addParticle(const ParticlePtr& particle);
|
void addParticle(const ParticlePtr& particle);
|
||||||
|
@ -47,7 +50,10 @@ public:
|
||||||
void render();
|
void render();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
bool hasFinished() { return m_finished; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_finished;
|
||||||
std::list<ParticlePtr> m_particles;
|
std::list<ParticlePtr> m_particles;
|
||||||
std::list<ParticleEmitterPtr> m_emitters;
|
std::list<ParticleEmitterPtr> m_emitters;
|
||||||
std::list<Affector> m_affectors;
|
std::list<Affector> m_affectors;
|
||||||
|
|
Loading…
Reference in New Issue