diff options
| author | chai <chaifix@163.com> | 2018-11-18 23:31:17 +0800 |
|---|---|---|
| committer | chai <chaifix@163.com> | 2018-11-18 23:31:17 +0800 |
| commit | f0f340dec7821cee103ab9267ef941a917ef4dc4 (patch) | |
| tree | 2f77f6ce6bdc9f63f002c13d4c261e1d6a9c1729 /src/libjin/graphics/particles/je_particle_system.cpp | |
| parent | fc7b4579e49aaeecc81919e247e03f68bd5abfd4 (diff) | |
*目录改为小写
Diffstat (limited to 'src/libjin/graphics/particles/je_particle_system.cpp')
| -rw-r--r-- | src/libjin/graphics/particles/je_particle_system.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/libjin/graphics/particles/je_particle_system.cpp b/src/libjin/graphics/particles/je_particle_system.cpp new file mode 100644 index 0000000..a81a3c9 --- /dev/null +++ b/src/libjin/graphics/particles/je_particle_system.cpp @@ -0,0 +1,67 @@ +#include "je_particle_system.h" + +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 |
