diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index cd5893d9c..d7a0e6278 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -212,6 +212,7 @@ private: bool quitGameCalled; bool disableSpeedChange; + std::map teamFowAlphaCellsLookupItem; std::map gamePerformanceCounts; public: diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index 58a2da294..b3ea97bac 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -54,10 +54,7 @@ class GameSettings; class FowAlphaCellsLookupItem { public: - std::vector surfPosList; - std::vector alphaList; - - static time_t lastDebug; + std::map surfPosAlphaList; }; // ===================================================== diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index a01ed5723..e421447be 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1278,18 +1278,15 @@ FowAlphaCellsLookupItem Unit::getFogOfWarRadius(bool useCache) const { if(dist > sightRange) { alpha= clamp(1.f-(dist - sightRange) / (World::indirectSightRange), 0.f, maxAlpha); } - result.surfPosList.push_back(surfPos); - result.alphaList.push_back(alpha); + result.surfPosAlphaList[surfPos] = alpha; } return result; } void Unit::calculateFogOfWarRadius() { if(game->getWorld()->getFogOfWar() == true) { - //if(Config::getInstance().getBool("EnableFowCache","true") == true && this->pos != this->cachedFowPos) { if(this->pos != this->cachedFowPos) { cachedFow = getFogOfWarRadius(false); - static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId); this->cachedFowPos = this->pos; @@ -4160,8 +4157,7 @@ Vec2i Unit::getPos() { } void Unit::clearCaches() { - cachedFow.alphaList.clear(); - cachedFow.surfPosList.clear(); + cachedFow.surfPosAlphaList.clear(); cachedFowPos = Vec2i(0,0); if(unitPath != NULL) { diff --git a/source/glest_game/world/minimap.cpp b/source/glest_game/world/minimap.cpp index fde6f2836..b12304a21 100644 --- a/source/glest_game/world/minimap.cpp +++ b/source/glest_game/world/minimap.cpp @@ -137,14 +137,14 @@ Minimap::~Minimap() { void Minimap::incFowTextureAlphaSurface(const Vec2i &sPos, float alpha, bool isIncrementalUpdate) { if(fowPixmap1) { - assert(sPos.xgetW() && sPos.ygetH()); + assert(sPos.x < fowPixmap1->getW() && sPos.y < fowPixmap1->getH()); - if(fowPixmap1->getPixelf(sPos.x, sPos.y)getPixelf(sPos.x, sPos.y) < alpha){ fowPixmap1->setPixel(sPos.x, sPos.y, alpha); } if(fowPixmap1Copy != NULL && isIncrementalUpdate == true) { - if(fowPixmap1Copy->getPixelf(sPos.x, sPos.y)getPixelf(sPos.x, sPos.y) < alpha){ fowPixmap1Copy->setPixel(sPos.x, sPos.y, alpha); } } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index b5b6f4993..3888156bb 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -54,9 +54,6 @@ World::World() { ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimerCount = 0; - // Disable this cache as it takes too much RAM (not sure if its worth the performance gain) - //enableFowAlphaCellsLookupItemCache = config.getBool("EnableFowCache","true"); - enableFowAlphaCellsLookupItemCache = true; nextCommandGroupId = 0; techTree = NULL; @@ -2566,23 +2563,13 @@ void World::computeFow() { faction->getTeam() == thisTeamIndex && unit->isOperative() == true) { - if(enableFowAlphaCellsLookupItemCache == true) { - const FowAlphaCellsLookupItem &cellList = unit->getCachedFow(); - for(int cellIndex = 0; cellIndex < cellList.surfPosList.size(); ++cellIndex) { - const Vec2i &surfPos = cellList.surfPosList[cellIndex]; - const float &alpha = cellList.alphaList[cellIndex]; + const FowAlphaCellsLookupItem &cellList = unit->getCachedFow(); + for(std::map::const_iterator iterMap = cellList.surfPosAlphaList.begin(); + iterMap != cellList.surfPosAlphaList.end(); ++iterMap) { + const Vec2i &surfPos = iterMap->first; + const float &alpha = iterMap->second; - minimap.incFowTextureAlphaSurface(surfPos, alpha, true); - } - } - else { - const FowAlphaCellsLookupItem cellList = unit->getFogOfWarRadius(false); - for(int cellIndex = 0; cellIndex < cellList.surfPosList.size(); ++cellIndex) { - const Vec2i &surfPos = cellList.surfPosList[cellIndex]; - const float &alpha = cellList.alphaList[cellIndex]; - - minimap.incFowTextureAlphaSurface(surfPos, alpha, true); - } + minimap.incFowTextureAlphaSurface(surfPos, alpha, true); } } } @@ -2687,28 +2674,26 @@ string World::getExploredCellsLookupItemCacheStats() { string World::getFowAlphaCellsLookupItemCacheStats() { string result = ""; - int surfPosCount = 0; - int alphaListCount = 0; + int surfPosAlphaCount = 0; - for(int i=0; igetTeam() == thisTeamIndex) { - for(int j=0; jgetUnitCount(); ++j) { - const Unit *unit= faction->getUnit(j); + for(int unitIndex = 0; unitIndex < faction->getUnitCount(); ++unitIndex) { + const Unit *unit= faction->getUnit(unitIndex); const FowAlphaCellsLookupItem &cache = unit->getCachedFow(); - surfPosCount += (int)cache.surfPosList.size(); - alphaListCount += (int)cache.alphaList.size(); + surfPosAlphaCount += (int)cache.surfPosAlphaList.size(); } } } - uint64 totalBytes = surfPosCount * sizeof(Vec2i); - totalBytes += alphaListCount * sizeof(float); + uint64 totalBytes = surfPosAlphaCount * sizeof(Vec2i); + totalBytes += surfPosAlphaCount * sizeof(float); totalBytes /= 1000; char szBuf[8096]=""; - snprintf(szBuf,8096,"surface count [%d] alpha count [%d] total KB: %s",surfPosCount,alphaListCount,formatNumber(totalBytes).c_str()); + snprintf(szBuf,8096,"surface count [%d] total KB: %s",surfPosAlphaCount,formatNumber(totalBytes).c_str()); result = szBuf; return result; } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 8bc0cffd2..a59f8c570 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -84,9 +84,6 @@ private: std::map ExploredCellsLookupItemCacheTimer; int ExploredCellsLookupItemCacheTimerCount; - bool enableFowAlphaCellsLookupItemCache; - //std::map > FowAlphaCellsLookupItemCache; - public: static const int generationArea= 100; static const int indirectSightRange= 5; @@ -95,7 +92,6 @@ private: Map map; Tileset tileset; - //TechTree techTree; TechTree *techTree; TimeFlow timeFlow; Scenario scenario; @@ -115,7 +111,6 @@ private: int thisFactionIndex; int thisTeamIndex; int frameCount; - //int nextUnitId; Mutex mutexFactionNextUnitId; std::map mapFactionNextUnitId;