- some performance updates to fog of war computation

This commit is contained in:
Mark Vejvoda
2010-08-23 14:48:33 +00:00
parent db47a14940
commit 284371f206
2 changed files with 79 additions and 62 deletions

View File

@@ -317,18 +317,19 @@ void World::update(){
} }
bool World::canTickFaction(int factionIdx) { bool World::canTickFaction(int factionIdx) {
int expectedFactionIdx = (frameCount / (GameConstants::updateFps / GameConstants::maxPlayers)); int factionUpdateInterval = (GameConstants::updateFps / GameConstants::maxPlayers);
int expectedFactionIdx = (frameCount / factionUpdateInterval) -1;
if(expectedFactionIdx >= GameConstants::maxPlayers) { if(expectedFactionIdx >= GameConstants::maxPlayers) {
expectedFactionIdx = expectedFactionIdx % GameConstants::maxPlayers; expectedFactionIdx = expectedFactionIdx % GameConstants::maxPlayers;
} }
bool result = (expectedFactionIdx == factionIdx); bool result = (expectedFactionIdx == factionIdx);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdx = %d, frameCount = %d, GameConstants::updateFps = %d, result = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdx,frameCount,GameConstants::updateFps,result); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdx = %d, frameCount = %d, GameConstants::updateFps = %d, expectedFactionIdx = %d, factionUpdateInterval = %d, result = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdx,frameCount,GameConstants::updateFps,expectedFactionIdx,factionUpdateInterval,result);
return result; return result;
} }
void World::tick() { int World::tickFactionIndex() {
int factionIdxToTick = -1; int factionIdxToTick = -1;
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
if(canTickFaction(i) == true) { if(canTickFaction(i) == true) {
@@ -336,15 +337,25 @@ void World::tick() {
break; break;
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdxToTick = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick);
return factionIdxToTick;
}
void World::tick() {
int factionIdxToTick = tickFactionIndex();
if(factionIdxToTick < 0) { if(factionIdxToTick < 0) {
return; return;
} }
computeFow(); computeFow(factionIdxToTick);
if(factionIdxToTick == 0) {
if(fogOfWarSmoothing == false) { if(fogOfWarSmoothing == false) {
minimap.updateFowTex(1.f); minimap.updateFowTex(1.f);
} }
}
//increase hp //increase hp
int i = factionIdxToTick; int i = factionIdxToTick;
@@ -973,16 +984,21 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){
} }
//computes the fog of war texture, contained in the minimap //computes the fog of war texture, contained in the minimap
void World::computeFow(){ void World::computeFow(int factionIdxToTick) {
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
//reset texture //reset texture
//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) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
//reset cells //reset cells
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
for(int i=0; i<map.getSurfaceW(); ++i) { for(int i=0; i<map.getSurfaceW(); ++i) {
for(int j=0; j<map.getSurfaceH(); ++j) { for(int j=0; j<map.getSurfaceH(); ++j) {
for(int k=0; k<GameConstants::maxPlayers; ++k) { for(int k=0; k<GameConstants::maxPlayers; ++k) {
@@ -992,11 +1008,13 @@ void World::computeFow(){
} }
} }
} }
}
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 cells //compute cells
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) { for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
Unit *unit= getFaction(i)->getUnit(j); Unit *unit= getFaction(i)->getUnit(j);
@@ -1006,11 +1024,13 @@ void World::computeFow(){
} }
} }
} }
}
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());
//fire //fire
for(int i=0; i<getFactionCount(); ++i) { for(int i=0; i<getFactionCount(); ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){ for(int j=0; j<getFaction(i)->getUnitCount(); ++j){
Unit *unit= getFaction(i)->getUnit(j); Unit *unit= getFaction(i)->getUnit(j);
@@ -1021,11 +1041,13 @@ void World::computeFow(){
} }
} }
} }
}
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) { for(int i=0; i<getFactionCount(); ++i) {
//if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
Faction *faction= getFaction(i); Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex){ if(faction->getTeam() == thisTeamIndex){
for(int j=0; j<faction->getUnitCount(); ++j){ for(int j=0; j<faction->getUnitCount(); ++j){
@@ -1036,42 +1058,36 @@ void World::computeFow(){
//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()){
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; 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;
} }
else{
maxAlpha= 0.0f;
}
//compute alpha //compute alpha
float alpha; 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);
} }
else{
alpha= 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());
} }
// WARNING! This id is critical! MAke sure it fits inside the network packet // WARNING! This id is critical! Make sure it fits inside the network packet
// (currently cannot be larger than 2,147,483,647) // (currently cannot be larger than 2,147,483,647)
// Make sure each faction has their own unique section of id #'s for proper // Make sure each faction has their own unique section of id #'s for proper
// multi-platform play // multi-platform play

View File

@@ -201,7 +201,8 @@ private:
//misc //misc
void tick(); void tick();
bool canTickFaction(int factionIdx); bool canTickFaction(int factionIdx);
void computeFow(); int tickFactionIndex();
void computeFow(int factionIdxToTick=-1);
void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex); void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);
void updateAllFactionUnits(); void updateAllFactionUnits();