From 5a796444b89a1166123469f6516f3d6b23c02379 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 25 Aug 2010 23:55:59 +0000 Subject: [PATCH] - added a cache for compute fog of war --- source/glest_game/main/program.cpp | 12 +++--- source/glest_game/network/network_message.h | 4 +- source/glest_game/world/world.cpp | 46 +++++++++++++++++---- source/glest_game/world/world.h | 11 +++++ 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index c2d217b3..cafc6419 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -252,12 +252,12 @@ void Program::loopWorker() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(skipRenderFrameCount <= 0) { - programState->render(); - } - else { - skipRenderFrameCount--; - } + //if(skipRenderFrameCount <= 0) { + programState->render(); + //} + //else { + // skipRenderFrameCount--; + //} //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 5e1eae6d..a2f68f2f 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -344,8 +344,8 @@ class NetworkMessageSynchNetworkGameData: public NetworkMessage{ private: -static const int maxStringSize= 100; -static const int maxFileCRCCount= 500; +static const int maxStringSize= 200; +static const int maxFileCRCCount= 400; private: diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 24939007..3574e770 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -52,6 +52,7 @@ World::World(){ ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCacheTimer.clear(); ExploredCellsLookupItemCacheTimerCount = 0; + FowAlphaCellsLookupItemCache.clear(); techTree = NULL; fogOfWarOverride = false; @@ -78,6 +79,7 @@ World::~World() { ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCacheTimer.clear(); + FowAlphaCellsLookupItemCache.clear(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -111,6 +113,7 @@ void World::end(){ ExploredCellsLookupItemCache.clear(); ExploredCellsLookupItemCacheTimer.clear(); + FowAlphaCellsLookupItemCache.clear(); for(int i= 0; igame = game; scriptManager= game->getScriptManager(); @@ -1133,13 +1137,32 @@ void World::computeFow(int factionIdxToTick) { //compute texture if(fogOfWar) { for(int i=0; ithisFactionIndex) { - Faction *faction= getFaction(i); - if(faction->getTeam() == thisTeamIndex){ - for(int j=0; jgetUnitCount(); ++j){ - const Unit *unit= faction->getUnit(j); - if(unit->isOperative()){ - int sightRange= unit->getType()->getSight(); + Faction *faction= getFaction(i); + if(faction->getTeam() == thisTeamIndex){ + for(int j=0; jgetUnitCount(); ++j){ + const Unit *unit= faction->getUnit(j); + if(unit->isOperative()){ + int sightRange= unit->getType()->getSight(); + + bool foundInCache = false; + std::map >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos()); + if(iterMap != FowAlphaCellsLookupItemCache.end()) { + std::map::iterator iterMap2 = iterMap->second.find(sightRange); + if(iterMap2 != iterMap->second.end()) { + foundInCache = true; + + FowAlphaCellsLookupItem &cellList = iterMap2->second; + for(int k = 0; k < cellList.surfPosList.size(); ++k) { + Vec2i &surfPos = cellList.surfPosList[k]; + float &alpha = cellList.alphaList[k]; + + minimap.incFowTextureAlphaSurface(surfPos, alpha); + } + } + } + + if(foundInCache == false) { + FowAlphaCellsLookupItem itemCache; //iterate through all cells PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange); @@ -1163,11 +1186,18 @@ void World::computeFow(int factionIdxToTick) { alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha); } minimap.incFowTextureAlphaSurface(surfPos, alpha); + + itemCache.surfPosList.push_back(surfPos); + itemCache.alphaList.push_back(alpha); + } + + if(itemCache.surfPosList.size() > 0) { + FowAlphaCellsLookupItemCache[unit->getPos()][sightRange] = itemCache; } } } } - //} + } } } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 3c3dcafa..83389673 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -70,6 +70,15 @@ public: static time_t lastDebug; }; +class FowAlphaCellsLookupItem { +public: + + std::vector surfPosList; + std::vector alphaList; + + static time_t lastDebug; +}; + class World{ private: typedef vector Factions; @@ -78,6 +87,8 @@ private: std::map ExploredCellsLookupItemCacheTimer; int ExploredCellsLookupItemCacheTimerCount; + std::map > FowAlphaCellsLookupItemCache; + public: static const int generationArea= 100; static const float airHeight;