From dfeea6fc0a4101d6a69ad7a10bcf548534c49cb0 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 6 Aug 2010 03:55:17 +0000 Subject: [PATCH] - another attempt to fix ultifd's game end issue --- source/glest_game/game/game.cpp | 16 ++++++++++++++-- source/glest_game/game/stats.cpp | 10 ---------- source/glest_game/game/stats.h | 24 +++++++++++++++++++++--- source/glest_game/main/program.cpp | 2 ++ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 1cfbf2a1..dfe73ddb 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1126,10 +1126,13 @@ void Game::keyPress(char c){ void Game::quitGame(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - Stats stats = *(world.getStats()); + //Stats stats = *(world.getStats()); + Stats *endStats = new Stats(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + *endStats = *(world.getStats()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); NetworkManager::getInstance().end(); @@ -1137,7 +1140,16 @@ void Game::quitGame(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - program->setState(new BattleEnd(program, &stats)); + ProgramState *newState = new BattleEnd(program, endStats); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + delete endStats; + endStats = NULL; + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + program->setState(newState); } // ==================== PRIVATE ==================== diff --git a/source/glest_game/game/stats.cpp b/source/glest_game/game/stats.cpp index 6de47a78..ce1fb924 100644 --- a/source/glest_game/game/stats.cpp +++ b/source/glest_game/game/stats.cpp @@ -15,16 +15,6 @@ namespace Glest{ namespace Game{ -PlayerStats::PlayerStats(){ - victory= false; - - kills= 0; - deaths= 0; - unitsProduced= 0; - resourcesHarvested= 0; - playerName = ""; -} - // ===================================================== // class Stats // ===================================================== diff --git a/source/glest_game/game/stats.h b/source/glest_game/game/stats.h index 81f36c48..426514bb 100644 --- a/source/glest_game/game/stats.h +++ b/source/glest_game/game/stats.h @@ -23,8 +23,20 @@ using namespace Shared::Graphics; namespace Glest{ namespace Game{ -struct PlayerStats{ - PlayerStats(); +class PlayerStats { +public: + PlayerStats() { + control = ctClosed; + factionTypeName = ""; + teamIndex = 0; + victory = false; + kills = 0; + deaths = 0; + unitsProduced = 0; + resourcesHarvested = 0; + playerName = ""; + playerColor = Vec3f(0,0,0); + } ControlType control; string factionTypeName; @@ -44,7 +56,7 @@ struct PlayerStats{ /// Player statistics that are shown after the game ends // ===================================================== -class Stats{ +class Stats { private: PlayerStats playerStats[GameConstants::maxPlayers]; @@ -53,6 +65,12 @@ private: int thisFactionIndex; public: + + Stats() { + description = ""; + factionCount = 0; + thisFactionIndex = 0; + } void init(int factionCount, int thisFactionIndex, const string &description); string getDescription() const {return description;} diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 28282267..ae138ca6 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -232,7 +232,9 @@ void Program::loopWorker() { assert(programState != NULL); if(this->programState->quitTriggered() == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); this->programState->quitAndToggleState(); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); return; } ProgramState *prevState = this->programState;