- attempt ot get fine details of performance bottlenecks

- attempt to improve performance a bit
This commit is contained in:
Mark Vejvoda 2013-11-11 08:28:15 +00:00
parent f1abe148ea
commit 9625bd77a4
10 changed files with 345 additions and 289 deletions

View File

@ -1959,7 +1959,7 @@ void Game::update() {
}
}
addGamePerformanceCount("CalculateNetworkUpdateLoops",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("CalculateNetworkUpdateLoops",chronoGamePerformanceCounts.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(showPerfStats) {
@ -1981,7 +1981,7 @@ void Game::update() {
ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role);
addGamePerformanceCount("ReplaceDisconnectedNetworkPlayersWithAI",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ReplaceDisconnectedNetworkPlayersWithAI",chronoGamePerformanceCounts.getMillis());
setupPopupMenus(true);
@ -2021,7 +2021,7 @@ void Game::update() {
processNetworkSynchChecksIfRequired();
addGamePerformanceCount("CalculateNetworkCRCSynchChecks",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("CalculateNetworkCRCSynchChecks",chronoGamePerformanceCounts.getMillis());
const bool newThreadManager = Config::getInstance().getBool("EnableNewThreadManager","false");
if(newThreadManager == true) {
@ -2085,7 +2085,7 @@ void Game::update() {
}
}
addGamePerformanceCount("ProcessAIWorkerThreads",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ProcessAIWorkerThreads",chronoGamePerformanceCounts.getMillis());
}
if(showPerfStats) {
@ -2150,7 +2150,7 @@ void Game::update() {
if(pendingQuitError == false) world.update();
addGamePerformanceCount("ProcessWorldUpdate",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ProcessWorldUpdate",chronoGamePerformanceCounts.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [world update i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2191,7 +2191,7 @@ void Game::update() {
if(pendingQuitError == false) commander.signalNetworkUpdate(this);
addGamePerformanceCount("ProcessNetworkUpdate",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ProcessNetworkUpdate",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -2206,7 +2206,7 @@ void Game::update() {
gui.update();
addGamePerformanceCount("ProcessGUIUpdate",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ProcessGUIUpdate",chronoGamePerformanceCounts.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [gui updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2235,7 +2235,7 @@ void Game::update() {
renderer.updateParticleManager(rsGame,avgRenderFps);
addGamePerformanceCount("ProcessParticleManager",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ProcessParticleManager",chronoGamePerformanceCounts.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [particle manager updating i = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2303,7 +2303,7 @@ void Game::update() {
perfList.push_back(perfBuf);
}
addGamePerformanceCount("ProcessMiscNetwork",chronoGamePerformanceCounts.getMillis());
addPerformanceCount("ProcessMiscNetwork",chronoGamePerformanceCounts.getMillis());
// START - Handle joining in progress games
if(role == nrServer) {
@ -2752,7 +2752,7 @@ void Game::update() {
}
}
void Game::addGamePerformanceCount(string key,int64 value) {
void Game::addPerformanceCount(string key,int64 value) {
gamePerformanceCounts[key] = value + gamePerformanceCounts[key] / 2;
}
@ -2762,12 +2762,18 @@ string Game::getGamePerformanceCounts(bool displayWarnings) const {
}
bool displayWarningHeader = true;
int WARNING_MILLIS = Config::getInstance().getInt("PerformanceWarningMillis","10");
int WARNING_MILLIS = Config::getInstance().getInt("PerformanceWarningMillis","7");
int WARNING_RENDER_MILLIS = Config::getInstance().getInt("PerformanceWarningRenderMillis","40");
string result = "";
for(std::map<string,int64>::const_iterator iterMap = gamePerformanceCounts.begin();
iterMap != gamePerformanceCounts.end(); ++iterMap) {
if(iterMap->second < WARNING_MILLIS) {
if(iterMap->first == ProgramState::MAIN_PROGRAM_RENDER_KEY) {
if(iterMap->second < WARNING_RENDER_MILLIS) {
continue;
}
}
else if(iterMap->second < WARNING_MILLIS) {
continue;
}

View File

@ -340,7 +340,7 @@ public:
void setDisableSpeedChange(bool value) { disableSpeedChange = value; }
string getGamePerformanceCounts(bool displayWarnings) const;
void addGamePerformanceCount(string key,int64 value);
virtual void addPerformanceCount(string key,int64 value);
bool getRenderInGamePerformance() const { return renderInGamePerformance; }
private:

View File

@ -45,6 +45,7 @@ Program *Program::singleton = NULL;
const int SOUND_THREAD_UPDATE_MILLISECONDS = 25;
bool Program::wantShutdownApplicationAfterGame = false;
const char *ProgramState::MAIN_PROGRAM_RENDER_KEY = "MEGAGLEST.RENDER";
// =====================================================
// class Program::CrashProgramState
@ -386,6 +387,8 @@ void Program::loopWorker() {
}
}
Chrono chronoPerformanceCounts;
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
@ -422,8 +425,13 @@ void Program::loopWorker() {
}
assert(programState != NULL);
chronoPerformanceCounts.start();
programState->render();
programState->addPerformanceCount(ProgramState::MAIN_PROGRAM_RENDER_KEY,chronoPerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
@ -434,10 +442,15 @@ void Program::loopWorker() {
//update camera
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
while(updateCameraTimer.isTime()){
chronoPerformanceCounts.start();
while(updateCameraTimer.isTime()) {
programState->updateCamera();
}
programState->addPerformanceCount("programState->updateCamera()",chronoPerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
@ -459,6 +472,7 @@ void Program::loopWorker() {
GraphicComponent::update();
programState->update();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] programState->update took msecs: %lld, updateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
@ -468,6 +482,8 @@ void Program::loopWorker() {
}
if(prevState == this->programState) {
chronoPerformanceCounts.start();
if(soundThreadManager == NULL || soundThreadManager->isThreadExecutionLagging()) {
if(soundThreadManager != NULL) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] ERROR / WARNING soundThreadManager->isThreadExecutionLagging is TRUE\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -478,12 +494,19 @@ void Program::loopWorker() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
}
programState->addPerformanceCount("SoundRenderer::getInstance().update()",chronoPerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " updateCount: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),updateCount);
perfList.push_back(perfBuf);
}
chronoPerformanceCounts.start();
NetworkManager::getInstance().update();
programState->addPerformanceCount("NetworkManager::getInstance().update()",chronoPerformanceCounts.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] NetworkManager::getInstance().update() took msecs: %lld, updateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
@ -507,11 +530,15 @@ void Program::loopWorker() {
if(prevState == this->programState) {
//fps timer
chronoPerformanceCounts.start();
chrono.start();
while(fpsTimer.isTime()) {
programState->tick();
}
programState->addPerformanceCount("programState->tick()",chronoPerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);

View File

@ -65,6 +65,9 @@ protected:
int lastFps;
public:
static const char *MAIN_PROGRAM_RENDER_KEY;
ProgramState(Program *program);
virtual ~ProgramState(){};
@ -105,6 +108,7 @@ public:
virtual void consoleAddLine(string line) { };
virtual void reloadUI() {};
virtual void addPerformanceCount(string key,int64 value) {};
protected:
virtual void incrementFps();

View File

@ -558,6 +558,64 @@ void Faction::end() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void Faction::notifyUnitAliveStatusChange(const Unit *unit) {
if(unit != NULL) {
if(unit->isAlive() == true) {
aliveUnitList[unit->getId()] = unit;
if(unit->getType()->isMobile() == true) {
mobileUnitList[unit->getId()] = unit;
}
}
else {
aliveUnitList.erase(unit->getId());
if(unit->getType()->isMobile() == true) {
mobileUnitList.erase(unit->getId());
}
}
}
}
void Faction::notifyUnitTypeChange(const Unit *unit, const UnitType *newType) {
if(unit != NULL) {
if(unit->getType()->isMobile() == true) {
mobileUnitList.erase(unit->getId());
}
if(newType != NULL && newType->isMobile() == true) {
mobileUnitList[unit->getId()] = unit;
}
}
}
void Faction::notifyUnitSkillTypeChange(const Unit *unit, const SkillType *newType) {
if(unit != NULL) {
if(unit->isBeingBuilt() == true) {
beingBuiltUnitList.erase(unit->getId());
}
if(newType != NULL && newType->getClass() == scBeBuilt) {
beingBuiltUnitList[unit->getId()] = unit;
}
}
}
bool Faction::hasAliveUnits(bool filterMobileUnits, bool filterBuiltUnits) const {
bool result = false;
if(aliveUnitList.empty() == false) {
if(filterMobileUnits == true) {
result = (mobileUnitList.empty() == false);
}
else {
result = true;
}
if(result == true && filterBuiltUnits == true) {
result = (beingBuiltUnitList.empty() == true);
}
}
return result;
}
FactionPersonalityType Faction::getPersonalityType() const {
if(overridePersonalityType != fpt_EndCount) {

View File

@ -171,6 +171,10 @@ private:
std::map<int,string> crcWorldFrameDetails;
std::map<int,const Unit *> aliveUnitList;
std::map<int,const Unit *> mobileUnitList;
std::map<int,const Unit *> beingBuiltUnitList;
public:
Faction();
~Faction();
@ -184,6 +188,11 @@ public:
throw megaglest_runtime_error("class Faction is NOT safe to assign!");
}
void notifyUnitAliveStatusChange(const Unit *unit);
void notifyUnitTypeChange(const Unit *unit, const UnitType *newType);
void notifyUnitSkillTypeChange(const Unit *unit, const SkillType *newType);
bool hasAliveUnits(bool filterMobileUnits, bool filterBuiltUnits) const;
inline void addWorldSynchThreadedLogList(const string &data) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
worldSynchThreadedLogList.push_back(data);

View File

@ -419,9 +419,12 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
}
this->pos=pos;
this->preMorph_type = NULL;
this->type=type;
this->faction=faction;
this->preMorph_type = NULL;
this->type=type;
setType(this->type);
this->map= map;
this->targetRef = NULL;
this->targetField = fLand;
@ -465,7 +468,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
highlight= 0.f;
meetingPos= pos;
alive= true;
setAlive(true);
if (type->hasSkillClass(scBeBuilt) == false) {
float rot= 0.f;
@ -490,6 +493,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
this->lastModelIndexForCurrSkillType = -1;
this->animationRandomCycleCount = 0;
this->currSkill = getType()->getFirstStOfClass(scStop);
this->setCurrSkill(this->currSkill);
this->currentAttackBoostOriginatorEffect.skillType = this->currSkill;
this->faction->addLivingUnits(id);
@ -594,6 +598,16 @@ ParticleSystem * Unit::getFire() const {
return this->fire;
}
void Unit::setType(const UnitType *newType) {
this->faction->notifyUnitTypeChange(this, newType);
this->type = newType;
}
void Unit::setAlive(bool value) {
this->alive = value;
this->faction->notifyUnitAliveStatusChange(this);
}
#ifdef LEAK_CHECK_UNITS
void Unit::dumpMemoryList() {
printf("===== START report of Unfreed Unit pointers =====\n");
@ -1164,6 +1178,8 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
this->lastModelIndexForCurrSkillType = -1;
this->animationRandomCycleCount = 0;
}
if(faction != NULL) faction->notifyUnitSkillTypeChange(this, currSkill);
const SkillType *original_skill = this->currSkill;
this->currSkill= currSkill;
@ -2694,7 +2710,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
//stop DamageParticles on death
if(this->hp <= 0) {
this->alive= false;
setAlive(false);
this->hp=0;
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
@ -2790,7 +2806,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) {
//stop DamageParticles on death
if(this->hp <= 0) {
this->alive= false;
setAlive(false);
this->hp=0;
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
@ -3078,7 +3094,7 @@ bool Unit::decHp(int decrementValue) {
//stop DamageParticles on death
if(this->hp <= 0) {
this->alive = false;
setAlive(false);
this->hp = 0;
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);
@ -3340,7 +3356,7 @@ bool Unit::morph(const MorphCommandType *mct) {
checkModelStateInfoForNewHpValue();
this->preMorph_type = this->type;
this->type= morphUnitType;
this->setType(morphUnitType);
Field original_field = this->currField;
this->currField=morphUnitField;
computeTotalUpgrade();
@ -4768,6 +4784,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
string skillTypeName = unitNode->getAttribute("currSkillName")->getValue();
SkillClass skillClass = static_cast<SkillClass>(unitNode->getAttribute("currSkillClass")->getIntValue());
result->currSkill = ut->getSkillType(skillTypeName,skillClass);
result->setCurrSkill(result->currSkill);
}
// int lastModelIndexForCurrSkillType;
@ -4778,7 +4795,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction *
// bool toBeUndertaken;
result->toBeUndertaken = unitNode->getAttribute("toBeUndertaken")->getIntValue() != 0;
// bool alive;
result->alive = unitNode->getAttribute("alive")->getIntValue() != 0;
result->setAlive(unitNode->getAttribute("alive")->getIntValue() != 0);
// bool showUnitParticles;
result->showUnitParticles = unitNode->getAttribute("showUnitParticles")->getIntValue() != 0;
// Faction *faction;

View File

@ -494,7 +494,6 @@ public:
void setCurrentPathFinderDesiredFinalPos(const Vec2i &finalPos) { currentPathFinderDesiredFinalPos = finalPos; }
Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; }
//const std::pair<const SkillType *,std::vector<Unit *> > & getCurrentAttackBoostUnits() const { return currentAttackBoostUnits; }
const UnitAttackBoostEffectOriginator & getAttackBoostOriginatorEffect() const { return currentAttackBoostOriginatorEffect; }
bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const;
@ -540,7 +539,9 @@ public:
inline Vec2i getMeetingPos() const {return meetingPos;}
inline Faction *getFaction() const {return faction;}
inline const ResourceType *getLoadType() const {return loadType;}
inline const UnitType *getType() const {return type;}
void setType(const UnitType *newType);
inline const UnitType *getPreMorphType() const {return preMorph_type;}
inline const SkillType *getCurrSkill() const {return currSkill;}
@ -813,6 +814,8 @@ private:
void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false);
void updateAttackBoostProgress(const Game* game);
void setAlive(bool value);
};
}}// end namespace

View File

@ -47,8 +47,6 @@ World::World() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Config &config= Config::getInstance();
//staggeredFactionUpdates = config.getBool("StaggeredFactionUpdates","false");
staggeredFactionUpdates = false;
unitParticlesEnabled=config.getBool("UnitParticles","true");
animatedTilesetObjectPosListLoaded = false;
@ -762,42 +760,33 @@ void World::updateAllFactionUnits() {
void World::underTakeDeadFactionUnits() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
int factionIdxToTick = -1;
if(staggeredFactionUpdates == true) {
factionIdxToTick = tickFactionIndex();
if(factionIdxToTick < 0) {
return;
}
}
int factionCount = getFactionCount();
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] factionIdxToTick = %d, factionCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,factionCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] factionCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//undertake the dead
for(int i = 0; i< factionCount; ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == i) {
Faction *faction = getFaction(i);
int unitCount = faction->getUnitCount();
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] factionIdxToTick = %d, i = %d, unitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,i,unitCount);
Faction *faction = getFaction(i);
int unitCount = faction->getUnitCount();
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] i = %d, unitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,i,unitCount);
for(int j= unitCount - 1; j >= 0; j--) {
Unit *unit= faction->getUnit(j);
for(int j= unitCount - 1; j >= 0; j--) {
Unit *unit= faction->getUnit(j);
if(unit == NULL) {
throw megaglest_runtime_error("unit == NULL");
}
if(unit->getToBeUndertaken() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
unit->undertake();
delete unit;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
if(unit == NULL) {
throw megaglest_runtime_error("unit == NULL");
}
}
if(unit->getToBeUndertaken() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
unit->undertake();
delete unit;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
}
@ -860,7 +849,7 @@ void World::update() {
updateAllTilesetObjects();
if(this->game) this->game->addGamePerformanceCount("updateAllTilesetObjects",chronoGamePerformanceCounts.getMillis());
if(this->game) this->game->addPerformanceCount("updateAllTilesetObjects",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -873,7 +862,7 @@ void World::update() {
updateAllFactionUnits();
if(this->game) this->game->addGamePerformanceCount("updateAllFactionUnits",chronoGamePerformanceCounts.getMillis());
if(this->game) this->game->addPerformanceCount("updateAllFactionUnits",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -885,7 +874,7 @@ void World::update() {
underTakeDeadFactionUnits();
if(this->game) this->game->addGamePerformanceCount("underTakeDeadFactionUnits",chronoGamePerformanceCounts.getMillis());
if(this->game) this->game->addPerformanceCount("underTakeDeadFactionUnits",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -899,7 +888,7 @@ void World::update() {
updateAllFactionConsumableCosts();
if(this->game) this->game->addGamePerformanceCount("updateAllFactionConsumableCosts",chronoGamePerformanceCounts.getMillis());
if(this->game) this->game->addPerformanceCount("updateAllFactionConsumableCosts",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -914,7 +903,7 @@ void World::update() {
float fogFactor= static_cast<float>(frameCount % GameConstants::updateFps) / GameConstants::updateFps;
minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f));
if(this->game) this->game->addGamePerformanceCount("minimap.updateFowTex",chronoGamePerformanceCounts.getMillis());
if(this->game) this->game->addPerformanceCount("minimap.updateFowTex",chronoGamePerformanceCounts.getMillis());
}
if(showPerfStats) {
@ -939,7 +928,7 @@ void World::update() {
tick();
if(this->game) this->game->addGamePerformanceCount("tick",chronoGamePerformanceCounts.getMillis());
if(this->game) this->game->addPerformanceCount("world->tick",chronoGamePerformanceCounts.getMillis());
}
if(showPerfStats) {
@ -959,10 +948,6 @@ void World::update() {
bool World::canTickWorld() const {
//tick
bool needToTick = (frameCount % GameConstants::updateFps == 0);
if(staggeredFactionUpdates == true) {
needToTick = (frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0);
}
return needToTick;
}
@ -979,20 +964,6 @@ bool World::canTickFaction(int factionIdx) {
return result;
}
int World::tickFactionIndex() {
int factionIdxToTick = -1;
for(int i=0; i<getFactionCount(); ++i) {
if(canTickFaction(i) == true) {
factionIdxToTick = i;
break;
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] factionIdxToTick = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick);
return factionIdxToTick;
}
void World::tick() {
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
@ -1000,30 +971,29 @@ void World::tick() {
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
int factionIdxToTick = -1;
if(staggeredFactionUpdates == true) {
factionIdxToTick = tickFactionIndex();
if(factionIdxToTick < 0) {
return;
}
}
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
computeFow(factionIdxToTick);
Chrono chronoGamePerformanceCounts;
if(this->game) chronoGamePerformanceCounts.start();
computeFow();
if(this->game) this->game->addPerformanceCount("world->computeFow",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER " fogOfWar: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis(),fogOfWar);
perfList.push_back(perfBuf);
}
if(factionIdxToTick == -1 || factionIdxToTick == 0) {
if(fogOfWarSmoothing == false) {
minimap.updateFowTex(1.f);
}
if(fogOfWarSmoothing == false) {
if(this->game) chronoGamePerformanceCounts.start();
minimap.updateFowTex(1.f);
if(this->game) this->game->addPerformanceCount("minimap.updateFowTex",chronoGamePerformanceCounts.getMillis());
}
if(showPerfStats) {
@ -1032,22 +1002,23 @@ void World::tick() {
}
//increase hp
if(this->game) chronoGamePerformanceCounts.start();
int factionCount = getFactionCount();
for(int i = 0; i < factionCount; ++i) {
if(factionIdxToTick == -1 || i == factionIdxToTick) {
Faction *faction = getFaction(i);
int unitCount = faction->getUnitCount();
for(int factionIndex = 0; factionIndex < factionCount; ++factionIndex) {
Faction *faction = getFaction(factionIndex);
int unitCount = faction->getUnitCount();
for(int j = 0; j < unitCount; ++j) {
Unit *unit = faction->getUnit(j);
if(unit == NULL) {
throw megaglest_runtime_error("unit == NULL");
}
unit->tick();
for(int unitIndex = 0; unitIndex < unitCount; ++unitIndex) {
Unit *unit = faction->getUnit(unitIndex);
if(unit == NULL) {
throw megaglest_runtime_error("unit == NULL");
}
unit->tick();
}
}
if(this->game) this->game->addPerformanceCount("world unit->tick()",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -1055,34 +1026,48 @@ void World::tick() {
}
//compute resources balance
if(this->game) chronoGamePerformanceCounts.start();
std::map<const UnitType *, std::map<const ResourceType *, const Resource *> > resourceCostCache;
factionCount = getFactionCount();
for(int k = 0; k < factionCount; ++k) {
if(factionIdxToTick == -1 || k == factionIdxToTick) {
Faction *faction= getFaction(k);
for(int factionIndex = 0; factionIndex < factionCount; ++factionIndex) {
Faction *faction = getFaction(factionIndex);
//for each resource
for(int i = 0; i < techTree->getResourceTypeCount(); ++i) {
const ResourceType *rt= techTree->getResourceType(i);
//for each resource
for(int resourceTypeIndex = 0;
resourceTypeIndex < techTree->getResourceTypeCount(); ++resourceTypeIndex) {
const ResourceType *rt= techTree->getResourceType(resourceTypeIndex);
//if consumable
if(rt != NULL && rt->getClass()==rcConsumable) {
int balance= 0;
for(int j = 0; j < faction->getUnitCount(); ++j) {
//if consumable
if(rt != NULL && rt->getClass() == rcConsumable) {
int balance= 0;
for(int unitIndex = 0;
unitIndex < faction->getUnitCount(); ++unitIndex) {
//if unit operative and has this cost
const Unit *u= faction->getUnit(j);
if(u != NULL && 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 *unit = faction->getUnit(unitIndex);
if(unit != NULL && unit->isOperative()) {
const UnitType *ut = unit->getType();
const Resource *resource = NULL;
std::map<const UnitType *, std::map<const ResourceType *, const Resource *> >::iterator iterFind = resourceCostCache.find(ut);
if(iterFind != resourceCostCache.end() &&
iterFind->second.find(rt) != iterFind->second.end()) {
resource = iterFind->second.find(rt)->second;
}
else {
resource = ut->getCost(rt);
resourceCostCache[ut][rt] = resource;
}
if(resource != NULL) {
balance -= resource->getAmount();
}
}
faction->setResourceBalance(rt, balance);
}
faction->setResourceBalance(rt, balance);
}
}
}
if(this->game) this->game->addPerformanceCount("world faction->setResourceBalance()",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
@ -2093,8 +2078,6 @@ void World::initFactionTypes(GameSettings *gs) {
//
// bool unitParticlesEnabled;
unitParticlesEnabled = loadWorldNode->getAttribute("unitParticlesEnabled")->getIntValue() != 0;
// bool staggeredFactionUpdates;
staggeredFactionUpdates = loadWorldNode->getAttribute("staggeredFactionUpdates")->getIntValue() != 0;
// std::map<string,StaticSound *> staticSoundList;
// std::map<string,StrSound *> streamSoundList;
//
@ -2414,7 +2397,8 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
bool World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) const {
bool ret = false;
if(excludeFogOfWarCheck == false && fogOfWarSkillTypeValue == 0 && fogOfWarOverride == true) {
if(excludeFogOfWarCheck == false &&
fogOfWarSkillTypeValue == 0 && fogOfWarOverride == true) {
ret = true;
}
else if(factionIndex == thisFactionIndex && game != NULL) {
@ -2439,13 +2423,18 @@ bool World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) cons
if(getStats()->getVictory(factionIndex) == false) {
// If the player has at least 1 Unit alive that is mobile (can move)
// then we cannot turn off fog of war
for(int i = 0; i < getFaction(factionIndex)->getUnitCount(); ++i) {
Unit *unit = getFaction(factionIndex)->getUnit(i);
if(unit != NULL && unit->isAlive() && unit->getType()->isMobile() == true) {
ret = false;
break;
}
}
const Faction *faction = getFaction(factionIndex);
// for(int i = 0; i < faction->getUnitCount(); ++i) {
// Unit *unit = getFaction(factionIndex)->getUnit(i);
// if(unit != NULL && unit->isAlive() && unit->getType()->isMobile() == true) {
// ret = false;
// break;
// }
// }
if(faction->hasAliveUnits(true,false) == true) {
ret = false;
}
}
}
}
@ -2454,94 +2443,67 @@ bool World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) cons
}
//computes the fog of war texture, contained in the minimap
void World::computeFow(int factionIdxToTick) {
void World::computeFow() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf;
char perfBuf[8096]="";
std::vector<string> perfList;
if(showPerfStats) chronoPerf.start();
//bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
//Chrono chronoPerf;
//char perfBuf[8096]="";
//std::vector<string> perfList;
//if(showPerfStats) chronoPerf.start();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
Chrono chronoGamePerformanceCounts;
if(this->game) chronoGamePerformanceCounts.start();
minimap.resetFowTex();
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(this->game) this->game->addPerformanceCount("world minimap.resetFowTex",chronoGamePerformanceCounts.getMillis());
// if(showPerfStats) {
// sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
// perfList.push_back(perfBuf);
// }
// reset cells
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
//reset cells
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
for(int i = 0; i < map.getSurfaceW(); ++i) {
for(int j = 0; j < map.getSurfaceH(); ++j) {
for(int k = 0; k < GameConstants::maxPlayers + GameConstants::specialFactions; ++k) {
if(fogOfWar || k != thisTeamIndex) {
map.getSurfaceCell(i, j)->setVisible(k, false);
if(showWorldForPlayer(k) == true) {
const Vec2i pos(i,j);
Vec2i surfPos= pos;
//compute max alpha
float maxAlpha= 0.0f;
if(surfPos.x > 1 && surfPos.y > 1 &&
surfPos.x < map.getSurfaceW() - 2 &&
surfPos.y < map.getSurfaceH() - 2) {
maxAlpha= 1.f;
}
else if(surfPos.x > 0 && surfPos.y > 0 &&
surfPos.x < map.getSurfaceW() - 1 &&
surfPos.y < map.getSurfaceH() - 1){
maxAlpha= 0.3f;
}
if(this->game) chronoGamePerformanceCounts.start();
//compute alpha
float alpha=maxAlpha;
minimap.incFowTextureAlphaSurface(surfPos, alpha);
}
//else {
// map.getSurfaceCell(i, j)->setVisible(k, false);
//}
}
}
int resetFowAlphaFactionCount = 0;
for(int indexFaction = 0;
indexFaction < GameConstants::maxPlayers + GameConstants::specialFactions;
++indexFaction) {
if(fogOfWar || indexFaction != thisTeamIndex) {
bool showWorldForFaction = showWorldForPlayer(indexFaction);
if(showWorldForFaction == true) {
resetFowAlphaFactionCount++;
}
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
// Deal with observers
for(int i = 0; i < map.getSurfaceW(); ++i) {
for(int j = 0; j < map.getSurfaceH(); ++j) {
for(int k = 0; k < GameConstants::maxPlayers + GameConstants::specialFactions; ++k) {
if(fogOfWar || k != thisTeamIndex) {
if(k == thisTeamIndex && thisTeamIndex == GameConstants::maxPlayers -1 + fpt_Observer) {
//map.getSurfaceCell(i, j)->setVisible(k, true);
//map.getSurfaceCell(i, j)->setExplored(k, true);
const Vec2i pos(i,j);
Vec2i surfPos= pos;
for(int indexSurfaceW = 0; indexSurfaceW < map.getSurfaceW(); ++indexSurfaceW) {
for(int indexSurfaceH = 0; indexSurfaceH < map.getSurfaceH(); ++indexSurfaceH) {
map.getSurfaceCell(indexSurfaceW, indexSurfaceH)->setVisible(indexFaction, false);
//compute max alpha
float maxAlpha= 0.0f;
if(surfPos.x > 1 && surfPos.y > 1 &&
surfPos.x < map.getSurfaceW() - 2 &&
surfPos.y < map.getSurfaceH() - 2) {
maxAlpha= 1.f;
}
else if(surfPos.x > 0 && surfPos.y > 0 &&
surfPos.x < map.getSurfaceW() - 1 &&
surfPos.y < map.getSurfaceH() - 1){
maxAlpha= 0.3f;
}
if(showWorldForFaction == true && resetFowAlphaFactionCount <= 1) {
const Vec2i surfPos(indexSurfaceW,indexSurfaceH);
//compute alpha
float alpha=maxAlpha;
minimap.incFowTextureAlphaSurface(surfPos, alpha);
//compute max alpha
float maxAlpha= 0.0f;
if(surfPos.x > 1 && surfPos.y > 1 &&
surfPos.x < map.getSurfaceW() - 2 &&
surfPos.y < map.getSurfaceH() - 2) {
maxAlpha= 1.f;
}
else if(surfPos.x > 0 && surfPos.y > 0 &&
surfPos.x < map.getSurfaceW() - 1 &&
surfPos.y < map.getSurfaceH() - 1){
maxAlpha= 0.3f;
}
//compute alpha
float alpha = maxAlpha;
minimap.incFowTextureAlphaSurface(surfPos, alpha);
}
}
}
@ -2549,103 +2511,81 @@ void World::computeFow(int factionIdxToTick) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
}
if(this->game) this->game->addPerformanceCount("world reset cells",chronoGamePerformanceCounts.getMillis());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
// if(showPerfStats) {
// sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
// perfList.push_back(perfBuf);
// }
//compute cells
for(int i=0; i<getFactionCount(); ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
Unit *unit= getFaction(i)->getUnit(j);
if(this->game) chronoGamePerformanceCounts.start();
//exploration
unit->exploreCells();
}
}
}
for(int factionIndex = 0; factionIndex < getFactionCount(); ++factionIndex) {
Faction *faction = getFaction(factionIndex);
bool cellVisibleForFaction = showWorldForPlayer(thisFactionIndex);
int unitCount = faction->getUnitCount();
for(int unitIndex = 0; unitIndex < unitCount; ++unitIndex) {
Unit *unit= faction->getUnit(unitIndex);
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
// exploration
unit->exploreCells();
//fire
for(int i=0; i<getFactionCount(); ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
bool cellVisibleForFaction = showWorldForPlayer(thisFactionIndex);
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){
Unit *unit= getFaction(i)->getUnit(j);
//fire
ParticleSystem *fire= unit->getFire();
if(fire != NULL) {
bool cellVisible = cellVisibleForFaction;
if(cellVisible == false) {
Vec2i sCoords = Map::toSurfCoords(unit->getPos());
SurfaceCell *sc = map.getSurfaceCell(sCoords);
if(sc != NULL) {
cellVisible = sc->isVisible(thisTeamIndex);
}
}
fire->setActive(cellVisible);
// fire particle visible
ParticleSystem *fire = unit->getFire();
if(fire != NULL) {
bool cellVisible = cellVisibleForFaction;
if(cellVisible == false) {
Vec2i sCoords = Map::toSurfCoords(unit->getPos());
SurfaceCell *sc = map.getSurfaceCell(sCoords);
if(sc != NULL) {
cellVisible = sc->isVisible(thisTeamIndex);
}
}
fire->setActive(cellVisible);
}
}
}
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
// compute fog of war render texture
if(fogOfWar == true &&
faction->getTeam() == thisTeamIndex &&
unit->isOperative() == true) {
//compute texture
if(fogOfWar == true) {
for(int i=0; i<getFactionCount(); ++i) {
Faction *faction= getFaction(i);
if(faction->getTeam() == thisTeamIndex) {
for(int j=0; j<faction->getUnitCount(); ++j){
const Unit *unit= faction->getUnit(j);
if(unit->isOperative()){
//int sightRange= unit->getType()->getSight();
if(enableFowAlphaCellsLookupItemCache == true) {
const FowAlphaCellsLookupItem &cellList = unit->getCachedFow();
for(int cellIndex = 0; cellIndex < cellList.surfPosList.size(); ++cellIndex) {
const Vec2i &surfPos = cellList.surfPosList[cellIndex];
const float &alpha = cellList.alphaList[cellIndex];
if(enableFowAlphaCellsLookupItemCache == true) {
const FowAlphaCellsLookupItem &cellList = unit->getCachedFow();
for(int k = 0; k < cellList.surfPosList.size(); ++k) {
const Vec2i &surfPos = cellList.surfPosList[k];
const float &alpha = cellList.alphaList[k];
minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
}
}
else {
const FowAlphaCellsLookupItem cellList = unit->getFogOfWarRadius(false);
for(int cellIndex = 0; cellIndex < cellList.surfPosList.size(); ++cellIndex) {
const Vec2i &surfPos = cellList.surfPosList[cellIndex];
const float &alpha = cellList.alphaList[cellIndex];
minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
}
}
else {
const FowAlphaCellsLookupItem cellList = unit->getFogOfWarRadius(false);
for(int k = 0; k < cellList.surfPosList.size(); ++k) {
const Vec2i &surfPos = cellList.surfPosList[k];
const float &alpha = cellList.alphaList[k];
minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
}
}
minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
}
}
}
}
}
if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
perfList.push_back(perfBuf);
}
if(this->game) this->game->addPerformanceCount("world compute cells",chronoGamePerformanceCounts.getMillis());
if(showPerfStats && chronoPerf.getMillis() >= 50) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
printf("%s",perfList[x].c_str());
}
}
// if(showPerfStats) {
// sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
// perfList.push_back(perfBuf);
// }
//
// if(showPerfStats && chronoPerf.getMillis() >= 50) {
// for(unsigned int x = 0; x < perfList.size(); ++x) {
// printf("%s",perfList[x].c_str());
// }
// }
}
GameSettings * World::getGameSettingsPtr() {
@ -2945,8 +2885,6 @@ void World::saveGame(XmlNode *rootNode) {
//
// bool unitParticlesEnabled;
worldNode->addAttribute("unitParticlesEnabled",intToStr(unitParticlesEnabled), mapTagReplacements);
// bool staggeredFactionUpdates;
worldNode->addAttribute("staggeredFactionUpdates",intToStr(staggeredFactionUpdates), mapTagReplacements);
// std::map<string,StaticSound *> staticSoundList;
// std::map<string,StrSound *> streamSoundList;
//

View File

@ -131,7 +131,6 @@ private:
bool perfTimerEnabled;
bool unitParticlesEnabled;
bool staggeredFactionUpdates;
std::map<string,StaticSound *> staticSoundList;
std::map<string,StrSound *> streamSoundList;
@ -297,9 +296,6 @@ public:
inline int getUpdateFps(int factionIndex) const {
int result = GameConstants::updateFps;
//if(factionIndex != -1 && staggeredFactionUpdates == true) {
// result = (GameConstants::updateFps / GameConstants::maxPlayers);
//}
return result;
}
bool canTickWorld() const;
@ -336,13 +332,11 @@ private:
void initMinimap();
void initUnits();
void initMap();
//void initExplorationState();
//misc
void tick();
bool canTickFaction(int factionIdx);
int tickFactionIndex();
void computeFow(int factionIdxToTick=-1);
void computeFow();
void updateAllTilesetObjects();
void updateAllFactionUnits();