Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/particles.cc95
-rw-r--r--src/render/particles.h3
2 files changed, 60 insertions, 38 deletions
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 638b8b3..c232ca1 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -185,6 +185,11 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, con
ParticleSystem::~ParticleSystem()
{
+ clear();
+}
+
+void ParticleSystem::clear()
+{
for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
delete (*it);
}
@@ -193,24 +198,34 @@ ParticleSystem::~ParticleSystem()
void ParticleSystem::draw(float elapsed)
{
+ if (particlesystem_entity->type() == core::Entity::Controlable) {
+ core::EntityControlable *ec = static_cast<core::EntityControlable *>(particlesystem_entity);
+ if (ec->eventstate() == core::Entity::Docked) {
+ if (particlesystem_stream.size())
+ clear();
+ return;
+ }
+ }
+
now = core::application()->time();
ejector_location.assign(particlesystem_entity->location() + (particlesystem_entity->axis() * location()));
// remove dead particles
- Stream::iterator it = particlesystem_stream.begin();
- while ((it != particlesystem_stream.end()) && ((*it)->time() + particlesystem_script->timeout() <= now)) {
- delete (*it);
- particlesystem_stream.erase(it);
- it = particlesystem_stream.begin();
+ Stream::reverse_iterator it = particlesystem_stream.rbegin();
+ while ((it != particlesystem_stream.rend()) && ((*it)->time() + particlesystem_script->timeout() <= now)) {
+ delete (*particlesystem_stream.rbegin());
+ particlesystem_stream.pop_back();
+ it = particlesystem_stream.rbegin();
}
// apply speed
bool ejector_active = false;
if (particlesystem_script->speed()) {
- for (Stream::reverse_iterator rit = particlesystem_stream.rbegin(); rit != particlesystem_stream.rend(); rit++) {
- Particle *particle = (*rit);
+ for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
+ Particle *particle = (*it);
particle->location() += particle->axis().forward() * particlesystem_script->speed() * elapsed;
}
+ ejector_active = true;
} else {
if (particlesystem_entity->type() == core::Entity::Dynamic) {
core::EntityDynamic *ed = static_cast<core::EntityDynamic *>(particlesystem_entity);
@@ -227,7 +242,7 @@ void ParticleSystem::draw(float elapsed)
// add new particles
if (ejector_active && (particlesystem_last_eject + particlesystem_script->eject() <= now)) {
- particlesystem_stream.push_back(new Particle(ejector_location, particlesystem_entity->axis() * particlesystem_axis, now));
+ particlesystem_stream.push_front(new Particle(ejector_location, particlesystem_entity->axis() * particlesystem_axis, now));
particlesystem_last_eject = now;
}
}
@@ -253,8 +268,8 @@ void Jet::draw(float elapsed) {
Textures::bind(particlesystem_texture);
gl::begin(gl::Quads);
- for (Stream::reverse_iterator rit = particlesystem_stream.rbegin(); rit != particlesystem_stream.rend(); rit++) {
- Particle *particle = (*rit);
+ for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
+ Particle *particle = (*it);
quad[0].assign(particle->axis().up() - particle->axis().left());
quad[1].assign(particle->axis().up() + particle->axis().left());
@@ -308,14 +323,14 @@ void Trail::draw(float elapsed) {
ParticleSystem::draw(elapsed);
- if (particlesystem_stream.size() > 1) {
+ if (particlesystem_stream.size()) {
Textures::bind(particlesystem_texture);
gl::begin(gl::Quads);
- Stream::reverse_iterator previous = particlesystem_stream.rbegin();
+ Stream::iterator first = particlesystem_stream.begin();
- float tp = now - (*previous)->time();
+ float tp = now - (*first)->time();
float fp = 0;
if (tp < particlesystem_script->timeout() * 0.1f) {
@@ -326,8 +341,27 @@ void Trail::draw(float elapsed) {
fp = 1.0 - fp;
}
- Stream::reverse_iterator next = previous;
- for (next++; next != particlesystem_stream.rend(); next++) {
+ if (tp > 0) {
+ color.a = 0.0f;
+ gl::color(color);
+
+ glTexCoord2f(1,0);
+ gl::vertex(ejector_location);
+ glTexCoord2f(0,0);
+ gl::vertex(ejector_location);
+
+ color.a = fp;
+ gl::color(color);
+
+ glTexCoord2f(0,1);
+ gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_script->radius() * fp);
+ glTexCoord2f(1,1);
+ gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_script->radius() * fp);
+ Stats::quads++;
+ }
+
+ Stream::iterator next = first;
+ for (next++; next != particlesystem_stream.end(); next++) {
float t = now - (*next)->time();
float f = 0;
@@ -340,44 +374,29 @@ void Trail::draw(float elapsed) {
f = 1.0 - f;
}
- color.a = f * particlesystem_script->alpha();
+ color.a = fp * particlesystem_script->alpha();
gl::color(color);
glTexCoord2f(1,0);
- gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_script->radius() * f);
+ gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_script->radius() * fp);
glTexCoord2f(0,0);
- gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_script->radius() * f);
+ gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_script->radius() * fp);
- color.a = fp * particlesystem_script->alpha();
+ color.a = f * particlesystem_script->alpha();
gl::color(color);
glTexCoord2f(0,1);
- gl::vertex((*previous)->location() + (*previous)->axis().left() * particlesystem_script->radius() * fp);
+ gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_script->radius() * f);
glTexCoord2f(1,1);
- gl::vertex((*previous)->location() - (*previous)->axis().left() * particlesystem_script->radius() * fp);
+ gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_script->radius() * f);
+
Stats::quads++;
- previous = next;
+ first = next;
fp = f;
tp = t;
}
- color.a = 0.0f;
- gl::color(color);
-
- glTexCoord2f(1,0);
- gl::vertex(ejector_location);
- glTexCoord2f(0,0);
- gl::vertex(ejector_location);
-
- color.a = fp;
- gl::color(color);
-
- glTexCoord2f(0,1);
- gl::vertex((*previous)->location() + (*previous)->axis().left() * particlesystem_script->radius() * fp);
- glTexCoord2f(1,1);
- gl::vertex((*previous)->location() - (*previous)->axis().left() * particlesystem_script->radius() * fp);
- Stats::quads++;
gl::end();
}
diff --git a/src/render/particles.h b/src/render/particles.h
index e74c3d8..0044832 100644
--- a/src/render/particles.h
+++ b/src/render/particles.h
@@ -113,6 +113,9 @@ public:
void set_eject(float eject);
+ /// clear all particles
+ void clear();
+
protected:
core::Entity *particlesystem_entity;