diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index d8e73a15..65f467f9 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1594,7 +1594,10 @@ void Game::render2d(){ str+= "Render FPS: " + intToStr(lastRenderFps) + "[" + intToStr(avgRenderFps) + "]\n"; str+= "Update FPS: " + intToStr(lastUpdateFps) + "[" + intToStr(avgUpdateFps) + "]\n"; str+= "GameCamera pos: " + floatToStr(gameCamera.getPos().x)+","+floatToStr(gameCamera.getPos().y)+","+floatToStr(gameCamera.getPos().z)+"\n"; - str+= "Time: " + floatToStr(world.getTimeFlow()->getTime(),8)+"\n"; + str+= "Time: " + floatToStr(world.getTimeFlow()->getTime(),2)+"\n"; + if(SystemFlags::getThreadedLoggerRunning() == true) { + str+= "Log buffer count: " + intToStr(SystemFlags::getLogEntryBufferCount())+"\n"; + } str+= "Triangle count: " + intToStr(renderer.getTriangleCount())+"\n"; str+= "Vertex count: " + intToStr(renderer.getPointCount())+"\n"; str+= "Frame count:" + intToStr(world.getFrameCount())+"\n"; @@ -1648,7 +1651,7 @@ void Game::render2d(){ renderer.renderText(factionInfo, coreData.getMenuFontBig(), Vec4f(playerColor.x,playerColor.y,playerColor.z,1.0), - 10, metrics.getVirtualH() - mh - 60 - 210 - (i * 16), false); + 10, metrics.getVirtualH() - mh - 90 - 210 - (i * 16), false); } if(renderer.getAllowRenderUnitTitles() == false) { @@ -1694,19 +1697,18 @@ void Game::render2d(){ // ==================== misc ==================== -void Game::checkWinner(){ - if(!gameOver){ - if(gameSettings.getDefaultVictoryConditions()){ +void Game::checkWinner() { + if(gameOver == false) { + if(gameSettings.getDefaultVictoryConditions()) { checkWinnerStandard(); } - else - { + else { checkWinnerScripted(); } } } -void Game::checkWinnerStandard(){ +void Game::checkWinnerStandard() { if(world.getThisFaction()->getType()->getPersonalityType() == fpt_Observer) { // lookup int is team #, value is players alive on team std::map teamsAlive; @@ -1854,16 +1856,16 @@ void Game::checkWinnerScripted() { } } -bool Game::hasBuilding(const Faction *faction){ - for(int i=0; igetUnitCount(); ++i){ - if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)){ +bool Game::hasBuilding(const Faction *faction) { + for(int i=0; igetUnitCount(); ++i) { + if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)) { return true; } } return false; } -void Game::incSpeed(){ +void Game::incSpeed() { Lang &lang= Lang::getInstance(); switch(speed){ case sSlow: @@ -1879,7 +1881,7 @@ void Game::incSpeed(){ } } -void Game::decSpeed(){ +void Game::decSpeed() { Lang &lang= Lang::getInstance(); switch(speed){ case sNormal: @@ -1895,20 +1897,20 @@ void Game::decSpeed(){ } } -int Game::getUpdateLoops(){ - if(paused){ +int Game::getUpdateLoops() { + if(paused) { return 0; } - else if(speed==sFast){ + else if(speed == sFast) { return Config::getInstance().getInt("FastSpeedLoops"); } - else if(speed==sSlow){ + else if(speed == sSlow) { return updateFps % 2 == 0? 1: 0; } return 1; } -void Game::showLoseMessageBox(){ +void Game::showLoseMessageBox() { Lang &lang= Lang::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index ab1f420c..d27e4c4e 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -622,7 +622,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n\n"); } -int glestMain(int argc, char** argv) { +int glestMain(int argc, char** argv) { #ifdef SL_LEAK_DUMP AllocRegistry memoryLeaks = AllocRegistry::getInstance(); #endif @@ -778,12 +778,20 @@ int glestMain(int argc, char** argv) { } } + //printf("In MAIN STARTUP A\n"); std::auto_ptr preCacheThread; - Config &config = Config::getInstance(); + Config &config = Config::getInstance(); + + //printf("In MAIN STARTUP B\n"); + + SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","true"); + + //printf("In MAIN STARTUP C, SystemFlags::ENABLE_THREADED_LOGGING = %d\n",SystemFlags::ENABLE_THREADED_LOGGING); + FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str())); Socket::isUPNP = !config.getBool("DisableUPNP","false"); - SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","false"); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/platform/common/simple_threads.h b/source/shared_lib/include/platform/common/simple_threads.h index b8193004..3b5a7f2c 100644 --- a/source/shared_lib/include/platform/common/simple_threads.h +++ b/source/shared_lib/include/platform/common/simple_threads.h @@ -106,6 +106,7 @@ public: LogFileThread(); virtual void execute(); void addLogEntry(SystemFlags::DebugType type, string logEntry); + std::size_t getLogEntryBufferCount(); }; diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 1dab803b..0d7ea2b5 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -130,6 +130,9 @@ public: static CURL *initHTTP(); static void cleanupHTTP(CURL **handle); + static bool getThreadedLoggerRunning(); + static std::size_t getLogEntryBufferCount(); + // Let the macro call into this when require.. NEVER call it automatically. static void handleDebug(DebugType type, const char *fmt, ...); static void logDebugEntry(DebugType type, string debugEntry, time_t debugTime); diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 25c6b418..dc4cc3f0 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -217,7 +217,7 @@ void LogFileThread::execute() { try { for(;this->getQuitStatus() == false;) { - if(difftime(time(NULL),lastSaveToDisk) >= 3) { + if(difftime(time(NULL),lastSaveToDisk) >= 5) { lastSaveToDisk = time(NULL); saveToDisk(); } @@ -244,9 +244,16 @@ void LogFileThread::execute() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__); } +std::size_t LogFileThread::getLogEntryBufferCount() { + MutexSafeWrapper safeMutex(&mutexLogList); + std::size_t logCount = logList.size(); + safeMutex.ReleaseLock(); + return logCount; +} + void LogFileThread::saveToDisk() { MutexSafeWrapper safeMutex(&mutexLogList); - unsigned int logCount = logList.size(); + std::size_t logCount = logList.size(); if(logCount > 0) { vector tempLogList = logList; safeMutex.ReleaseLock(true); diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index b820d953..3fcb2008 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -61,6 +61,18 @@ static void *myrealloc(void *ptr, size_t size) return malloc(size); } +bool SystemFlags::getThreadedLoggerRunning() { + return (threadLogger != NULL && threadLogger->getRunningStatus() == true); +} + +std::size_t SystemFlags::getLogEntryBufferCount() { + std::size_t ret = 0; + if(threadLogger != NULL) { + ret = threadLogger->getLogEntryBufferCount(); + } + return ret; +} + size_t SystemFlags::httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; @@ -159,6 +171,8 @@ CURL *SystemFlags::initHTTP() { } void SystemFlags::init(bool haveSpecialOutputCommandLineOption) { + //printf("SystemFlags::init CALLED, SystemFlags::debugLogFileList.size() = %d\n",SystemFlags::debugLogFileList.size()); + SystemFlags::haveSpecialOutputCommandLineOption = haveSpecialOutputCommandLineOption; if(SystemFlags::debugLogFileList.size() == 0) { SystemFlags::debugLogFileList[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem); @@ -168,13 +182,14 @@ void SystemFlags::init(bool haveSpecialOutputCommandLineOption) { SystemFlags::debugLogFileList[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands); SystemFlags::debugLogFileList[SystemFlags::debugLUA] = SystemFlags::SystemFlagsType(SystemFlags::debugLUA); SystemFlags::debugLogFileList[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError); - - if(SystemFlags::ENABLE_THREADED_LOGGING) { - threadLogger = new LogFileThread(); - threadLogger->start(); - } } + if(threadLogger == NULL) { + threadLogger = new LogFileThread(); + threadLogger->start(); + sleep(5); + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(curl_handle == NULL) { @@ -224,14 +239,12 @@ SystemFlags::~SystemFlags() { } void SystemFlags::Close() { - if(SystemFlags::ENABLE_THREADED_LOGGING) { - if(threadLogger != NULL) { - SystemFlags::ENABLE_THREADED_LOGGING = false; - threadLogger->signalQuit(); - threadLogger->shutdownAndWait(); - delete threadLogger; - threadLogger = NULL; - } + if(threadLogger != NULL) { + SystemFlags::ENABLE_THREADED_LOGGING = false; + threadLogger->signalQuit(); + threadLogger->shutdownAndWait(); + delete threadLogger; + threadLogger = NULL; } if(SystemFlags::debugLogFileList.size() > 0) { @@ -285,7 +298,8 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) { va_end(argList); if(SystemFlags::ENABLE_THREADED_LOGGING && - threadLogger != NULL) { + threadLogger != NULL && + threadLogger->getRunningStatus() == true) { threadLogger->addLogEntry(type, szBuf); } else {