From db47a14940fc4505d809db26897b25c74cbf6972 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 23 Aug 2010 09:53:04 +0000 Subject: [PATCH] - attempt to spread out faction world ticks for better performance --- source/glest_game/world/world.cpp | 87 +++++++++++++++++++++---------- source/glest_game/world/world.h | 1 + 2 files changed, 60 insertions(+), 28 deletions(-) diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index cbb1d964..68303c28 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -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()); //tick - if(frameCount % GameConstants::updateFps == 0){ - computeFow(); - + //if(frameCount % GameConstants::updateFps == 0) { + 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()); tick(); @@ -317,44 +316,76 @@ 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()); } -void World::tick(){ - if(!fogOfWarSmoothing){ +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() { + int factionIdxToTick = -1; + for(int i=0; igetUnitCount(); ++j){ - getFaction(i)->getUnit(j)->tick(); - } - } + int i = factionIdxToTick; + //for(int i=0; igetUnitCount(); ++j) { + getFaction(i)->getUnit(j)->tick(); + } + // } + //} //compute resources balance - for(int k=0; kgetResourceTypeCount(); ++i){ - const ResourceType *rt= techTree->getResourceType(i); + //for each resource + for(int i=0; igetResourceTypeCount(); ++i) { + const ResourceType *rt= techTree->getResourceType(i); - //if consumable - if(rt->getClass()==rcConsumable){ - int balance= 0; - for(int j=0; jgetUnitCount(); ++j){ + //if consumable + if(rt->getClass()==rcConsumable) { + int balance= 0; + for(int j=0; jgetUnitCount(); ++j) { - //if unit operative and has this cost - const Unit *u= faction->getUnit(j); - if(u->isOperative()){ - const Resource *r= u->getType()->getCost(rt); - if(r!=NULL){ - balance-= u->getType()->getCost(rt)->getAmount(); + //if unit operative and has this cost + const Unit *u= faction->getUnit(j); + if(u->isOperative()) { + const Resource *r= u->getType()->getCost(rt); + if(r!=NULL) { + balance-= u->getType()->getCost(rt)->getAmount(); + } } } + faction->setResourceBalance(rt, balance); } - faction->setResourceBalance(rt, balance); } - } - } + //} + //} + if(cartographer != NULL) { cartographer->tick(); } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 62e100b8..d454bff1 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -200,6 +200,7 @@ private: //misc void tick(); + bool canTickFaction(int factionIdx); void computeFow(); void exploreCells(const Vec2i &newPos, int sightRange, int teamIndex);