diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 61140b49..b1ef4399 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1777,6 +1777,7 @@ void Game::update() { perfList.push_back(perfBuf); } + Chrono chronoGamePerformanceCounts; Chrono chrono; if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); @@ -1851,6 +1852,7 @@ void Game::update() { //updateLoops = 80; } + chronoGamePerformanceCounts.start(); //NetworkManager &networkManager= NetworkManager::getInstance(); bool enableServerControlledAI = this->gameSettings.getEnableServerControlledAI(); //bool isNetworkGame = this->gameSettings.isNetworkGame(); @@ -1983,6 +1985,10 @@ void Game::update() { } } + + gamePerformanceCounts["CalculateNetorkUpdateLoops"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["CalculateNetorkUpdateLoops"] / 2; + chronoGamePerformanceCounts.stop(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(showPerfStats) { sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); @@ -2033,8 +2039,13 @@ void Game::update() { //AiInterface if(commander.hasReplayCommandListForFrame() == false) { + chronoGamePerformanceCounts.start(); + processNetworkSynchChecksIfRequired(); + gamePerformanceCounts["CalculateNetorkCRCSynchChecks"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["CalculateNetorkCRCSynchChecks"] / 2; + chronoGamePerformanceCounts.stop(); + /* for(int j = 0; j < world.getFactionCount(); ++j) { Faction *faction = world.getFaction(j); @@ -2063,6 +2074,8 @@ void Game::update() { } else { // Signal the faction threads to do any pre-processing + chronoGamePerformanceCounts.start(); + bool hasAIPlayer = false; for(int j = 0; j < world.getFactionCount(); ++j) { Faction *faction = world.getFaction(j); @@ -2113,6 +2126,9 @@ void Game::update() { } } } + + gamePerformanceCounts["ProcessAIWorkerThreads"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessAIWorkerThreads"] / 2; + chronoGamePerformanceCounts.stop(); } if(showPerfStats) { @@ -2173,7 +2189,13 @@ void Game::update() { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); //World + chronoGamePerformanceCounts.start(); + if(pendingQuitError == false) world.update(); + + gamePerformanceCounts["ProcessWorldUpdate"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessWorldUpdate"] / 2; + chronoGamePerformanceCounts.stop(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); @@ -2182,7 +2204,7 @@ void Game::update() { perfList.push_back(perfBuf); } - if(currentCameraFollowUnit!=NULL){ + if(currentCameraFollowUnit != NULL) { Vec3f c=currentCameraFollowUnit->getCurrVector(); int rotation=currentCameraFollowUnit->getRotation(); float angle=rotation+180; @@ -2209,9 +2231,13 @@ void Game::update() { } // Commander - //commander.updateNetwork(); + chronoGamePerformanceCounts.start(); + if(pendingQuitError == false) commander.signalNetworkUpdate(this); + gamePerformanceCounts["ProcessNetworkUpdate"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessNetworkUpdate"] / 2; + chronoGamePerformanceCounts.stop(); + if(showPerfStats) { sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); perfList.push_back(perfBuf); @@ -2221,7 +2247,13 @@ void Game::update() { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); //Gui + chronoGamePerformanceCounts.start(); + gui.update(); + + gamePerformanceCounts["ProcessGUIUpdate"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessGUIUpdate"] / 2; + chronoGamePerformanceCounts.stop(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); @@ -2244,7 +2276,14 @@ void Game::update() { } Renderer &renderer= Renderer::getInstance(); + + chronoGamePerformanceCounts.start(); + renderer.updateParticleManager(rsGame,avgRenderFps); + + gamePerformanceCounts["ProcessParticleManager"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessParticleManager"] / 2; + chronoGamePerformanceCounts.stop(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); @@ -2275,6 +2314,8 @@ void Game::update() { perfList.push_back(perfBuf); } + chronoGamePerformanceCounts.start(); + //call the chat manager chatManager.updateNetwork(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [chatManager.updateNetwork]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); @@ -2309,6 +2350,9 @@ void Game::update() { perfList.push_back(perfBuf); } + gamePerformanceCounts["ProcessMiscNetwork"] = chronoGamePerformanceCounts.getMillis() + gamePerformanceCounts["ProcessMiscNetwork"] / 2; + chronoGamePerformanceCounts.stop(); + // START - Handle joining in progress games if(role == nrServer) { ServerInterface *server = NetworkManager::getInstance().getServerInterface(); @@ -2756,6 +2800,22 @@ void Game::update() { } } +string Game::getGamePerformanceCounts() const { + if(gamePerformanceCounts.empty() == true) { + return ""; + } + string result = ""; + for(std::map::const_iterator iterMap = gamePerformanceCounts.begin(); + iterMap != gamePerformanceCounts.end(); ++iterMap) { + if(result != "") { + result += "\n"; + } + result += iterMap->first + " = avg millis: " + intToStr(iterMap->second); + } + + return result; +} + bool Game::switchSetupForSlots(ServerInterface *& serverInterface, int startIndex, int endIndex, bool onlyNetworkUnassigned) { bool switchRequested = false; @@ -5500,6 +5560,8 @@ void Game::render2d() { renderer.renderClock(); } + renderer.renderPerformanceStats(); + //resource info if(photoModeEnabled == false) { if(this->masterserverMode == false) { diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 8c4c1b81..6b11563f 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -211,6 +211,8 @@ private: bool quitGameCalled; bool disableSpeedChange; + std::map gamePerformanceCounts; + public: Game(); Game(Program *program, const GameSettings *gameSettings, bool masterserverMode); @@ -336,6 +338,8 @@ public: bool getDisableSpeedChange() const { return disableSpeedChange; } void setDisableSpeedChange(bool value) { disableSpeedChange = value; } + string getGamePerformanceCounts() const; + private: //render void render3d(); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e3ab47a1..ab3b61cd 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2217,6 +2217,50 @@ void Renderer::renderChatManager(const ChatManager *chatManager) { } } + +void Renderer::renderPerformanceStats() { + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + return; + } + + Config &config= Config::getInstance(); + if(config.getBool("ShowInGamePerformance","false") == false) { + return; + } + + const Metrics &metrics = Metrics::getInstance(); + const World *world = game->getWorld(); + const Vec4f fontColor = game->getGui()->getDisplay()->getColor(); + + char szBuf[200]=""; + snprintf(szBuf,200,"Frame: %d",game->getWorld()->getFrameCount() / 20); + string str = string(szBuf) + string("\n"); + + static time_t lastGamePerfCheck = time(NULL); + static string gamePerfStats = ""; + if(difftime((long int)time(NULL),lastGamePerfCheck) > 3) { + lastGamePerfCheck = time(NULL); + gamePerfStats = game->getGamePerformanceCounts(); + } + + if(gamePerfStats != "") { + str += gamePerfStats + "\n"; + } + + if(renderText3DEnabled == true) { + renderTextShadow3D( + str, CoreData::getInstance().getDisplayFontSmall3D(), + fontColor, + 10, metrics.getVirtualH()-180, false); + } + else { + renderTextShadow( + str, CoreData::getInstance().getDisplayFontSmall(), + fontColor, + 10, metrics.getVirtualH()-180, false); + } +} + void Renderer::renderClock() { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index cc969f76..510697b9 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -502,6 +502,7 @@ public: void renderChatManager(const ChatManager *chatManager); void renderClock(); + void renderPerformanceStats(); void renderResourceStatus(); void renderSelectionQuad(); void renderText(const string &text, Font2D *font, float alpha, int x, int y, bool centered= false);