- added a cache for compute fog of war

This commit is contained in:
Mark Vejvoda 2010-08-25 23:55:59 +00:00
parent 0ef23749b8
commit 5a796444b8
4 changed files with 57 additions and 16 deletions

View File

@ -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__);

View File

@ -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:

View File

@ -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; i<factions.size(); ++i){
factions[i].end();
@ -142,6 +145,7 @@ void World::init(Game *game, bool createUnits){
ExploredCellsLookupItemCache.clear();
ExploredCellsLookupItemCacheTimer.clear();
FowAlphaCellsLookupItemCache.clear();
this->game = game;
scriptManager= game->getScriptManager();
@ -1133,13 +1137,32 @@ void World::computeFow(int factionIdxToTick) {
//compute texture
if(fogOfWar) {
for(int i=0; i<getFactionCount(); ++i) {
//if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex){
for(int j=0; j<faction->getUnitCount(); ++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; j<faction->getUnitCount(); ++j){
const Unit *unit= faction->getUnit(j);
if(unit->isOperative()){
int sightRange= unit->getType()->getSight();
bool foundInCache = false;
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > >::iterator iterMap = FowAlphaCellsLookupItemCache.find(unit->getPos());
if(iterMap != FowAlphaCellsLookupItemCache.end()) {
std::map<int, FowAlphaCellsLookupItem>::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;
}
}
}
}
//}
}
}
}

View File

@ -70,6 +70,15 @@ public:
static time_t lastDebug;
};
class FowAlphaCellsLookupItem {
public:
std::vector<Vec2i> surfPosList;
std::vector<float> alphaList;
static time_t lastDebug;
};
class World{
private:
typedef vector<Faction> Factions;
@ -78,6 +87,8 @@ private:
std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer;
int ExploredCellsLookupItemCacheTimerCount;
std::map<Vec2i, std::map<int, FowAlphaCellsLookupItem > > FowAlphaCellsLookupItemCache;
public:
static const int generationArea= 100;
static const float airHeight;