- 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(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) { if(showPerfStats) {
@ -1981,7 +1981,7 @@ void Game::update() {
ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role); ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role);
addGamePerformanceCount("ReplaceDisconnectedNetworkPlayersWithAI",chronoGamePerformanceCounts.getMillis()); addPerformanceCount("ReplaceDisconnectedNetworkPlayersWithAI",chronoGamePerformanceCounts.getMillis());
setupPopupMenus(true); setupPopupMenus(true);
@ -2021,7 +2021,7 @@ void Game::update() {
processNetworkSynchChecksIfRequired(); processNetworkSynchChecksIfRequired();
addGamePerformanceCount("CalculateNetworkCRCSynchChecks",chronoGamePerformanceCounts.getMillis()); addPerformanceCount("CalculateNetworkCRCSynchChecks",chronoGamePerformanceCounts.getMillis());
const bool newThreadManager = Config::getInstance().getBool("EnableNewThreadManager","false"); const bool newThreadManager = Config::getInstance().getBool("EnableNewThreadManager","false");
if(newThreadManager == true) { if(newThreadManager == true) {
@ -2085,7 +2085,7 @@ void Game::update() {
} }
} }
addGamePerformanceCount("ProcessAIWorkerThreads",chronoGamePerformanceCounts.getMillis()); addPerformanceCount("ProcessAIWorkerThreads",chronoGamePerformanceCounts.getMillis());
} }
if(showPerfStats) { if(showPerfStats) {
@ -2150,7 +2150,7 @@ void Game::update() {
if(pendingQuitError == false) world.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) 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(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2191,7 +2191,7 @@ void Game::update() {
if(pendingQuitError == false) commander.signalNetworkUpdate(this); if(pendingQuitError == false) commander.signalNetworkUpdate(this);
addGamePerformanceCount("ProcessNetworkUpdate",chronoGamePerformanceCounts.getMillis()); addPerformanceCount("ProcessNetworkUpdate",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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(); 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) 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(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2235,7 +2235,7 @@ void Game::update() {
renderer.updateParticleManager(rsGame,avgRenderFps); 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) 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(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2303,7 +2303,7 @@ void Game::update() {
perfList.push_back(perfBuf); perfList.push_back(perfBuf);
} }
addGamePerformanceCount("ProcessMiscNetwork",chronoGamePerformanceCounts.getMillis()); addPerformanceCount("ProcessMiscNetwork",chronoGamePerformanceCounts.getMillis());
// START - Handle joining in progress games // START - Handle joining in progress games
if(role == nrServer) { 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; gamePerformanceCounts[key] = value + gamePerformanceCounts[key] / 2;
} }
@ -2762,12 +2762,18 @@ string Game::getGamePerformanceCounts(bool displayWarnings) const {
} }
bool displayWarningHeader = true; 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 = ""; string result = "";
for(std::map<string,int64>::const_iterator iterMap = gamePerformanceCounts.begin(); for(std::map<string,int64>::const_iterator iterMap = gamePerformanceCounts.begin();
iterMap != gamePerformanceCounts.end(); ++iterMap) { 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; continue;
} }

View File

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

View File

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

View File

@ -65,6 +65,9 @@ protected:
int lastFps; int lastFps;
public: public:
static const char *MAIN_PROGRAM_RENDER_KEY;
ProgramState(Program *program); ProgramState(Program *program);
virtual ~ProgramState(){}; virtual ~ProgramState(){};
@ -105,6 +108,7 @@ public:
virtual void consoleAddLine(string line) { }; virtual void consoleAddLine(string line) { };
virtual void reloadUI() {}; virtual void reloadUI() {};
virtual void addPerformanceCount(string key,int64 value) {};
protected: protected:
virtual void incrementFps(); 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__); 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 { FactionPersonalityType Faction::getPersonalityType() const {
if(overridePersonalityType != fpt_EndCount) { if(overridePersonalityType != fpt_EndCount) {

View File

@ -171,6 +171,10 @@ private:
std::map<int,string> crcWorldFrameDetails; std::map<int,string> crcWorldFrameDetails;
std::map<int,const Unit *> aliveUnitList;
std::map<int,const Unit *> mobileUnitList;
std::map<int,const Unit *> beingBuiltUnitList;
public: public:
Faction(); Faction();
~Faction(); ~Faction();
@ -184,6 +188,11 @@ public:
throw megaglest_runtime_error("class Faction is NOT safe to assign!"); 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) { inline void addWorldSynchThreadedLogList(const string &data) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
worldSynchThreadedLogList.push_back(data); worldSynchThreadedLogList.push_back(data);

View File

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

View File

@ -494,7 +494,6 @@ public:
void setCurrentPathFinderDesiredFinalPos(const Vec2i &finalPos) { currentPathFinderDesiredFinalPos = finalPos; } void setCurrentPathFinderDesiredFinalPos(const Vec2i &finalPos) { currentPathFinderDesiredFinalPos = finalPos; }
Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; } Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; }
//const std::pair<const SkillType *,std::vector<Unit *> > & getCurrentAttackBoostUnits() const { return currentAttackBoostUnits; }
const UnitAttackBoostEffectOriginator & getAttackBoostOriginatorEffect() const { return currentAttackBoostOriginatorEffect; } const UnitAttackBoostEffectOriginator & getAttackBoostOriginatorEffect() const { return currentAttackBoostOriginatorEffect; }
bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const; bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const;
@ -540,7 +539,9 @@ public:
inline Vec2i getMeetingPos() const {return meetingPos;} inline Vec2i getMeetingPos() const {return meetingPos;}
inline Faction *getFaction() const {return faction;} inline Faction *getFaction() const {return faction;}
inline const ResourceType *getLoadType() const {return loadType;} inline const ResourceType *getLoadType() const {return loadType;}
inline const UnitType *getType() const {return type;} inline const UnitType *getType() const {return type;}
void setType(const UnitType *newType);
inline const UnitType *getPreMorphType() const {return preMorph_type;} inline const UnitType *getPreMorphType() const {return preMorph_type;}
inline const SkillType *getCurrSkill() const {return currSkill;} inline const SkillType *getCurrSkill() const {return currSkill;}
@ -813,6 +814,8 @@ private:
void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false); void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false);
void updateAttackBoostProgress(const Game* game); void updateAttackBoostProgress(const Game* game);
void setAlive(bool value);
}; };
}}// end namespace }}// 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__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Config &config= Config::getInstance(); Config &config= Config::getInstance();
//staggeredFactionUpdates = config.getBool("StaggeredFactionUpdates","false");
staggeredFactionUpdates = false;
unitParticlesEnabled=config.getBool("UnitParticles","true"); unitParticlesEnabled=config.getBool("UnitParticles","true");
animatedTilesetObjectPosListLoaded = false; animatedTilesetObjectPosListLoaded = false;
@ -762,42 +760,33 @@ void World::updateAllFactionUnits() {
void World::underTakeDeadFactionUnits() { 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__); 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(); 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__); 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 //undertake the dead
for(int i = 0; i< factionCount; ++i) { for(int i = 0; i< factionCount; ++i) {
if(factionIdxToTick == -1 || factionIdxToTick == i) { Faction *faction = getFaction(i);
Faction *faction = getFaction(i); int unitCount = faction->getUnitCount();
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);
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);
for(int j= unitCount - 1; j >= 0; j--) { for(int j= unitCount - 1; j >= 0; j--) {
Unit *unit= faction->getUnit(j); Unit *unit= faction->getUnit(j);
if(unit == NULL) { if(unit == NULL) {
throw megaglest_runtime_error("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->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__); 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(); updateAllTilesetObjects();
if(this->game) this->game->addGamePerformanceCount("updateAllTilesetObjects",chronoGamePerformanceCounts.getMillis()); if(this->game) this->game->addPerformanceCount("updateAllTilesetObjects",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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(); updateAllFactionUnits();
if(this->game) this->game->addGamePerformanceCount("updateAllFactionUnits",chronoGamePerformanceCounts.getMillis()); if(this->game) this->game->addPerformanceCount("updateAllFactionUnits",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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(); underTakeDeadFactionUnits();
if(this->game) this->game->addGamePerformanceCount("underTakeDeadFactionUnits",chronoGamePerformanceCounts.getMillis()); if(this->game) this->game->addPerformanceCount("underTakeDeadFactionUnits",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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(); updateAllFactionConsumableCosts();
if(this->game) this->game->addGamePerformanceCount("updateAllFactionConsumableCosts",chronoGamePerformanceCounts.getMillis()); if(this->game) this->game->addPerformanceCount("updateAllFactionConsumableCosts",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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; float fogFactor= static_cast<float>(frameCount % GameConstants::updateFps) / GameConstants::updateFps;
minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f)); 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) { if(showPerfStats) {
@ -939,7 +928,7 @@ void World::update() {
tick(); tick();
if(this->game) this->game->addGamePerformanceCount("tick",chronoGamePerformanceCounts.getMillis()); if(this->game) this->game->addPerformanceCount("world->tick",chronoGamePerformanceCounts.getMillis());
} }
if(showPerfStats) { if(showPerfStats) {
@ -959,10 +948,6 @@ void World::update() {
bool World::canTickWorld() const { bool World::canTickWorld() const {
//tick //tick
bool needToTick = (frameCount % GameConstants::updateFps == 0); bool needToTick = (frameCount % GameConstants::updateFps == 0);
if(staggeredFactionUpdates == true) {
needToTick = (frameCount % (GameConstants::updateFps / GameConstants::maxPlayers) == 0);
}
return needToTick; return needToTick;
} }
@ -979,20 +964,6 @@ bool World::canTickFaction(int factionIdx) {
return result; 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() { void World::tick() {
bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false"); bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf; Chrono chronoPerf;
@ -1000,30 +971,29 @@ void World::tick() {
std::vector<string> perfList; std::vector<string> perfList;
if(showPerfStats) chronoPerf.start(); if(showPerfStats) chronoPerf.start();
int factionIdxToTick = -1;
if(staggeredFactionUpdates == true) {
factionIdxToTick = tickFactionIndex();
if(factionIdxToTick < 0) {
return;
}
}
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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); 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) { 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); 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); perfList.push_back(perfBuf);
} }
if(factionIdxToTick == -1 || factionIdxToTick == 0) { if(fogOfWarSmoothing == false) {
if(fogOfWarSmoothing == false) { if(this->game) chronoGamePerformanceCounts.start();
minimap.updateFowTex(1.f);
} minimap.updateFowTex(1.f);
if(this->game) this->game->addPerformanceCount("minimap.updateFowTex",chronoGamePerformanceCounts.getMillis());
} }
if(showPerfStats) { if(showPerfStats) {
@ -1032,22 +1002,23 @@ void World::tick() {
} }
//increase hp //increase hp
if(this->game) chronoGamePerformanceCounts.start();
int factionCount = getFactionCount(); int factionCount = getFactionCount();
for(int i = 0; i < factionCount; ++i) { for(int factionIndex = 0; factionIndex < factionCount; ++factionIndex) {
if(factionIdxToTick == -1 || i == factionIdxToTick) { Faction *faction = getFaction(factionIndex);
Faction *faction = getFaction(i); int unitCount = faction->getUnitCount();
int unitCount = faction->getUnitCount();
for(int j = 0; j < unitCount; ++j) { for(int unitIndex = 0; unitIndex < unitCount; ++unitIndex) {
Unit *unit = faction->getUnit(j); Unit *unit = faction->getUnit(unitIndex);
if(unit == NULL) { if(unit == NULL) {
throw megaglest_runtime_error("unit == NULL"); throw megaglest_runtime_error("unit == NULL");
}
unit->tick();
} }
unit->tick();
} }
} }
if(this->game) this->game->addPerformanceCount("world unit->tick()",chronoGamePerformanceCounts.getMillis());
if(showPerfStats) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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 //compute resources balance
if(this->game) chronoGamePerformanceCounts.start();
std::map<const UnitType *, std::map<const ResourceType *, const Resource *> > resourceCostCache;
factionCount = getFactionCount(); factionCount = getFactionCount();
for(int k = 0; k < factionCount; ++k) { for(int factionIndex = 0; factionIndex < factionCount; ++factionIndex) {
if(factionIdxToTick == -1 || k == factionIdxToTick) { Faction *faction = getFaction(factionIndex);
Faction *faction= getFaction(k);
//for each resource //for each resource
for(int i = 0; i < techTree->getResourceTypeCount(); ++i) { for(int resourceTypeIndex = 0;
const ResourceType *rt= techTree->getResourceType(i); resourceTypeIndex < techTree->getResourceTypeCount(); ++resourceTypeIndex) {
const ResourceType *rt= techTree->getResourceType(resourceTypeIndex);
//if consumable //if consumable
if(rt != NULL && rt->getClass()==rcConsumable) { if(rt != NULL && rt->getClass() == rcConsumable) {
int balance= 0; int balance= 0;
for(int j = 0; j < faction->getUnitCount(); ++j) { for(int unitIndex = 0;
unitIndex < faction->getUnitCount(); ++unitIndex) {
//if unit operative and has this cost //if unit operative and has this cost
const Unit *u= faction->getUnit(j); const Unit *unit = faction->getUnit(unitIndex);
if(u != NULL && u->isOperative()) { if(unit != NULL && unit->isOperative()) {
const Resource *r= u->getType()->getCost(rt); const UnitType *ut = unit->getType();
if(r != NULL) { const Resource *resource = NULL;
balance -= u->getType()->getCost(rt)->getAmount(); 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) { if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); 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; // bool unitParticlesEnabled;
unitParticlesEnabled = loadWorldNode->getAttribute("unitParticlesEnabled")->getIntValue() != 0; unitParticlesEnabled = loadWorldNode->getAttribute("unitParticlesEnabled")->getIntValue() != 0;
// bool staggeredFactionUpdates;
staggeredFactionUpdates = loadWorldNode->getAttribute("staggeredFactionUpdates")->getIntValue() != 0;
// std::map<string,StaticSound *> staticSoundList; // std::map<string,StaticSound *> staticSoundList;
// std::map<string,StrSound *> streamSoundList; // 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 World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) const {
bool ret = false; bool ret = false;
if(excludeFogOfWarCheck == false && fogOfWarSkillTypeValue == 0 && fogOfWarOverride == true) { if(excludeFogOfWarCheck == false &&
fogOfWarSkillTypeValue == 0 && fogOfWarOverride == true) {
ret = true; ret = true;
} }
else if(factionIndex == thisFactionIndex && game != NULL) { else if(factionIndex == thisFactionIndex && game != NULL) {
@ -2439,13 +2423,18 @@ bool World::showWorldForPlayer(int factionIndex, bool excludeFogOfWarCheck) cons
if(getStats()->getVictory(factionIndex) == false) { if(getStats()->getVictory(factionIndex) == false) {
// If the player has at least 1 Unit alive that is mobile (can move) // If the player has at least 1 Unit alive that is mobile (can move)
// then we cannot turn off fog of war // then we cannot turn off fog of war
for(int i = 0; i < getFaction(factionIndex)->getUnitCount(); ++i) {
Unit *unit = getFaction(factionIndex)->getUnit(i); const Faction *faction = getFaction(factionIndex);
if(unit != NULL && unit->isAlive() && unit->getType()->isMobile() == true) { // for(int i = 0; i < faction->getUnitCount(); ++i) {
ret = false; // Unit *unit = getFaction(factionIndex)->getUnit(i);
break; // 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 //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()); 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"); //bool showPerfStats = Config::getInstance().getBool("ShowPerfStats","false");
Chrono chronoPerf; //Chrono chronoPerf;
char perfBuf[8096]=""; //char perfBuf[8096]="";
std::vector<string> perfList; //std::vector<string> perfList;
if(showPerfStats) chronoPerf.start(); //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(); minimap.resetFowTex();
if(showPerfStats) { if(this->game) this->game->addPerformanceCount("world minimap.resetFowTex",chronoGamePerformanceCounts.getMillis());
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);
// }
// reset cells
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());
//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 if(this->game) chronoGamePerformanceCounts.start();
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 int resetFowAlphaFactionCount = 0;
float alpha=maxAlpha; for(int indexFaction = 0;
minimap.incFowTextureAlphaSurface(surfPos, alpha); indexFaction < GameConstants::maxPlayers + GameConstants::specialFactions;
} ++indexFaction) {
//else { if(fogOfWar || indexFaction != thisTeamIndex) {
// map.getSurfaceCell(i, j)->setVisible(k, false); 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); for(int indexSurfaceW = 0; indexSurfaceW < map.getSurfaceW(); ++indexSurfaceW) {
Vec2i surfPos= pos; for(int indexSurfaceH = 0; indexSurfaceH < map.getSurfaceH(); ++indexSurfaceH) {
map.getSurfaceCell(indexSurfaceW, indexSurfaceH)->setVisible(indexFaction, false);
//compute max alpha if(showWorldForFaction == true && resetFowAlphaFactionCount <= 1) {
float maxAlpha= 0.0f; const Vec2i surfPos(indexSurfaceW,indexSurfaceH);
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 //compute max alpha
float alpha=maxAlpha; float maxAlpha= 0.0f;
minimap.incFowTextureAlphaSurface(surfPos, alpha); 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(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(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s] Line: %d in frame: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,getFrameCount());
if(showPerfStats) { // if(showPerfStats) {
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); // 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); // perfList.push_back(perfBuf);
} // }
//compute cells //compute cells
for(int i=0; i<getFactionCount(); ++i) { if(this->game) chronoGamePerformanceCounts.start();
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) {
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
Unit *unit= getFaction(i)->getUnit(j);
//exploration for(int factionIndex = 0; factionIndex < getFactionCount(); ++factionIndex) {
unit->exploreCells(); 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) { // exploration
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); unit->exploreCells();
perfList.push_back(perfBuf);
}
//fire // fire particle visible
for(int i=0; i<getFactionCount(); ++i) { ParticleSystem *fire = unit->getFire();
if(factionIdxToTick == -1 || factionIdxToTick == this->thisFactionIndex) { if(fire != NULL) {
bool cellVisibleForFaction = showWorldForPlayer(thisFactionIndex); bool cellVisible = cellVisibleForFaction;
for(int j=0; j<getFaction(i)->getUnitCount(); ++j){ if(cellVisible == false) {
Unit *unit= getFaction(i)->getUnit(j); Vec2i sCoords = Map::toSurfCoords(unit->getPos());
SurfaceCell *sc = map.getSurfaceCell(sCoords);
//fire if(sc != NULL) {
ParticleSystem *fire= unit->getFire(); cellVisible = sc->isVisible(thisTeamIndex);
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->setActive(cellVisible);
} }
}
}
if(showPerfStats) { // compute fog of war render texture
sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis()); if(fogOfWar == true &&
perfList.push_back(perfBuf); faction->getTeam() == thisTeamIndex &&
} unit->isOperative() == true) {
//compute texture if(enableFowAlphaCellsLookupItemCache == true) {
if(fogOfWar == true) { const FowAlphaCellsLookupItem &cellList = unit->getCachedFow();
for(int i=0; i<getFactionCount(); ++i) { for(int cellIndex = 0; cellIndex < cellList.surfPosList.size(); ++cellIndex) {
Faction *faction= getFaction(i); const Vec2i &surfPos = cellList.surfPosList[cellIndex];
if(faction->getTeam() == thisTeamIndex) { const float &alpha = cellList.alphaList[cellIndex];
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) { minimap.incFowTextureAlphaSurface(surfPos, alpha, true);
const FowAlphaCellsLookupItem &cellList = unit->getCachedFow(); }
for(int k = 0; k < cellList.surfPosList.size(); ++k) { }
const Vec2i &surfPos = cellList.surfPosList[k]; else {
const float &alpha = cellList.alphaList[k]; 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); 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);
}
}
} }
} }
} }
} }
} }
if(showPerfStats) { if(this->game) this->game->addPerformanceCount("world compute cells",chronoGamePerformanceCounts.getMillis());
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) { // if(showPerfStats) {
for(unsigned int x = 0; x < perfList.size(); ++x) { // sprintf(perfBuf,"In [%s::%s] Line: %d took msecs: " MG_I64_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chronoPerf.getMillis());
printf("%s",perfList[x].c_str()); // 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() { GameSettings * World::getGameSettingsPtr() {
@ -2945,8 +2885,6 @@ void World::saveGame(XmlNode *rootNode) {
// //
// bool unitParticlesEnabled; // bool unitParticlesEnabled;
worldNode->addAttribute("unitParticlesEnabled",intToStr(unitParticlesEnabled), mapTagReplacements); worldNode->addAttribute("unitParticlesEnabled",intToStr(unitParticlesEnabled), mapTagReplacements);
// bool staggeredFactionUpdates;
worldNode->addAttribute("staggeredFactionUpdates",intToStr(staggeredFactionUpdates), mapTagReplacements);
// std::map<string,StaticSound *> staticSoundList; // std::map<string,StaticSound *> staticSoundList;
// std::map<string,StrSound *> streamSoundList; // std::map<string,StrSound *> streamSoundList;
// //

View File

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