mirror of
https://github.com/glest/glest-source.git
synced 2025-08-29 19:00:07 +02:00
- attempt to spread out faction world ticks for better performance
This commit is contained in:
@@ -307,9 +307,8 @@ void World::update(){
|
|||||||
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());
|
||||||
|
|
||||||
//tick
|
//tick
|
||||||
if(frameCount % GameConstants::updateFps == 0){
|
//if(frameCount % GameConstants::updateFps == 0) {
|
||||||
computeFow();
|
if(frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0) {
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
@@ -317,20 +316,50 @@ void World::update(){
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool World::canTickFaction(int factionIdx) {
|
||||||
|
int expectedFactionIdx = (frameCount / (GameConstants::updateFps / GameConstants::maxPlayers));
|
||||||
|
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);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void World::tick() {
|
void World::tick() {
|
||||||
if(!fogOfWarSmoothing){
|
int factionIdxToTick = -1;
|
||||||
|
for(int i=0; i<getFactionCount(); ++i) {
|
||||||
|
if(canTickFaction(i) == true) {
|
||||||
|
factionIdxToTick = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(factionIdxToTick < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
computeFow();
|
||||||
|
|
||||||
|
if(fogOfWarSmoothing == false) {
|
||||||
minimap.updateFowTex(1.f);
|
minimap.updateFowTex(1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//increase hp
|
//increase hp
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
int i = factionIdxToTick;
|
||||||
|
//for(int i=0; i<getFactionCount(); ++i) {
|
||||||
|
// if(canTickFaction(i) == true) {
|
||||||
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
|
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
|
||||||
getFaction(i)->getUnit(j)->tick();
|
getFaction(i)->getUnit(j)->tick();
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
//compute resources balance
|
//compute resources balance
|
||||||
for(int k=0; k<getFactionCount(); ++k){
|
int k = factionIdxToTick;
|
||||||
|
//for(int k=0; k<getFactionCount(); ++k) {
|
||||||
|
//if(canTickFaction(k) == true) {
|
||||||
Faction *faction= getFaction(k);
|
Faction *faction= getFaction(k);
|
||||||
|
|
||||||
//for each resource
|
//for each resource
|
||||||
@@ -354,7 +383,9 @@ void World::tick(){
|
|||||||
faction->setResourceBalance(rt, balance);
|
faction->setResourceBalance(rt, balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
if(cartographer != NULL) {
|
if(cartographer != NULL) {
|
||||||
cartographer->tick();
|
cartographer->tick();
|
||||||
}
|
}
|
||||||
|
@@ -200,6 +200,7 @@ private:
|
|||||||
|
|
||||||
//misc
|
//misc
|
||||||
void tick();
|
void tick();
|
||||||
|
bool canTickFaction(int factionIdx);
|
||||||
void computeFow();
|
void computeFow();
|
||||||
void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);
|
void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user