bugfix for rain particles when loading keyboard setup in game (and memory cleanup)

This commit is contained in:
Mark Vejvoda 2013-04-30 06:17:30 +00:00
parent 65266ca41e
commit c19065ebd0
6 changed files with 50 additions and 20 deletions

View File

@ -3546,7 +3546,8 @@ void Game::mouseDownLeft(int x, int y) {
//currentUIState->load();
currentUIState->init();
newMenu->setState(new MenuStateKeysetup(program, newMenu,&currentUIState)); // open keyboard shortcuts setup screen
// open keyboard shortcuts setup screen
newMenu->setState(new MenuStateKeysetup(program, newMenu, &currentUIState));
}
else if(result.first == pauseGamePopupMenuIndex) {
//this->setPaused(!paused);

View File

@ -49,6 +49,8 @@ MenuState * MainMenu::oldstate=NULL;
MainMenu::MainMenu(Program *program) : ProgramState(program), menuBackgroundVideo(NULL) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In MainMenu::MainMenu()\n");
mouseX=100;
mouseY=100;
@ -78,6 +80,8 @@ void MainMenu::reloadUI() {
MainMenu::~MainMenu() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In MainMenu::~MainMenu()\n");
if(menuBackgroundVideo != NULL) {
menuBackgroundVideo->closePlayer();
delete menuBackgroundVideo;
@ -242,6 +246,8 @@ void MainMenu::keyPress(SDL_KeyboardEvent c) {
void MainMenu::setState(MenuState *newstate) {
//printf("In [%s::%s Line: %d] oldstate [%p] newstate [%p] this->state [%p]\n",__FILE__,__FUNCTION__,__LINE__,oldstate,newstate,this->state);
//printf("In MainMenu::setState() #1\n");
//delete this->state;
//this->state = newstate;
@ -249,19 +255,24 @@ void MainMenu::setState(MenuState *newstate) {
MenuState *oldstatePtr = oldstate;
delete oldstate;
//printf("In MainMenu::setState() #2\n");
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(oldstatePtr != this->state) {
oldstate=this->state;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In MainMenu::setState() #3\n");
}
else {
oldstate = NULL;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In MainMenu::setState() #4\n");
}
}
else {
oldstate=this->state;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//printf("In MainMenu::setState() #5\n");
}
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->state= newstate;

View File

@ -130,7 +130,31 @@ MenuBackground::MenuBackground() : rps(NULL) {
anim= 0.f;
}
MenuBackground::~MenuBackground() {
//printf("In ~MenuBackground() rps = %p\n",rps);
cleanup();
}
void MenuBackground::cleanup() {
//printf("In MenuBackground::cleanup() rps = %p\n",rps);
if(rps != NULL) {
Renderer &renderer= Renderer::getInstance();
if(renderer.validateParticleSystemStillExists(rps,rsMenu) == true) {
rps->fade();
vector<ParticleSystem *> particleSystems;
particleSystems.push_back(rps);
renderer.cleanupParticleSystems(particleSystems, rsMenu);
}
rps = NULL;
}
}
void MenuBackground::createRainParticleSystem() {
//printf("In MenuBackground::createRainParticleSystem() rps = %p\n",rps);
if(rps == NULL) {
rps= new RainParticleSystem();
rps->setSpeed(12.f/GameConstants::updateFps);
@ -176,17 +200,7 @@ 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<ParticleSystem *> particleSystems;
particleSystems.push_back(rps);
renderer.cleanupParticleSystems(particleSystems, rsMenu);
}
rps = NULL;
}
cleanup();
}
if(targetCamera!=NULL){

View File

@ -83,6 +83,7 @@ private:
public:
MenuBackground();
~MenuBackground();
bool getWater() const {return water;}
float getWaterHeight() const {return waterHeight;}
@ -107,6 +108,7 @@ public:
private:
Vec2f computeRaindropPos();
void createRainParticleSystem();
void cleanup();
};
}} //end namespace

View File

@ -279,8 +279,11 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(this->parentUI != NULL) {
// Set the parent pointer to NULL so the owner knows it was deleted
*this->parentUI = NULL;
delete *this->parentUI;
// Delete the main menu
delete mainMenu;
return;
}
mainMenu->setState(new MenuStateRoot(program, mainMenu));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -299,8 +302,11 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){
configKeys.reload();
if(this->parentUI != NULL) {
// Set the parent pointer to NULL so the owner knows it was deleted
*this->parentUI = NULL;
delete *this->parentUI;
// Delete the main menu
delete mainMenu;
return;
}
mainMenu->setState(new MenuStateKeysetup(program, mainMenu));
@ -324,12 +330,6 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){
Lang &lang= Lang::getInstance();
console.addLine(lang.get("SettingsSaved"));
// if(this->parentUI != NULL) {
// *this->parentUI = NULL;
// delete *this->parentUI;
// }
//
// mainMenu->setState(new MenuStateOptions(program, mainMenu));
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
else if ( keyScrollBar.getElementCount() != 0) {

View File

@ -410,6 +410,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
weather= wSnowy;
}
//printf("==> Weather is: %d rnd = %f [sun: %f rainyProb: %f]",weather,rnd,sunnyProb,rainyProb);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}