diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 68303c281..4295789e7 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -317,18 +317,19 @@ void World::update(){ } 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) { expectedFactionIdx = expectedFactionIdx % GameConstants::maxPlayers; } 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; } -void World::tick() { +int World::tickFactionIndex() { int factionIdxToTick = -1; for(int i=0; ithisFactionIndex) { + //if(frameCount % (GameConstants::updateFps) == 0) { + minimap.resetFowTex(); + //} if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); //reset cells - for(int i=0; isetVisible(k, false); + if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { + for(int i=0; isetVisible(k, false); + } } } } @@ -996,13 +1013,15 @@ 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()); //compute cells - for(int i=0; igetUnitCount(); ++j){ - Unit *unit= getFaction(i)->getUnit(j); + for(int i=0; ithisFactionIndex) { + for(int j=0; jgetUnitCount(); ++j) { + Unit *unit= getFaction(i)->getUnit(j); - //exploration - if(unit->isOperative()){ - exploreCells(unit->getCenteredPos(), unit->getType()->getSight(), unit->getTeam()); + //exploration + if(unit->isOperative()) { + exploreCells(unit->getCenteredPos(), unit->getType()->getSight(), unit->getTeam()); + } } } } @@ -1010,14 +1029,16 @@ 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()); //fire - for(int i=0; igetUnitCount(); ++j){ - Unit *unit= getFaction(i)->getUnit(j); + for(int i=0; ithisFactionIndex) { + for(int j=0; jgetUnitCount(); ++j){ + Unit *unit= getFaction(i)->getUnit(j); - //fire - ParticleSystem *fire= unit->getFire(); - if(fire!=NULL){ - fire->setActive(map.getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(thisTeamIndex)); + //fire + ParticleSystem *fire= unit->getFire(); + if(fire!=NULL){ + fire->setActive(map.getSurfaceCell(Map::toSurfCoords(unit->getPos()))->isVisible(thisTeamIndex)); + } } } } @@ -1025,53 +1046,48 @@ 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()); //compute texture - for(int i=0; igetTeam()==thisTeamIndex){ - for(int j=0; jgetUnitCount(); ++j){ - const Unit *unit= faction->getUnit(j); - if(unit->isOperative()){ - int sightRange= unit->getType()->getSight(); + 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(); - //iterate through all cells - PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange); - while(pci.next()){ - Vec2i pos= pci.getPos(); - Vec2i surfPos= Map::toSurfCoords(pos); + //iterate through all cells + PosCircularIterator pci(&map, unit->getPos(), sightRange+indirectSightRange); + while(pci.next()){ + const Vec2i pos= pci.getPos(); + Vec2i surfPos= Map::toSurfCoords(pos); + //compute max alpha + float maxAlpha= 0.0f; + if(surfPos.x>1 && surfPos.y>1 && surfPos.x0 && surfPos.y>0 && surfPos.x1 && surfPos.y>1 && surfPos.xgetPos().dist(pos); + if(dist>sightRange){ + alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha); + } + minimap.incFowTextureAlphaSurface(surfPos, alpha); } - else if(surfPos.x>0 && surfPos.y>0 && surfPos.xgetPos().dist(pos); - if(dist>sightRange){ - alpha= clamp(1.f-(dist-sightRange)/(indirectSightRange), 0.f, maxAlpha); - } - else{ - alpha= maxAlpha; - } - 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()); } -// 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) // Make sure each faction has their own unique section of id #'s for proper // multi-platform play diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index d454bff16..1585c4a59 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -201,7 +201,8 @@ private: //misc void tick(); bool canTickFaction(int factionIdx); - void computeFow(); + int tickFactionIndex(); + void computeFow(int factionIdxToTick=-1); void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex); void updateAllFactionUnits();