- attempt to spread out faction world ticks for better performance
This commit is contained in:
parent
bb456574eb
commit
db47a14940
|
@ -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,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());
|
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(){
|
bool World::canTickFaction(int factionIdx) {
|
||||||
if(!fogOfWarSmoothing){
|
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; 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 j=0; j<getFaction(i)->getUnitCount(); ++j){
|
//for(int i=0; i<getFactionCount(); ++i) {
|
||||||
getFaction(i)->getUnit(j)->tick();
|
// if(canTickFaction(i) == true) {
|
||||||
}
|
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
|
||||||
}
|
getFaction(i)->getUnit(j)->tick();
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
//compute resources balance
|
//compute resources balance
|
||||||
for(int k=0; k<getFactionCount(); ++k){
|
int k = factionIdxToTick;
|
||||||
Faction *faction= getFaction(k);
|
//for(int k=0; k<getFactionCount(); ++k) {
|
||||||
|
//if(canTickFaction(k) == true) {
|
||||||
|
Faction *faction= getFaction(k);
|
||||||
|
|
||||||
//for each resource
|
//for each resource
|
||||||
for(int i=0; i<techTree->getResourceTypeCount(); ++i){
|
for(int i=0; i<techTree->getResourceTypeCount(); ++i) {
|
||||||
const ResourceType *rt= techTree->getResourceType(i);
|
const ResourceType *rt= techTree->getResourceType(i);
|
||||||
|
|
||||||
//if consumable
|
//if consumable
|
||||||
if(rt->getClass()==rcConsumable){
|
if(rt->getClass()==rcConsumable) {
|
||||||
int balance= 0;
|
int balance= 0;
|
||||||
for(int j=0; j<faction->getUnitCount(); ++j){
|
for(int j=0; j<faction->getUnitCount(); ++j) {
|
||||||
|
|
||||||
//if unit operative and has this cost
|
//if unit operative and has this cost
|
||||||
const Unit *u= faction->getUnit(j);
|
const Unit *u= faction->getUnit(j);
|
||||||
if(u->isOperative()){
|
if(u->isOperative()) {
|
||||||
const Resource *r= u->getType()->getCost(rt);
|
const Resource *r= u->getType()->getCost(rt);
|
||||||
if(r!=NULL){
|
if(r!=NULL) {
|
||||||
balance-= u->getType()->getCost(rt)->getAmount();
|
balance-= u->getType()->getCost(rt)->getAmount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user