diff options
author | Stijn Buys <ingar@osirion.org> | 2013-01-27 17:24:16 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-01-27 17:24:16 +0000 |
commit | f4eee214a79634cdd2e6fe576950524170c01fa9 (patch) | |
tree | c00f9685202c5c4ae502e2a632d341643e5b1ba8 /src/render/particleejector.cc | |
parent | fd6663f0d3a4e860c14a0f3279fcce06d27fa283 (diff) |
Support for particle ejector timeout value,
do not draw destroyed entity models.,
Diffstat (limited to 'src/render/particleejector.cc')
-rw-r--r-- | src/render/particleejector.cc | 79 |
1 files changed, 45 insertions, 34 deletions
diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc index acec84f..29a255d 100644 --- a/src/render/particleejector.cc +++ b/src/render/particleejector.cc @@ -21,6 +21,7 @@ ParticleEjector::ParticleEjector(const ParticleEjectorScript &script) : Particle { ejector_last_eject = 0; ejector_enabled = true; + ejector_timestamp = 0; } ParticleEjector::~ParticleEjector() @@ -53,45 +54,55 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat // add new particles if (ejector_enabled) { - while (ejector_last_eject > interval()) { - math::Vector3f particle_location; - math::Axis particle_axis; - if (!attached()) { - particle_location.assign(ps_location); - particle_axis.assign(ps_axis); - } - particle_axis.change_roll(math::randomf(360.0f)); - if (cone() > 0) { - particle_axis.change_pitch(math::randomf(cone()) - (cone() * 0.5f) ); - } - if (spawn_radius() > 0) { - // FIXME find a faster formula - math::Axis random_axis(ps_axis); - random_axis.change_roll(math::randomf(360.0f)); - random_axis.change_pitch(math::randomf(180.0f)); - particle_location += random_axis.forward() * spawn_radius(); - } - - Particle *particle = new Particle(particle_location, particle_axis, now); - particle->set_radius(radius_vec()[0]); - particle->set_alpha(alpha_vec()[0]); - particle->set_rotation(math::randomf(2.0f * M_PI)); - particle->set_speed(math::randomf(speed_vec()[0], speed_vec()[1])); - particles().push_front(particle); + + if (!ejector_timestamp) { + ejector_timestamp = now; + } + + if (!timeout() || (ejector_timestamp + timeout() > now)) { - if (type() == Streak) { - Particle *tail = new Particle(particle_location, particle_axis, now); - tail->set_radius(radius_vec()[0]); - tail->set_alpha(alpha_vec()[0]); - tail->set_rotation(particle->rotation()); - tail->set_speed(math::randomf(tailspeed_vec()[0], tailspeed_vec()[1])); - particles().push_front(tail); + while (ejector_last_eject > interval()) { + math::Vector3f particle_location; + math::Axis particle_axis; + if (!attached()) { + particle_location.assign(ps_location); + particle_axis.assign(ps_axis); + } + particle_axis.change_roll(math::randomf(360.0f)); + if (cone() > 0) { + particle_axis.change_pitch(math::randomf(cone()) - (cone() * 0.5f) ); + } + if (spawn_radius() > 0) { + // FIXME find a faster formula + math::Axis random_axis(ps_axis); + random_axis.change_roll(math::randomf(360.0f)); + random_axis.change_pitch(math::randomf(180.0f)); + particle_location += random_axis.forward() * spawn_radius(); + } + + Particle *particle = new Particle(particle_location, particle_axis, now); + particle->set_radius(radius_vec()[0]); + particle->set_alpha(alpha_vec()[0]); + particle->set_rotation(math::randomf(2.0f * M_PI)); + particle->set_speed(math::randomf(speed_vec()[0], speed_vec()[1])); + particles().push_front(particle); + + if (type() == Streak) { + Particle *tail = new Particle(particle_location, particle_axis, now); + tail->set_radius(radius_vec()[0]); + tail->set_alpha(alpha_vec()[0]); + tail->set_rotation(particle->rotation()); + tail->set_speed(math::randomf(tailspeed_vec()[0], tailspeed_vec()[1])); + particles().push_front(tail); + } + + ejector_last_eject -= interval(); } - - ejector_last_eject -= interval(); } + } else { ejector_last_eject = 0; + ejector_timestamp = 0; } for (Particles::iterator it = particles().begin(); it != particles().end(); ++it) { |