diff options
Diffstat (limited to 'src/libjin/Graphics/particles/je_particle_system.cpp')
-rw-r--r-- | src/libjin/Graphics/particles/je_particle_system.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/libjin/Graphics/particles/je_particle_system.cpp b/src/libjin/Graphics/particles/je_particle_system.cpp index 68f8f21..a81a3c9 100644 --- a/src/libjin/Graphics/particles/je_particle_system.cpp +++ b/src/libjin/Graphics/particles/je_particle_system.cpp @@ -4,8 +4,64 @@ namespace JinEngine { namespace Graphics { + namespace Particles + { + ParticleSystem::ParticleSystem(const ParticleSystemDef& def) + : mDef(def) + , mEmitter(*this) + , mParticlePool(def.maxParticleCount, sizeof(Particle)) + { + } + ParticleSystem::~ParticleSystem() + { + } + void ParticleSystem::update(float dt) + { + mEmitter.update(dt); + for (int i = 0; i < mAliveParticles.size(); ++i) + { + Particle* p = mAliveParticles[i]; + if (p->alive == false) + { + recycle(i, p); + --i; + } + else + { + p->update(dt); + } + } + } + + void ParticleSystem::render(float x, float y, float sx /* = 1 */, float sy /* = 1 */, float r /* = 0 */, float ax /* = 0 */, float ay /* = 0 */) + { + for (Particle* p : mAliveParticles) + p->render(); + } + + void ParticleSystem::setGraphic(const Graphic* graphic) + { + mGraphic = graphic; + } + + Particle* ParticleSystem::claim() + { + Particle* p = new (mParticlePool.GetNextWithoutInitializing()) Particle(mGraphic); + mAliveParticles.push_back(p); + return p; + } + + void ParticleSystem::recycle(int i, Particle* p) + { + if (i >= mAliveParticles.size()) + return; + mAliveParticles.erase(mAliveParticles.begin() + i); + mParticlePool.Delete(p); + } + + } } -} +}
\ No newline at end of file |