diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index dafd2ea5e..9b393bf46 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -268,32 +268,38 @@ void Program::resize(SizeState sizeState){ void Program::setState(ProgramState *programState, bool cleanupOldState) { try { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(cleanupOldState == true) { - delete this->programState; + if(this->programState != programState) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + delete this->programState; + this->programState = NULL; + } } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); this->programState= programState; programState->load(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); programState->init(); - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); updateTimer.reset(); updateCameraTimer.reset(); fpsTimer.reset(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); } catch(const exception &e){ //exceptionMessage(e); //throw runtime_error(e.what()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s LineL: %d]\n",__FILE__,__FUNCTION__,__LINE__); this->showMessage(e.what()); setState(new Intro(this)); } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 52c93fef4..ff90bceb4 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -251,7 +251,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b //chatManager.init(&console, world.getThisTeamIndex()); chatManager.init(&console, -1); - publishToMasterserverThread = new SimpleTaskThread(this,0,150); + publishToMasterserverThread = new SimpleTaskThread(this,0,50); publishToMasterserverThread->start(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -366,6 +366,18 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ saveGameSettingsToFile("lastCustomGamSettings.mgg"); BaseThread::shutdownAndWait(publishToMasterserverThread); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + + delete publishToMasterserverThread; + publishToMasterserverThread = NULL; + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + + assert(program != NULL); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + program->setState(new Game(program, &gameSettings)); } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/util/randomgen.h b/source/shared_lib/include/util/randomgen.h index 833e43621..90541babb 100644 --- a/source/shared_lib/include/util/randomgen.h +++ b/source/shared_lib/include/util/randomgen.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -12,7 +12,7 @@ #ifndef _SHARED_UTIL_RANDOM_H_ #define _SHARED_UTIL_RANDOM_H_ -#include "math_wrapper.h" +//#include "math_wrapper.h" namespace Shared { namespace Util { @@ -28,9 +28,9 @@ private: private: int lastNumber; -#ifdef USE_STREFLOP - streflop::RandomState randomState; -#endif +//#ifdef USE_STREFLOP +// streflop::RandomState randomState; +//#endif public: RandomGen(); diff --git a/source/shared_lib/sources/platform/common/base_thread.cpp b/source/shared_lib/sources/platform/common/base_thread.cpp index 82e2ae974..1b4616bf8 100644 --- a/source/shared_lib/sources/platform/common/base_thread.cpp +++ b/source/shared_lib/sources/platform/common/base_thread.cpp @@ -29,7 +29,9 @@ BaseThread::BaseThread() : Thread() { } BaseThread::~BaseThread() { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); shutdownAndWait(); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void BaseThread::signalQuit() { @@ -87,17 +89,20 @@ void BaseThread::setRunningStatus(bool value) { } void BaseThread::shutdownAndWait(BaseThread *pThread) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(pThread != NULL && pThread->getRunningStatus() == true) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); pThread->signalQuit(); for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= 10; ) { if(pThread->getRunningStatus() == false) { break; } - sleep(50); + sleep(10); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } void BaseThread::shutdownAndWait() { diff --git a/source/shared_lib/sources/util/randomgen.cpp b/source/shared_lib/sources/util/randomgen.cpp index 43e8d4e9b..2c728dfd9 100644 --- a/source/shared_lib/sources/util/randomgen.cpp +++ b/source/shared_lib/sources/util/randomgen.cpp @@ -15,21 +15,21 @@ const int RandomGen::b= 150889; RandomGen::RandomGen(){ -#ifdef USE_STREFLOP - lastNumber = streflop::RandomInit(0); // streflop -#else +//#ifdef USE_STREFLOP +// lastNumber = streflop::RandomInit(0); // streflop +//#else lastNumber= 0; -#endif +//#endif //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] lastNumber = %d\n",__FILE__,__FUNCTION__,__LINE__,lastNumber); } void RandomGen::init(int seed){ -#ifdef USE_STREFLOP - lastNumber = streflop::RandomInit(seed); // streflop -#else +//#ifdef USE_STREFLOP +// lastNumber = streflop::RandomInit(seed); // streflop +//#else lastNumber= seed % m; -#endif +//#endif //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] seed = %d, lastNumber = %d\n",__FILE__,__FUNCTION__,__LINE__,seed,lastNumber); } @@ -47,12 +47,12 @@ int RandomGen::rand() { int RandomGen::randRange(int min, int max){ assert(min<=max); -#ifdef USE_STREFLOP - int res = streflop::Random(min, max); // streflop -#else +//#ifdef USE_STREFLOP +// int res = streflop::Random(min, max); // streflop +//#else int diff= max-min; int res= min + static_cast((static_cast(diff+1)*RandomGen::rand()) / m); -#endif +//#endif assert(res>=min && res<=max); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] min = %d, max = %d, res = %d\n",__FILE__,__FUNCTION__,__LINE__,min,max,res); @@ -63,12 +63,12 @@ int RandomGen::randRange(int min, int max){ float RandomGen::randRange(float min, float max){ assert(min<=max); -#ifdef USE_STREFLOP - float res = streflop::Random(min, max, randomState); // streflop -#else +//#ifdef USE_STREFLOP +// float res = streflop::Random(min, max, randomState); // streflop +//#else float rand01= static_cast(RandomGen::rand())/(m-1); float res= min+((max-min)*rand01); -#endif +//#endif assert(res>=min && res<=max);