From 65e457423c357aa789ffb2b7a76e73a75637e56b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 10 Mar 2014 17:28:41 +0100 Subject: [PATCH] Add option for particles to inherit alpha/color from their ParticleEffect --- Aquaria/GridRender.cpp | 11 +---------- BBGE/Emitter.cpp | 5 ++++- BBGE/ParticleEffect.cpp | 10 ++++++++++ BBGE/Particles.h | 2 ++ BBGE/SpawnParticleData.cpp | 2 ++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Aquaria/GridRender.cpp b/Aquaria/GridRender.cpp index 3ebcd41..2d604ac 100644 --- a/Aquaria/GridRender.cpp +++ b/Aquaria/GridRender.cpp @@ -166,16 +166,7 @@ void SongLineRender::newPoint(const Vector &pt, const Vector &color) s.color = color; pts.push_back(s); if (pts.size() > maxx) - { - std::vector copy; - copy = pts; - pts.clear(); - for (int i = 1; i < copy.size(); i++) - { - pts.push_back(copy[i]); - } - } - + pts.pop_front(); } else if (!pts.empty() && inRange) { diff --git a/BBGE/Emitter.cpp b/BBGE/Emitter.cpp index 31c693e..dc855cf 100644 --- a/BBGE/Emitter.cpp +++ b/BBGE/Emitter.cpp @@ -284,6 +284,8 @@ void Emitter::onRender() if (hasRot) { + Vector colorMult = data.inheritColor ? pe->color : Vector(1, 1, 1); + float alphaMult = data.inheritAlpha ? pe->alpha.x : 1; for (Particles::iterator i = particles.begin(); i != particles.end(); i++) { Particle *p = *i; @@ -293,7 +295,8 @@ void Emitter::onRender() const float dy = h2 * p->scale.y; #ifdef BBGE_BUILD_OPENGL - glColor4f(p->color.x, p->color.y, p->color.z, p->alpha.x); + Vector col = p->color * colorMult; + glColor4f(col.x, col.y, col.z, p->alpha.x * alphaMult); if (p->rot.z != 0 || p->rot.isInterpolating()) diff --git a/BBGE/ParticleEffect.cpp b/BBGE/ParticleEffect.cpp index 72dde64..7209a0c 100644 --- a/BBGE/ParticleEffect.cpp +++ b/BBGE/ParticleEffect.cpp @@ -404,6 +404,16 @@ void ParticleEffect::bankLoad(const std::string &file, const std::string &path) inf >> tmp; inf >> currentEmitter->data.suckIndex >> currentEmitter->data.suckStr; } + else if (token == "InheritColor") + { + inf >> tmp; + inf >> currentEmitter->data.inheritColor; + } + else if (token == "InheritAlpha") + { + inf >> tmp; + inf >> currentEmitter->data.inheritAlpha; + } } } } diff --git a/BBGE/Particles.h b/BBGE/Particles.h index 4eb8a90..21b96ee 100644 --- a/BBGE/Particles.h +++ b/BBGE/Particles.h @@ -72,6 +72,8 @@ struct SpawnParticleData float counter; float spawnTimeOffset; bool spawnLocal; + bool inheritColor; + bool inheritAlpha; float lastDTDifference; int groupRender; diff --git a/BBGE/SpawnParticleData.cpp b/BBGE/SpawnParticleData.cpp index 0c99aef..f6f89cd 100644 --- a/BBGE/SpawnParticleData.cpp +++ b/BBGE/SpawnParticleData.cpp @@ -70,4 +70,6 @@ SpawnParticleData::SpawnParticleData() groupRender = 0; pauseLevel = 0; copyParentFlip = 0; + inheritColor = false; + inheritAlpha = false; }