From 3126a1096654780ed6fea9bc2e1e27019cadd857 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 19 Sep 2013 20:03:36 +0000 Subject: [PATCH] - added code to be able to properly render attack particles when unit is not visible (turned off for now due to questions) --- source/glest_game/type_instances/unit.cpp | 17 +++++++++++++++++ source/glest_game/type_instances/unit.h | 3 +++ source/glest_game/world/unit_updater.cpp | 2 ++ source/shared_lib/sources/graphics/particle.cpp | 1 + 4 files changed, 23 insertions(+) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 3e9fe227a..23fa2df20 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -560,6 +560,8 @@ Unit::~Unit() { Renderer::getInstance().cleanupParticleSystems(fireParticleSystems,rsGame); // Must set this to null of it will be used below in stopDamageParticles() + Renderer::getInstance().cleanupParticleSystems(attackParticleSystems,rsGame); + if(Renderer::getInstance().validateParticleSystemStillExists(this->fire,rsGame) == false) { this->fire = NULL; } @@ -1252,6 +1254,10 @@ void Unit::setTargetPos(const Vec2i &targetPos) { logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__); } +void Unit::addAttackParticleSystem(ParticleSystem *ps) { + attackParticleSystems.push_back(ps); +} + void Unit::setVisible(const bool visible) { this->visible = visible; @@ -1279,6 +1285,17 @@ void Unit::setVisible(const bool visible) { } } } + + if(attackParticleSystems.empty() == false) { + for(vector::iterator it= attackParticleSystems.begin(); it != attackParticleSystems.end(); ++it) { + if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { + // Not sure this is a good idea since the unit be not be visible but the attack particle might be. + // This means you won't see the attacking projectile until the unit moves into view. + //(*it)->setVisible(visible); + } + } + } + if(currentAttackBoostEffects.empty() == false) { for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index ee30066bc..e70b67beb 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -408,6 +408,7 @@ private: vector fireParticleSystems; vector smokeParticleSystems; + vector attackParticleSystems; CardinalDir modelFacing; @@ -771,6 +772,8 @@ public: void clearCaches(); bool showTranslatedTechTree() const; + void addAttackParticleSystem(ParticleSystem *ps); + Checksum getCRC(); private: diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index aabb9e8e9..7c4e81f3a 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2299,6 +2299,7 @@ void UnitUpdater::startAttackParticleSystem(Unit *unit){ psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } renderer.manageParticleSystem(psProj, rsGame); + unit->addAttackParticleSystem(psProj); } else{ hit(unit); @@ -2316,6 +2317,7 @@ void UnitUpdater::startAttackParticleSystem(Unit *unit){ if(pstProj!=NULL){ psProj->link(psSplash); } + unit->addAttackParticleSystem(psSplash); } } diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 28431e85b..a6e519a5f 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -1470,6 +1470,7 @@ void ProjectileParticleSystem::link(SplashParticleSystem *particleSystem){ } void ProjectileParticleSystem::update(){ + //printf("Projectile particle system updating...\n"); if(state == sPlay){ lastPos= pos;