diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 109da64ba..c1aebdd3a 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -43,7 +43,8 @@ ParticleSystemType::ParticleSystemType() { teamcolorNoEnergy=false; teamcolorEnergy=false; - alternations=false; + alternations=0; + particleSystemStartDelay=0; texture=NULL; model=NULL; minmaxEnabled=false; @@ -101,6 +102,7 @@ void ParticleSystemType::copyAll(const ParticleSystemType &src) { this->teamcolorNoEnergy = src.teamcolorNoEnergy; this->teamcolorEnergy = src.teamcolorEnergy; this->alternations = src.alternations; + this->particleSystemStartDelay= src.particleSystemStartDelay; for(Children::iterator it = children.begin(); it != children.end(); ++it) { UnitParticleSystemType *child = *it; @@ -239,6 +241,11 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d const XmlNode *alternatingNode= particleSystemNode->getChild("alternations"); alternations= alternatingNode->getAttribute("value")->getIntValue(); } + //particleSystemStartDelay + if(particleSystemNode->hasChild("particleSystemStartDelay")){ + const XmlNode *node= particleSystemNode->getChild("particleSystemStartDelay"); + particleSystemStartDelay= node->getAttribute("value")->getIntValue(); + } //mode if(particleSystemNode->hasChild("mode")) { const XmlNode *modeNode= particleSystemNode->getChild("mode"); @@ -293,6 +300,7 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){ ats->setTeamcolorNoEnergy(teamcolorNoEnergy); ats->setTeamcolorEnergy(teamcolorEnergy); ats->setAlternations(alternations); + ats->setParticleSystemStartDelay(particleSystemStartDelay); ats->setBlendMode(ParticleSystem::strToBlendMode(mode)); } diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index 62b37fc0f..6d3ecc7e6 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -69,6 +69,7 @@ protected: bool teamcolorNoEnergy; bool teamcolorEnergy; int alternations; + int particleSystemStartDelay; typedef std::list Children; Children children; diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 324de6f99..f39167ed0 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -839,7 +839,7 @@ void Renderer::setupLighting() { assertGl(); //sun/moon light - Vec3f lightColor= computeLightColor(time); + Vec3f lightColor= timeFlow->computeLightColor(); Vec3f fogColor= world->getTileset()->getFogColor(); Vec4f lightPos= timeFlow->isDay()? computeSunPos(time): computeMoonPos(time); nearestLightPos= lightPos; @@ -4183,7 +4183,7 @@ void Renderer::renderObjects(const int renderFps) { const Texture2D *fowTex = world->getMinimap()->getFowTexture(); const Pixmap2D *fowTexPixmap = fowTex->getPixmapConst(); - Vec3f baseFogColor = world->getTileset()->getFogColor() * computeLightColor(world->getTimeFlow()->getTime()); + Vec3f baseFogColor = world->getTileset()->getFogColor() * world->getTimeFlow()->computeLightColor(); bool modelRenderStarted = false; @@ -6461,35 +6461,6 @@ Vec4f Renderer::computeMoonPos(float time) { #endif } -Vec3f Renderer::computeLightColor(float time) { - const Tileset *tileset= game->getWorld()->getTileset(); - Vec3f color; - - const float transition= 2; - const float dayStart= TimeFlow::dawn; - const float dayEnd= TimeFlow::dusk-transition; - const float nightStart= TimeFlow::dusk; - const float nightEnd= TimeFlow::dawn-transition; - - if(time>dayStart && timegetSunLightColor(); - } - else if(time>nightStart || timegetMoonLightColor(); - } - else if(time>=dayEnd && time<=nightStart) { - color= tileset->getSunLightColor().lerp((time-dayEnd)/transition, tileset->getMoonLightColor()); - } - else if(time>=nightEnd && time<=dayStart) { - color= tileset->getMoonLightColor().lerp((time-nightEnd)/transition, tileset->getSunLightColor()); - } - else { - assert(false); - color= tileset->getSunLightColor(); - } - return color; -} - Vec4f Renderer::computeWaterColor(float waterLevel, float cellHeight) { const float waterFactor= 1.5f; return Vec4f(1.f, 1.f, 1.f, clamp((waterLevel-cellHeight)*waterFactor, 0.f, 1.f)); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 849329988..b0603a30d 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -581,7 +581,6 @@ private: float computeMoonAngle(float time); Vec4f computeSunPos(float time); Vec4f computeMoonPos(float time); - Vec3f computeLightColor(float time); Vec4f computeWaterColor(float waterLevel, float cellHeight); void checkExtension(const string &extension, const string &msg); diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index cecbc1c05..d42fe8d83 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -40,8 +40,9 @@ UnitParticleSystemType::UnitParticleSystemType() : ParticleSystemType() { relativeDirection = false; fixed = false; staticParticleCount = 0; - isVisibleAtNight = false; - isVisibleAtDay = false; + isVisibleAtNight = true; + isVisibleAtDay = true; + isDaylightAffected = false; radiusBasedStartenergy = false; delay = 0; lifetime = 0; @@ -146,6 +147,15 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin isVisibleAtDay=true; } + //isDaylightAffected + if(particleSystemNode->hasChild("isDaylightAffected")){ + const XmlNode *node= particleSystemNode->getChild("isDaylightAffected"); + isDaylightAffected= node->getAttribute("value")->getBoolValue(); + } + else { + isDaylightAffected=false; + } + //radiusBasedStartenergy if(particleSystemNode->hasChild("radiusBasedStartenergy")){ const XmlNode *isVisibleAtDayNode= particleSystemNode->getChild("radiusBasedStartenergy"); @@ -217,9 +227,11 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ ups->setTeamcolorNoEnergy(teamcolorNoEnergy); ups->setTeamcolorEnergy(teamcolorEnergy); ups->setAlternations(alternations); + ups->setParticleSystemStartDelay(particleSystemStartDelay); ups->setIsVisibleAtNight(isVisibleAtNight); ups->setIsVisibleAtDay(isVisibleAtDay); + ups->setIsDaylightAffected(isDaylightAffected); ups->setStaticParticleCount(staticParticleCount); ups->setRadius(radius); ups->setMinRadius(minRadius); diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index 00c4ef794..a3e500161 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -58,6 +58,7 @@ protected: int staticParticleCount; bool isVisibleAtNight; bool isVisibleAtDay; + bool isDaylightAffected; bool radiusBasedStartenergy; int delay; int lifetime; diff --git a/source/glest_game/world/time_flow.cpp b/source/glest_game/world/time_flow.cpp index d060dcf9c..8287f92e9 100644 --- a/source/glest_game/world/time_flow.cpp +++ b/source/glest_game/world/time_flow.cpp @@ -55,6 +55,7 @@ void TimeFlow::update() { soundRenderer.stopAmbient(ambientSounds->getNight()); UnitParticleSystem::isNight=false; } + UnitParticleSystem::lightColor=computeLightColor(); if((lastTime=dawn) || firstTime){ @@ -94,4 +95,35 @@ void TimeFlow::update() { // return (this->time>=time) && (this->timedayStart && timegetSunLightColor(); + } + else if(time>nightStart || timegetMoonLightColor(); + } + else if(time>=dayEnd && time<=nightStart) { + color= tileset->getSunLightColor().lerp((time-dayEnd)/transition, tileset->getMoonLightColor()); + } + else if(time>=nightEnd && time<=dayStart) { + color= tileset->getMoonLightColor().lerp((time-nightEnd)/transition, tileset->getSunLightColor()); + } + else { + assert(false); + color= tileset->getSunLightColor(); + } + return color; +} + + }}//end namespace diff --git a/source/glest_game/world/time_flow.h b/source/glest_game/world/time_flow.h index b099ce6a4..5090d3a3d 100644 --- a/source/glest_game/world/time_flow.h +++ b/source/glest_game/world/time_flow.h @@ -57,6 +57,7 @@ public: bool isTotalNight() const {return timedusk-1.f;} float getTimeInc() const {return timeInc;} + Vec3f computeLightColor() const; void update(); private: //bool isAproxTime(float time) const; diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 76471a6b6..201483e19 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -132,6 +132,7 @@ protected: bool teamcolorNoEnergy; bool teamcolorEnergy; int alternations; + int particleSystemStartDelay; ParticleObserver *particleObserver; public: @@ -173,6 +174,7 @@ public: void setTeamcolorNoEnergy(bool teamcolorNoEnergy) {this->teamcolorNoEnergy= teamcolorNoEnergy;} void setTeamcolorEnergy(bool teamcolorEnergy) {this->teamcolorEnergy= teamcolorEnergy;} void setAlternations(int alternations) {this->alternations= alternations;} + void setParticleSystemStartDelay(int delay) {this->particleSystemStartDelay= delay;} virtual void setFactionColor(Vec3f factionColor); static BlendMode strToBlendMode(const string &str); @@ -269,6 +271,7 @@ protected: class UnitParticleSystem: public GameParticleSystem{ public: static bool isNight; + static Vec3f lightColor; private: float radius; float minRadius; @@ -296,6 +299,7 @@ public: float rotation; bool isVisibleAtNight; bool isVisibleAtDay; + bool isDaylightAffected; bool radiusBasedStartenergy; int staticParticleCount; int delay; @@ -339,6 +343,7 @@ public: void setPrimitive(Primitive primitive) {this->primitive= primitive;} void setStaticParticleCount(int staticParticleCount){this->staticParticleCount= staticParticleCount;} void setIsVisibleAtNight(bool value) {this->isVisibleAtNight= value;} + void setIsDaylightAffected(bool value) {this->isDaylightAffected= value;} void setIsVisibleAtDay(bool value) {this->isVisibleAtDay= value;} void setRadiusBasedStartenergy(bool value) {this->radiusBasedStartenergy= value;} void setShape(Shape shape) {this->shape= shape;} diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 0a0a8a0e8..b0cf55bb5 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -74,6 +74,7 @@ ParticleSystem::ParticleSystem(int particleCount) { teamcolorNoEnergy= false; teamcolorEnergy= false; alternations= 0; + particleSystemStartDelay= 0; } ParticleSystem::~ParticleSystem(){ @@ -97,8 +98,10 @@ void ParticleSystem::update(){ if(aliveParticleCount > (int) particles.size()){ throw runtime_error("aliveParticleCount >= particles.size()"); } - - if(state != sPause){ + if(particleSystemStartDelay>0){ + particleSystemStartDelay--; + } + else if(state != sPause){ for(int i= 0; i < aliveParticleCount; ++i){ updateParticle(&particles[i]); @@ -527,6 +530,7 @@ void GameParticleSystem::setTween(float relative,float absolute) { // UnitParticleSystem // =========================================================================== bool UnitParticleSystem::isNight= false; +Vec3f UnitParticleSystem::lightColor=Vec3f(1.0f,1.0f,1.0f); UnitParticleSystem::UnitParticleSystem(int particleCount): GameParticleSystem(particleCount), @@ -549,6 +553,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount): isVisibleAtNight= true; isVisibleAtDay= true; + isDaylightAffected= false; cRotation= Vec3f(1.0f, 1.0f, 1.0f); fixedAddition= Vec3f(0.0f, 0.0f, 0.0f); @@ -736,6 +741,12 @@ void UnitParticleSystem::updateParticle(Particle *p){ } p->speed+= p->accel; p->color= color * energyRatio + colorNoEnergy * (1.0f - energyRatio); + if(isDaylightAffected) + { + p->color.x=p->color.x*lightColor.x; + p->color.y=p->color.y*lightColor.y; + p->color.z=p->color.z*lightColor.z; + } p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); if(state == ParticleSystem::sFade || staticParticleCount < 1){ p->energy--;