From 4ee98e7155e746665d82aed4f306688a2ba91bee Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 24 Aug 2010 23:15:33 +0000 Subject: [PATCH] - some changes to the explorecells cache for less memory and better performance. - updated performance logging to more easily find things in the log --- source/glest_game/game/game.cpp | 48 ++++++----- source/glest_game/main/program.cpp | 34 +++++--- source/glest_game/main/program.h | 1 + source/glest_game/world/world.cpp | 125 ++++++++++++++++------------- source/glest_game/world/world.h | 2 +- 5 files changed, 124 insertions(+), 86 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index c8c7958b..16dcf74b 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -520,6 +520,7 @@ void Game::update(){ NetworkManager &networkManager= NetworkManager::getInstance(); //update for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [AI updates]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //World world.update(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); // Commander commander.updateNetwork(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [commander updating network]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Gui gui.update(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //Particle systems @@ -556,13 +561,12 @@ void Game::update(){ weatherParticleSystem->setPos(gameCamera.getPos()); } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [weather particle updating]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); - //if(avgRenderFps >= 10 || world.getFrameCount() % 2 == 0) { - //renderer.updateParticleManager(rsGame,lastRenderFps); - renderer.updateParticleManager(rsGame,avgRenderFps); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - //} + renderer.updateParticleManager(rsGame,avgRenderFps); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); } @@ -1203,74 +1207,74 @@ void Game::render3d(){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); renderer.reset3d(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.computeVisibleQuad(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.loadGameCameraMatrix(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.setupLighting(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //shadow map //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderShadowsToTexture(avgRenderFps); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //clear buffers //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.clearBuffers(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //surface //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderSurface(avgRenderFps,world.getFrameCount()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //selection circles //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderSelectionEffects(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //units //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderUnits(avgRenderFps,world.getFrameCount()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //objects //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderObjects(avgRenderFps,world.getFrameCount()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //water //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderWater(); renderer.renderWaterEffects(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //particles //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderParticleManager(rsGame); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //mouse 3d //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - chrono.start(); renderer.renderMouse3d(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); } diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index e9194409..47fdc5a5 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -117,6 +117,7 @@ void Program::ShowMessageProgramState::update() { // ===================== PUBLIC ======================== Program::Program() { + skipRenderFrameCount = 0; programState= NULL; singleton = this; soundThreadManager = NULL; @@ -220,7 +221,10 @@ void Program::loop() { } void Program::loopWorker() { - //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] programState = %p\n",__FILE__,__FUNCTION__,__LINE__,programState); + SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] ================================= MAIN LOOP START ================================= \n",__FILE__,__FUNCTION__,__LINE__); + + Chrono chronoLoop; + chronoLoop.start(); Chrono chrono; chrono.start(); @@ -248,11 +252,17 @@ void Program::loopWorker() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - programState->render(); + if(skipRenderFrameCount <= 0) { + programState->render(); + } + else { + skipRenderFrameCount--; + } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP RENDERING\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //update camera chrono.start(); @@ -262,14 +272,14 @@ void Program::loopWorker() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->updateCamera took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP CAMERA UPDATING\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //update world chrono.start(); - + int updateCount = 0; while(prevState == this->programState && updateTimer.isTime()) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); - GraphicComponent::update(); programState->update(); if(prevState == this->programState) { @@ -285,9 +295,13 @@ void Program::loopWorker() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } + updateCount++; } - - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //if(chrono.getMillis() >= 100) { + // skipRenderFrameCount = (chrono.getMillis() / 100); + //} + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP BODY LOGIC, updateCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),updateCount); + if(chrono.getMillis() > 0) chrono.start(); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -300,10 +314,12 @@ void Program::loopWorker() { programState->tick(); } - //if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d programState->render took msecs: %lld ==============> MAIN LOOP TICKING\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] ------------------------------- MAIN LOOP END, stats: loop took msecs: %lld -------------------------------\n",__FILE__,__FUNCTION__,__LINE__,chronoLoop.getMillis()); } void Program::resize(SizeState sizeState){ diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index fe59dfbe..6a23d9aa 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -122,6 +122,7 @@ private: static Program *singleton; GraphicMessageBox msgBox; + int skipRenderFrameCount; public: Program(); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index a3cc92f3..b0c093e4 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -310,10 +310,12 @@ void World::update(){ //time timeFlow.update(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //water effects waterEffects.update(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //bool needToUpdateUnits = true; //if(staggeredFactionUpdates == true) { @@ -325,18 +327,21 @@ void World::update(){ //if(needToUpdateUnits == true) { // SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] needToUpdateUnits = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,needToUpdateUnits,frameCount); - //units - updateAllFactionUnits(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //units + updateAllFactionUnits(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [updateAllFactionUnits()]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); - //undertake the dead - underTakeDeadFactionUnits(); - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //undertake the dead + underTakeDeadFactionUnits(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //} //food costs updateAllFactionConsumableCosts(); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //fow smoothing if(fogOfWarSmoothing && ((frameCount+1) % (fogOfWarSmoothingFrameSkip+1))==0) { @@ -344,6 +349,7 @@ void World::update(){ minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f)); } if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //tick bool needToTick = canTickWorld(); @@ -927,6 +933,9 @@ void World::initMap(){ // ==================== exploration ==================== void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ + Chrono chrono; + chrono.start(); + // Experimental cache lookup of previously calculated cells + sight range if(MaxExploredCellsLookupItemCache > 0) { if(difftime(time(NULL),ExploredCellsLookupItem::lastDebug) >= 10) { @@ -935,7 +944,7 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ExploredCellsLookupItemCache.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,ExploredCellsLookupItemCache.size()); } - // Ok we limit the cache size doe to possible RAM constraints when + // Ok we limit the cache size due to possible RAM constraints when // the threshold is met bool MaxExploredCellsLookupItemCacheTriggered = false; if(ExploredCellsLookupItemCache.size() >= MaxExploredCellsLookupItemCache) { @@ -943,11 +952,8 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ // Snag the oldest entry in the list std::map::reverse_iterator purgeItem = ExploredCellsLookupItemCacheTimer.rbegin(); - ExploredCellsLookupItemCache[purgeItem->second.pos][purgeItem->second.sightRange].erase(purgeItem->second.teamIndex); + ExploredCellsLookupItemCache[purgeItem->second.pos].erase(purgeItem->second.sightRange); - if(ExploredCellsLookupItemCache[purgeItem->second.pos][purgeItem->second.sightRange].size() == 0) { - ExploredCellsLookupItemCache[purgeItem->second.pos].erase(purgeItem->second.sightRange); - } if(ExploredCellsLookupItemCache[purgeItem->second.pos].size() == 0) { ExploredCellsLookupItemCache.erase(purgeItem->second.pos); } @@ -955,70 +961,72 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ ExploredCellsLookupItemCacheTimer.erase(purgeItem->first); } - // Check the cache for the pos, sightrange and teamindex and use from + // Check the cache for the pos, sightrange and use from // cache if already found - std::map > >::iterator iterFind = ExploredCellsLookupItemCache.find(newPos); + std::map >::iterator iterFind = ExploredCellsLookupItemCache.find(newPos); if(iterFind != ExploredCellsLookupItemCache.end()) { - std::map >::iterator iterFind2 = iterFind->second.find(sightRange); + std::map::iterator iterFind2 = iterFind->second.find(sightRange); if(iterFind2 != iterFind->second.end()) { - std::map::iterator iterFind3 = iterFind2->second.find(teamIndex); - if(iterFind3 != iterFind2->second.end()) { - std::vector &cellList = iterFind3->second.exploredCellList; - for(int idx2 = 0; idx2 < cellList.size(); ++idx2) { - SurfaceCell *sc = cellList[idx2]; - sc->setExplored(teamIndex, true); - } - cellList = iterFind3->second.visibleCellList; - for(int idx2 = 0; idx2 < cellList.size(); ++idx2) { - SurfaceCell *sc = cellList[idx2]; - sc->setVisible(teamIndex, true); - } - // Only start worrying about updating the cache timer if we - // have hit the threshold - if(MaxExploredCellsLookupItemCacheTriggered == true) { - // Remove the old timer entry since the search key id is stale - ExploredCellsLookupItemCacheTimer.erase(iterFind3->second.ExploredCellsLookupItemCacheTimerCountIndex); - iterFind3->second.ExploredCellsLookupItemCacheTimerCountIndex = ExploredCellsLookupItemCacheTimerCount++; - - ExploredCellsLookupKey lookupKey; - lookupKey.pos = newPos; - lookupKey.sightRange = sightRange; - lookupKey.teamIndex = teamIndex; - - // Add a new search key since we just used this item - ExploredCellsLookupItemCacheTimer[iterFind3->second.ExploredCellsLookupItemCacheTimerCountIndex] = lookupKey; - } - - return; + std::vector &cellList = iterFind2->second.exploredCellList; + for(int idx2 = 0; idx2 < cellList.size(); ++idx2) { + SurfaceCell *sc = cellList[idx2]; + sc->setExplored(teamIndex, true); } + cellList = iterFind2->second.visibleCellList; + for(int idx2 = 0; idx2 < cellList.size(); ++idx2) { + SurfaceCell *sc = cellList[idx2]; + sc->setVisible(teamIndex, true); + } + + // Only start worrying about updating the cache timer if we + // have hit the threshold + if(MaxExploredCellsLookupItemCacheTriggered == true) { + // Remove the old timer entry since the search key id is stale + ExploredCellsLookupItemCacheTimer.erase(iterFind2->second.ExploredCellsLookupItemCacheTimerCountIndex); + iterFind2->second.ExploredCellsLookupItemCacheTimerCountIndex = ExploredCellsLookupItemCacheTimerCount++; + + ExploredCellsLookupKey lookupKey; + lookupKey.pos = newPos; + lookupKey.sightRange = sightRange; + lookupKey.teamIndex = teamIndex; + + // Add a new search key since we just used this item + ExploredCellsLookupItemCacheTimer[iterFind2->second.ExploredCellsLookupItemCacheTimerCountIndex] = lookupKey; + } + + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [CACHE lookup found]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); + + return; } } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [CACHE lookup not found]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); + Vec2i newSurfPos= Map::toSurfCoords(newPos); int surfSightRange= sightRange/Map::cellScale+1; // Explore, this code is quite expensive when we have lots of units ExploredCellsLookupItem item; - for(int i=-surfSightRange-indirectSightRange-1; i<=surfSightRange+indirectSightRange+1; ++i){ - for(int j=-surfSightRange-indirectSightRange-1; j<=surfSightRange+indirectSightRange+1; ++j){ + for(int i = -surfSightRange - indirectSightRange -1; i <= surfSightRange + indirectSightRange +1; ++i) { + for(int j = -surfSightRange - indirectSightRange -1; j <= surfSightRange + indirectSightRange +1; ++j) { Vec2i currRelPos= Vec2i(i, j); Vec2i currPos= newSurfPos + currRelPos; if(map.isInsideSurface(currPos)){ - SurfaceCell *sc= map.getSurfaceCell(currPos); //explore - if(Vec2i(0).dist(currRelPos) < surfSightRange+indirectSightRange+1){ + if(Vec2i(0).dist(currRelPos) < surfSightRange + indirectSightRange + 1) { sc->setExplored(teamIndex, true); - item.exploredCellList.push_back(sc); } //visible - if(Vec2i(0).dist(currRelPos) < surfSightRange){ + if(Vec2i(0).dist(currRelPos) < surfSightRange) { sc->setVisible(teamIndex, true); item.visibleCellList.push_back(sc); } @@ -1026,12 +1034,15 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [RAW explore cells logic]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); + // Ok update our caches with the latest info for this position, sight and team if(MaxExploredCellsLookupItemCache > 0) { if(item.exploredCellList.size() > 0 || item.visibleCellList.size() > 0) { //ExploredCellsLookupItemCache.push_back(item); item.ExploredCellsLookupItemCacheTimerCountIndex = ExploredCellsLookupItemCacheTimerCount++; - ExploredCellsLookupItemCache[newPos][sightRange][teamIndex] = item; + ExploredCellsLookupItemCache[newPos][sightRange] = item; ExploredCellsLookupKey lookupKey; lookupKey.pos = newPos; @@ -1040,6 +1051,8 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ ExploredCellsLookupItemCacheTimer[item.ExploredCellsLookupItemCacheTimerCountIndex] = lookupKey; } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [add explorecells result to CACHE]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); } //computes the fog of war texture, contained in the minimap @@ -1051,10 +1064,11 @@ void World::computeFow(int factionIdxToTick) { //if(factionIdxToTick == -1 || factionIdxToTick == 0) { //if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { //if(frameCount % (GameConstants::updateFps) == 0) { - minimap.resetFowTex(); + minimap.resetFowTex(); //} if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //reset cells if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { @@ -1070,6 +1084,7 @@ void World::computeFow(int factionIdxToTick) { } if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //compute cells for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [exploreCells]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //fire for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [activate Fire Particles]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) chrono.start(); //compute texture if(fogOfWar) { @@ -1145,7 +1162,7 @@ void World::computeFow(int factionIdxToTick) { } } - if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [increment Fog of War Texture]\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } // WARNING! This id is critical! Make sure it fits inside the network packet diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index d0a956a4..3c3dcafa 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -74,7 +74,7 @@ class World{ private: typedef vector Factions; - std::map > > ExploredCellsLookupItemCache; + std::map > ExploredCellsLookupItemCache; std::map ExploredCellsLookupItemCacheTimer; int ExploredCellsLookupItemCacheTimerCount;