From d6471bf0f398257cb379944323cf85e8115491a5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 13 Oct 2013 20:14:17 +0000 Subject: Axded explosion trigger for particle ejecotrs, fixed explosion particles for destroyed entities. --- src/render/draw.cc | 5 ++--- src/render/particleejectorscript.h | 18 ++++++++++++++++++ src/render/particlesystem.cc | 7 +++++-- src/render/particlesystem.h | 4 ++-- src/render/particlesystemscript.cc | 4 ++++ src/render/renderext.cc | 14 ++++++++++++-- src/render/renderext.h | 6 ++++++ 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/render/draw.cc b/src/render/draw.cc index 50d02a7..da0a063 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -1076,7 +1076,7 @@ void draw_pass_model_fx(float elapsed) for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); - + if (entity->model() && ext_render(entity)->detailvisible()) { // draw lights and flares @@ -1096,8 +1096,7 @@ void draw_pass_model_fx(float elapsed) for (RenderExt::ParticleSystems::iterator it = ext_render(entity)->particles().begin(); it != ext_render(entity)->particles().end(); ++it) { (*it)->draw(elapsed); } - } - + } } } diff --git a/src/render/particleejectorscript.h b/src/render/particleejectorscript.h index ef2be4c..4a06a84 100644 --- a/src/render/particleejectorscript.h +++ b/src/render/particleejectorscript.h @@ -108,6 +108,14 @@ public: { return script_impulse; } + + /** + * @brief true for a thrust impulse ejector + * */ + inline const bool explosion() const + { + return script_explosion; + } /** * @brief true if entity secondary color is to be applied to ejected particles @@ -423,6 +431,14 @@ public: { script_impulse = use_impulse; } + + /** + * @brief enable or disable explosion activated ejector + * */ + inline void set_explosion(const bool use_explosion) + { + script_explosion = use_explosion; + } /** * @brief ejector particles are drawn in entity coordinates @@ -509,6 +525,8 @@ private: bool script_thrust; /// impulse activated ejector bool script_impulse; + /// explosion activated ejector + bool script_explosion; /// ejector is attached to entity coordinates bool script_attached; /// ejector particles and speed are scaled according to modelscale diff --git a/src/render/particlesystem.cc b/src/render/particlesystem.cc index 7cf8f2f..1e3f13b 100644 --- a/src/render/particlesystem.cc +++ b/src/render/particlesystem.cc @@ -158,7 +158,7 @@ void ParticleSystem::draw(const float seconds) if (entity()) { bool ejector_active = true; - if (ejector->impulse() || ejector->thrust()) { + if (ejector->impulse() || ejector->thrust() || ejector->explosion()) { ejector_active = false; } @@ -182,7 +182,10 @@ void ParticleSystem::draw(const float seconds) break; default: - ejector_active = false; + // ejectors should be active to draw explosions + if (ejector->explosion()) { + ejector_active = true; + } break; } diff --git a/src/render/particlesystem.h b/src/render/particlesystem.h index 05bbe7d..974806f 100644 --- a/src/render/particlesystem.h +++ b/src/render/particlesystem.h @@ -56,12 +56,12 @@ public: return particlesystem_axis; } -private: inline Ejectors & ejectors() { return particlesystem_ejectors; } - + +private: float particlesystem_modelscale; math::Vector3f particlesystem_location; math::Axis particlesystem_axis; diff --git a/src/render/particlesystemscript.cc b/src/render/particlesystemscript.cc index 03ce86e..4c1f62b 100644 --- a/src/render/particlesystemscript.cc +++ b/src/render/particlesystemscript.cc @@ -235,6 +235,10 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label) ejector->set_impulse(b); continue; + } else if (inifile.got_key_bool("explosion", b)) { + ejector->set_impulse(b); + continue; + } else if (inifile.got_key_bool("entity", b)) { ejector->set_entity(b); continue; diff --git a/src/render/renderext.cc b/src/render/renderext.cc index 7ac5702..c66f036 100644 --- a/src/render/renderext.cc +++ b/src/render/renderext.cc @@ -168,17 +168,27 @@ void RenderExt::frame(float elapsed) const ParticleSystemScript *script = ParticleSystemScript::load("explosion"); if (script) { state_explosion = new ParticleSystem(script, entity(), 0); + + // forece all ejectors te explosion state + for (ParticleSystem::Ejectors::iterator it = state_explosion->ejectors().begin(); it != state_explosion->ejectors().end(); ++it) { + ParticleEjector *ejector = (*it); + ejector->set_explosion(true); + } + state_particles.push_back(state_explosion); } } } else { + if (state_explosion) { // remove explosion - for (ParticleSystems::iterator it = particles().begin(); state_explosion && (it != particles().end()); it++) { + for (ParticleSystems::iterator it = particles().begin(); state_explosion && (it != particles().end());) { if ((*it) == state_explosion) { - particles().erase(it); + particles().erase(it++); state_explosion = 0; + } else { + ++it; } } } diff --git a/src/render/renderext.h b/src/render/renderext.h index d140bbe..65fc5ed 100644 --- a/src/render/renderext.h +++ b/src/render/renderext.h @@ -69,7 +69,13 @@ public: return state_particles; } + + inline ParticleSystem *explosion() { + return state_explosion; + } + virtual void frame(float elapsed); + private: bool state_visible; -- cgit v1.2.3