From 732887516035015543b3e0594f654fd7e59e1463 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 11 Apr 2012 05:18:00 +0000 Subject: [PATCH] - bugfix for rain effect, now dynamically turns on/off when toggled in menu and hopefully fixes strange water splash bug --- source/glest_game/menu/menu_background.cpp | 65 ++++++++++++++++------ source/glest_game/menu/menu_background.h | 3 + 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/source/glest_game/menu/menu_background.cpp b/source/glest_game/menu/menu_background.cpp index b6b87691..72ec9e87 100644 --- a/source/glest_game/menu/menu_background.cpp +++ b/source/glest_game/menu/menu_background.cpp @@ -32,8 +32,7 @@ namespace Glest{ namespace Game{ // class MenuBackground // ===================================================== -MenuBackground::MenuBackground(){ - +MenuBackground::MenuBackground() : rps(NULL) { Renderer &renderer= Renderer::getInstance(); //load data @@ -68,22 +67,13 @@ MenuBackground::MenuBackground(){ bool withRainEffect = Config::getInstance().getBool("RainEffect","true"); if(withRainEffect == true) { rain= menuNode->getChild("rain")->getAttribute("value")->getBoolValue(); - if(rain){ - RainParticleSystem *rps= new RainParticleSystem(); - rps->setSpeed(12.f/GameConstants::updateFps); - rps->setEmissionRate(25); - rps->setWind(-90.f, 4.f/GameConstants::updateFps); - rps->setPos(Vec3f(0.f, 25.f, 0.f)); - rps->setColor(Vec4f(1.f, 1.f, 1.f, 0.2f)); - rps->setRadius(30.f); - renderer.manageParticleSystem(rps, rsMenu); - - for(int i=0; igetChild("camera"); @@ -140,17 +130,41 @@ MenuBackground::MenuBackground(){ anim= 0.f; } +void MenuBackground::createRainParticleSystem() { + if(rps == NULL) { + rps= new RainParticleSystem(); + rps->setSpeed(12.f/GameConstants::updateFps); + rps->setEmissionRate(25); + rps->setWind(-90.f, 4.f/GameConstants::updateFps); + rps->setPos(Vec3f(0.f, 25.f, 0.f)); + rps->setColor(Vec4f(1.f, 1.f, 1.f, 0.2f)); + rps->setRadius(30.f); + + Renderer &renderer= Renderer::getInstance(); + renderer.manageParticleSystem(rps, rsMenu); + + for(int i=0; itargetCamera= targetCamera; this->lastCamera= camera; t= 0.f; } -void MenuBackground::update(){ - +void MenuBackground::update() { //rain drops bool withRainEffect = Config::getInstance().getBool("RainEffect","true"); if(withRainEffect == true) { + if(rain == false) { + rain = true; + createRainParticleSystem(); + } + for(int i=0; i=1.f){ @@ -159,6 +173,21 @@ void MenuBackground::update(){ } } } + else if(rain == true) { + rain = false; + + if(rps != NULL) { + Renderer &renderer= Renderer::getInstance(); + if(renderer.validateParticleSystemStillExists(rps,rsMenu) == true) { + rps->fade(); + vector particleSystems; + particleSystems.push_back(rps); + renderer.cleanupParticleSystems(particleSystems, rsMenu); + } + + rps = NULL; + } + } if(targetCamera!=NULL){ t+= ((0.01f+(1.f-t)/10.f)/20.f)*(60.f/GameConstants::updateFps); diff --git a/source/glest_game/menu/menu_background.h b/source/glest_game/menu/menu_background.h index e41a20d1..42bddfb3 100644 --- a/source/glest_game/menu/menu_background.h +++ b/source/glest_game/menu/menu_background.h @@ -74,6 +74,8 @@ private: float fade; Vec3f aboutPosition; + RainParticleSystem *rps; + public: MenuBackground(); @@ -99,6 +101,7 @@ public: private: Vec2f computeRaindropPos(); + void createRainParticleSystem(); }; }} //end namespace