From 3b1ef055b169716a6358318824d39c4bb4938920 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Sat, 25 Sep 2010 14:38:00 +0000 Subject: [PATCH] - new switch for unit_particle _systems called static-particle-count - Bugfix for "wild particles". ( the splash particle systems never died before! ) - Better german language file ( cpu player have english words again, words like ultra are common enough in germany ) --- .../graphics/unit_particle_type.cpp | 20 ++++++++ .../glest_game/graphics/unit_particle_type.h | 1 + source/shared_lib/include/graphics/particle.h | 3 ++ .../shared_lib/sources/graphics/particle.cpp | 48 +++++++++++++++---- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index caa7c4aa..c15fc911 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -133,6 +133,15 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin relativeDirection=true; } + if(particleSystemNode->hasChild("static-particle-count")){ + //staticParticleCount + const XmlNode *staticParticleCountNode= particleSystemNode->getChild("static-particle-count"); + staticParticleCount= staticParticleCountNode->getAttribute("value")->getIntValue(); + } + else{ + staticParticleCount=0; + } + //fixed const XmlNode *fixedNode= particleSystemNode->getChild("fixed"); fixed= fixedNode->getAttribute("value")->getBoolValue(); @@ -186,8 +195,19 @@ void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ ups->setRelativeDirection(relativeDirection); ups->setTeamcolorNoEnergy(teamcolorNoEnergy); ups->setTeamcolorEnergy(teamcolorEnergy); + ups->setStaticParticleCount(staticParticleCount); ups->setRadius(radius); ups->setBlendMode(ParticleSystem::strToBlendMode(mode)); + //prepare system for given staticParticleCount + if(staticParticleCount>0) + { + ups->setEmissionRate(0.0f); + ups->setSpeed(0); + direction.x= 0.0f; + direction.y= 0.0f; + direction.z= 0.0f; + ups->setDirection(direction); + } } void UnitParticleSystemType::load(const string &dir, const string &path, RendererInterface *renderer){ diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index eedf6bd8..20b84f17 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -63,6 +63,7 @@ protected: bool fixed; bool teamcolorNoEnergy; bool teamcolorEnergy; + int staticParticleCount; string mode; public: diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 8662ac1e..fa0c8f14 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -211,6 +211,7 @@ private: Vec3f cRotation; Vec3f fixedAddition; Vec3f oldPosition; + bool energyUp; public: enum Primitive{ pQuad, @@ -227,6 +228,7 @@ public: float sizeNoEnergy; float gravity; float rotation; + int staticParticleCount; public: UnitParticleSystem(int particleCount= 2000); @@ -250,6 +252,7 @@ public: void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;} void setFixed(bool fixed) {this->fixed= fixed;} void setPrimitive(Primitive primitive) {this->primitive= primitive;} + void setStaticParticleCount(int staticParticleCount){this->staticParticleCount= staticParticleCount;} static Primitive strToPrimitive(const string &str); diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index fa2490ef..373833b4 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -58,7 +58,7 @@ ParticleSystem::ParticleSystem(int particleCount) { color= Vec4f(1.0f); colorNoEnergy= Vec4f(0.0f); emissionRate= 15.0f; - emissionState= 1.0f; + emissionState= 1.0f; // initialized with 1 because we must have at least one particle in the beginning! speed= 1.0f; teamcolorNoEnergy=false; teamcolorEnergy=false; @@ -102,11 +102,11 @@ void ParticleSystem::update() { initParticle(p, i); } emissionState=emissionState-(float)emissionIntValue; - if(aliveParticleCount==0){ - Particle *p = createParticle(); - initParticle(p, 0); - emissionState=0; - } +// if(aliveParticleCount==0){ +// Particle *p = createParticle(); +// initParticle(p, 0); +// emissionState=0; +// } } } @@ -380,10 +380,16 @@ UnitParticleSystem::UnitParticleSystem(int particleCount): ParticleSystem(partic rotation=0.0f; relativeDirection=true; relative=false; + staticParticleCount=0; cRotation= Vec3f(1.0f,1.0f,1.0f); fixedAddition = Vec3f(0.0f,0.0f,0.0f); - + //prepare system for given staticParticleCount + if(staticParticleCount>0) + { + emissionState= (float)staticParticleCount; + } + energyUp=false; } void UnitParticleSystem::render(ParticleRenderer *pr,ModelRenderer *mr){ @@ -492,7 +498,29 @@ void UnitParticleSystem::updateParticle(Particle *p){ p->speed+= p->accel; p->color = color * energyRatio + colorNoEnergy * (1.0f-energyRatio); p->size = particleSize * energyRatio + sizeNoEnergy * (1.0f-energyRatio); - p->energy--; + if(state == ParticleSystem::sFade || staticParticleCount<1) + { + p->energy--; + } + else + { + if(maxParticleEnergy>0) + { + if(energyUp){ + p->energy++; + } + else { + p->energy--; + } + + if(p->energy==1){ + energyUp=true; + } + if(p->energy==maxParticleEnergy){ + energyUp=false; + } + } + } /* p->lastPos= p->pos; @@ -876,6 +904,10 @@ void SplashParticleSystem::update(){ ParticleSystem::update(); if(state!=sPause){ emissionRate-= emissionRateFade; + if(emissionRate<0.0f) + {//otherwise this system lives forever! + fade(); + } } }