diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 904e187d..1cfbf2a1 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -45,6 +45,7 @@ Game::Game(Program *program, const GameSettings *gameSettings): { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + quitTriggeredIndicator = false; originalDisplayMsgCallback = NULL; thisGamePtr = this; @@ -113,6 +114,14 @@ Game::~Game(){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +bool Game::quitTriggered() { + return quitTriggeredIndicator; +} + +void Game::quitAndToggleState() { + quitGame(); +} + // ==================== init and load ==================== int Game::ErrorDisplayMessage(const char *msg, bool exitApp) { @@ -554,7 +563,8 @@ void Game::update(){ mainMessageBox.getEnabled() == false && errorMessageBox.getEnabled() == false) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - quitGame(); + //quitGame(); + quitTriggeredIndicator = true; return; } @@ -726,7 +736,8 @@ void Game::mouseDownLeft(int x, int y){ if(networkManager.getGameNetworkInterface() != NULL) { networkManager.getGameNetworkInterface()->quitGame(true); } - quitGame(); + //quitGame(); + quitTriggeredIndicator = true; return; } else { diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 1c6f8845..53f3f532 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -86,6 +86,8 @@ private: DisplayMessageFunction originalDisplayMsgCallback; bool isFirstRender; + bool quitTriggeredIndicator; + public: Game(Program *program, const GameSettings *gameSettings); ~Game(); @@ -123,9 +125,12 @@ public: virtual void eventMouseWheel(int x, int y, int zDelta); virtual void mouseMove(int x, int y, const MouseState *mouseState); - void quitGame(); virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } + virtual bool quitTriggered(); + virtual void quitAndToggleState(); + void quitGame(); + private: //render void render3d(); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 3279b702..28282267 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -231,6 +231,10 @@ void Program::loopWorker() { //render assert(programState != NULL); + if(this->programState->quitTriggered() == true) { + this->programState->quitAndToggleState(); + return; + } ProgramState *prevState = this->programState; //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index bec02b54..8293fae9 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -76,6 +76,8 @@ public: virtual void setStartXY(int X,int Y) { startX=X; startY=Y; } virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); } virtual bool isInSpecialKeyCaptureEvent() { return false; } + virtual bool quitTriggered() { return false; } + virtual void quitAndToggleState() {}; }; // ===============================