- some performance updates to fog of war computation

This commit is contained in:
Mark Vejvoda 2010-08-23 15:10:37 +00:00
parent 284371f206
commit 70817a07d1

View File

@ -1046,42 +1046,44 @@ 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\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//compute texture //compute texture
for(int i=0; i<getFactionCount(); ++i) { if(fogOfWar) {
//if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { for(int i=0; i<getFactionCount(); ++i) {
Faction *faction= getFaction(i); //if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
if(faction->getTeam() == thisTeamIndex){ Faction *faction= getFaction(i);
for(int j=0; j<faction->getUnitCount(); ++j){ if(faction->getTeam() == thisTeamIndex){
const Unit *unit= faction->getUnit(j); for(int j=0; j<faction->getUnitCount(); ++j){
if(unit->isOperative()){ const Unit *unit= faction->getUnit(j);
int sightRange= unit->getType()->getSight(); if(unit->isOperative()){
int sightRange= unit->getType()->getSight();
//iterate through all cells //iterate through all cells
PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange); PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange);
while(pci.next()){ while(pci.next()){
const Vec2i pos= pci.getPos(); const Vec2i pos= pci.getPos();
Vec2i surfPos= Map::toSurfCoords(pos); Vec2i surfPos= Map::toSurfCoords(pos);
//compute max alpha //compute max alpha
float maxAlpha= 0.0f; float maxAlpha= 0.0f;
if(surfPos.x>1 && surfPos.y>1 && surfPos.x<map.getSurfaceW()-2 && surfPos.y<map.getSurfaceH()-2){ if(surfPos.x>1 && surfPos.y>1 && surfPos.x<map.getSurfaceW()-2 && surfPos.y<map.getSurfaceH()-2){
maxAlpha= 1.f; maxAlpha= 1.f;
} }
else if(surfPos.x>0 && surfPos.y>0 && surfPos.x<map.getSurfaceW()-1 && surfPos.y<map.getSurfaceH()-1){ else if(surfPos.x>0 && surfPos.y>0 && surfPos.x<map.getSurfaceW()-1 && surfPos.y<map.getSurfaceH()-1){
maxAlpha= 0.3f; maxAlpha= 0.3f;
} }
//compute alpha //compute alpha
float alpha=maxAlpha; float alpha=maxAlpha;
float dist= unit->getPos().dist(pos); float dist= unit->getPos().dist(pos);
if(dist>sightRange){ if(dist>sightRange){
alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha); alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha);
}
minimap.incFowTextureAlphaSurface(surfPos, alpha);
} }
minimap.incFowTextureAlphaSurface(surfPos, alpha);
} }
} }
} }
} //}
//} }
} }
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\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());