added logging of threaded unit actions

This commit is contained in:
Mark Vejvoda 2013-05-21 05:43:57 +00:00
parent a7382619cb
commit 5cfc4d07a0
6 changed files with 339 additions and 7 deletions

View File

@ -159,6 +159,12 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
//printf("Unit Pathfind Unit [%d - %s] from = %s to = %s frameIndex = %d\n",unit->getId(),unit->getType()->getName().c_str(),unit->getPos().getString().c_str(),finalPos.getString().c_str(),frameIndex);
if(frameIndex >= 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[findPath] ");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
clearUnitPrecache(unit);
}
if(unit->getFaction()->canUnitsPathfind() == true) {
@ -171,6 +177,11 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
snprintf(szBuf,8096,"canUnitsPathfind() == false");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"canUnitsPathfind() == false");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return tsBlocked;
}
@ -214,6 +225,12 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
unit->setCurrentUnitTitle(szBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return tsArrived");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return tsArrived;
}
@ -235,6 +252,13 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return tsMoving");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return tsMoving;
}
}
@ -247,6 +271,13 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
advPath->pop();
unit->setTargetPos(pos);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return tsMoving");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return tsMoving;
}
}
@ -264,6 +295,11 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
snprintf(szBuf,8096,"path->isStuck() == true unit->getLastStuckPos() [%s] finalPos [%s] path->getBlockCount() [%d] tolerance: %d",unit->getLastStuckPos().getString().c_str(),finalPos.getString().c_str(),path->getBlockCount(),unit->isLastStuckFrameWithinCurrentFrameTolerance());
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"path->isStuck() == true unit->getLastStuckPos() [%s] finalPos [%s] path->getBlockCount() [%d] tolerance: %d",unit->getLastStuckPos().getString().c_str(),finalPos.getString().c_str(),path->getBlockCount(),unit->isLastStuckFrameWithinCurrentFrameTolerance());
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
//printf("$$$$ Unit STILL BLOCKED for [%d - %s]\n",unit->getId(),unit->getFullName().c_str());
return tsBlocked;
@ -286,6 +322,12 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
snprintf(szBuf,8096,"maxNodeCount: %d",maxNodeCount);
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"maxNodeCount: %d",maxNodeCount);
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
}
//int unitFactionIndex = unit->getFactionIndex();
@ -304,9 +346,20 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
snprintf(szBuf,8096,"calling aStar()");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"calling aStar()");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
ts = aStar(unit, finalPos, false, frameIndex, maxNodeCount,&searched_node_count);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"called aStar() ts: %d",ts);
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
//post actions
switch(ts) {
case tsBlocked:
@ -859,6 +912,12 @@ void PathFinder::astarJPS(std::map<Vec2i,Vec2i> cameFrom, Node *& node,
TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout,
int frameIndex, int maxNodeCount, uint32 *searched_node_count) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In aStar()");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@ -968,10 +1027,21 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return factions[unitFactionIndex].precachedTravelState[unit->getId()];
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"clearUnitPrecache(unit);");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
clearUnitPrecache(unit);
}
}
@ -988,6 +1058,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return factions[unitFactionIndex].precachedTravelState[unit->getId()];");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return factions[unitFactionIndex].precachedTravelState[unit->getId()];
}
@ -995,6 +1070,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"clearUnitPrecache(unit);");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
clearUnitPrecache(unit);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
@ -1100,6 +1181,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"return ts: %d",ts);
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return ts: %d",ts);
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return ts;
}
@ -1167,6 +1253,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"return ts: %d",ts);
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return ts: %d",ts);
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return ts;
}
@ -1348,6 +1439,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"calling aStar()");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"calling aStar()");
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return aStar(unit, targetPos, false, frameIndex, pathFindNodesAbsoluteMax);
}
@ -1359,6 +1455,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"nodeLimitReached: %d",nodeLimitReached);
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"nodeLimitReached: %d",nodeLimitReached);
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),nodeLimitReached,whileLoopCount,factions[unitFactionIndex].nodePoolCount);
@ -1541,6 +1643,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
snprintf(szBuf,8096,"return ts: %d",ts);
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"return ts: %d",ts);
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
return ts;
}

View File

@ -167,6 +167,8 @@ private:
std::map<int,std::map<Field, std::map<Vec2i,bool> > > mapSharedPathFinderCache;
std::vector<string> worldSynchThreadedLogList;
public:
Faction();
~Faction();
@ -180,6 +182,27 @@ public:
throw megaglest_runtime_error("class Faction is NOT safe to assign!");
}
inline void addWorldSynchThreadedLogList(const string &data) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
worldSynchThreadedLogList.push_back(data);
}
}
inline void clearWorldSynchThreadedLogList() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
worldSynchThreadedLogList.clear();
}
}
inline void dumpWorldSynchThreadedLogList() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
if(worldSynchThreadedLogList.empty() == false) {
for(unsigned int index = 0; index < worldSynchThreadedLogList.size(); ++index) {
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,worldSynchThreadedLogList[index].c_str());
}
worldSynchThreadedLogList.clear();
}
}
}
inline const bool * aproxCanMoveSoonCached(int size, Field field, const Vec2i &pos1, const Vec2i &pos2) const {
const bool *result = NULL;
// std::map<int,std::map<Field, std::map<Vec2i,bool> > >::const_iterator iterFind1 = mapSharedPathFinderCache.find(size);

View File

@ -3498,10 +3498,14 @@ void Unit::exploreCells() {
}
void Unit::logSynchData(string file,int line,string source) {
logSynchDataCommon(file,line,source,false);
}
void Unit::logSynchDataThreaded(string file,int line,string source) {
logSynchDataCommon(file,line,source,true);
}
void Unit::logSynchDataCommon(string file,int line,string source,bool threadedMode) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
char szBuf[8096]="";
snprintf(szBuf,8096,
"FrameCount [%d] Unit = %d [%s][%s] pos = %s, lastPos = %s, targetPos = %s, targetVec = %s, meetingPos = %s, progress [%f], progress2 [%d]\nUnit Path [%s]\n",
getFrameCount(),
@ -3529,6 +3533,23 @@ void Unit::logSynchData(string file,int line,string source) {
lastFile = file;
lastSource = source;
string logDataText = "";
char szBufDataText[8096]="";
snprintf(szBufDataText,8096,"----------------------------------- START [FRAME %d UNIT: %d - %s] ------------------------------------------------\n",getFrameCount(),this->id,this->getType()->getName().c_str());
logDataText = szBufDataText;
snprintf(szBufDataText,8096,"[%s::%d]\n",extractFileFromDirectoryPath(file).c_str(),line);
logDataText += szBufDataText;
if(source != "") {
snprintf(szBufDataText,8096,"%s ",source.c_str());
logDataText += szBufDataText;
}
snprintf(szBufDataText,8096,"%s\n",szBuf);
logDataText += szBufDataText;
snprintf(szBufDataText,8096,"------------------------------------ END [FRAME %d UNIT: %d - %s] ------------------------------------------------\n",getFrameCount(),this->id,this->getType()->getName().c_str());
logDataText += szBufDataText;
/*
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"----------------------------------- START [FRAME %d UNIT: %d - %s] ------------------------------------------------\n",getFrameCount(),this->id,this->getType()->getName().c_str());
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"[%s::%d]\n",extractFileFromDirectoryPath(file).c_str(),line);
if(source != "") {
@ -3536,6 +3557,13 @@ void Unit::logSynchData(string file,int line,string source) {
}
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"%s\n",szBuf);
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"------------------------------------ END [FRAME %d UNIT: %d - %s] ------------------------------------------------\n",getFrameCount(),this->id,this->getType()->getName().c_str());
*/
if(threadedMode == false) {
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"%s",logDataText.c_str());
}
else {
this->faction->addWorldSynchThreadedLogList(logDataText);
}
}
}
}

View File

@ -720,6 +720,8 @@ public:
//void addCurrentTargetPathTakenCell(const Vec2i &target,const Vec2i &cell);
void logSynchData(string file,int line,string source="");
void logSynchDataThreaded(string file,int line,string source="");
std::string toString() const;
bool needToUpdate();
@ -766,6 +768,8 @@ private:
void checkUnitLevel();
void morphAttackBoosts(Unit *unit);
void logSynchDataCommon(string file,int line,string source="",bool threadedMode=false);
};
}}// end namespace

View File

@ -356,6 +356,11 @@ void UnitUpdater::updateUnitCommand(Unit *unit, int frameIndex) {
void UnitUpdater::updateStop(Unit *unit, int frameIndex) {
// Nothing to do
if(frameIndex >= 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateStop]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
clearUnitPrecache(unit);
return;
}
@ -436,6 +441,11 @@ void UnitUpdater::updateMove(Unit *unit, int frameIndex) {
snprintf(szBuf,8096,"[updateMove] pos [%s] unit [%d - %s] cmd [%s]",pos.getString().c_str(),unit->getId(),unit->getFullName().c_str(),command->toString().c_str());
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateMove] pos [%s] unit [%d - %s] cmd [%s]",pos.getString().c_str(),unit->getId(),unit->getFullName().c_str(),command->toString().c_str());
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@ -468,6 +478,18 @@ void UnitUpdater::updateMove(Unit *unit, int frameIndex) {
break;
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateMove] tsValue [%d]",tsValue);
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateMove] tsValue [%d]",tsValue);
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
@ -481,6 +503,11 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) {
snprintf(szBuf,8096,"[updateAttack]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttack]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@ -561,10 +588,14 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttack] pos [%s] unit->getPos() [%s]",
pos.getString().c_str(),unit->getPos().getString().c_str());
snprintf(szBuf,8096,"[updateAttack] pos [%s] unit->getPos() [%s]",pos.getString().c_str(),unit->getPos().getString().c_str());
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttack] pos [%s] unit->getPos() [%s]",pos.getString().c_str(),unit->getPos().getString().c_str());
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@ -662,6 +693,12 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) {
}
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttack] tsValue [%d]",tsValue);
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
}
@ -675,6 +712,11 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) {
void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
// Nothing to do
if(frameIndex >= 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttackStopped]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
clearUnitPrecache(unit);
return;
}
@ -691,8 +733,13 @@ void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
const AttackStoppedCommandType *asct= static_cast<const AttackStoppedCommandType*>(command->getCommandType());
Unit *enemy=NULL;
if(unit->getCommandSize() > 1)
{
if(unit->getCommandSize() > 1) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttackStopped]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
unit->finishCommand(); // attackStopped is skipped if somthing else is queued after this.
return;
}
@ -703,13 +750,31 @@ void UnitUpdater::updateAttackStopped(Unit *unit, int frameIndex) {
if(result.first == true) {
unit->setCurrSkill(asct->getAttackSkillType());
unit->setTarget(result.second);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttackStopped]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
}
else if(attackableOnRange(unit, &enemy, asct->getAttackSkillType(),(frameIndex >= 0))) {
unit->setCurrSkill(asct->getAttackSkillType());
unit->setTarget(enemy);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttackStopped]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
}
else {
unit->setCurrSkill(asct->getStopSkillType());
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateAttackStopped]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@ -769,6 +834,18 @@ std::pair<bool,Unit *> UnitUpdater::unitBeingAttacked(const Unit *unit) {
// ==================== updateBuild ====================
void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@ -802,8 +879,26 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
unit->getPos().getString().c_str(),command->getPos().getString().c_str(),buildPos.getString().c_str());
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild] unit->getPos() [%s] command->getPos() [%s] buildPos [%s]",
unit->getPos().getString().c_str(),command->getPos().getString().c_str(),buildPos.getString().c_str());
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
tsValue = pathFinder->findPath(unit, buildPos, NULL, frameIndex);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild] tsValue: %d",tsValue);
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild] tsValue: %d",tsValue);
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
}
break;
default:
@ -938,11 +1033,24 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
//if unit is killed while building then u==NULL;
if(builtUnit != NULL && builtUnit != command->getUnit()) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is not the command's unit!\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild]");
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
unit->setCurrSkill(scStop);
}
else if(builtUnit == NULL || builtUnit->isBuilt()) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is NULL or ALREADY built\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild]");
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
unit->finishCommand();
unit->setCurrSkill(scStop);
@ -950,6 +1058,12 @@ void UnitUpdater::updateBuild(Unit *unit, int frameIndex) {
else if(builtUnit == NULL || builtUnit->repair()) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateBuild]");
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
const CommandType *ct = (command != NULL ? command->getCommandType() : NULL);
//building finished
unit->finishCommand();
@ -978,6 +1092,12 @@ void UnitUpdater::updateHarvestEmergencyReturn(Unit *unit, int frameIndex) {
return;
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvestEmergencyReturn]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
//printf("\n#1 updateHarvestEmergencyReturn\n");
Command *command= unit->getCurrCommand();
@ -1043,6 +1163,18 @@ void UnitUpdater::updateHarvestEmergencyReturn(Unit *unit, int frameIndex) {
}
void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
Chrono chrono;
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
@ -1104,6 +1236,12 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
//printf("%%----------- unit [%s - %d] CHANGING RESOURCE POS from [%s] to [%s]\n",unit->getFullName().c_str(),unit->getId(),command->getOriginalPos().getString().c_str(),clickPos.getString().c_str());
if(frameIndex < 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest] clickPos [%s]",clickPos.getString().c_str());
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
command->setPos(clickPos);
}
}
@ -1118,8 +1256,19 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
if (canHarvestDestPos == true ) {
if(frameIndex < 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest]");
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
unit->setLastHarvestResourceTarget(NULL);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest]");
unit->logSynchDataThreaded(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
canHarvestDestPos = (map->getSurfaceCell(Map::toSurfCoords(targetPos)) != NULL && map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource() != NULL && map->getSurfaceCell(Map::toSurfCoords(targetPos))->getResource()->getType() != NULL);
@ -1143,12 +1292,24 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
default:
throw megaglest_runtime_error("detected unsupported pathfinder type!");
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest] targetPos [%s]",targetPos.getString().c_str());
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
}
if(canHarvestDestPos == false) {
if(frameIndex < 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest] targetPos [%s]",targetPos.getString().c_str());
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
unit->setLastHarvestResourceTarget(&targetPos);
}
@ -1160,6 +1321,12 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
unit->getPos().getString().c_str(),command->getPos().getString().c_str());
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
else if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex >= 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"[updateHarvest] unit->getPos() [%s] command->getPos() [%s]",
unit->getPos().getString().c_str(),command->getPos().getString().c_str());
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
//if not continue walking
bool wasStuck = false;

View File

@ -67,7 +67,7 @@ World::World() {
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str());
//MaxExploredCellsLookupItemCache= config.getInt("MaxExploredCellsLookupItemCache",intToStr(MaxExploredCellsLookupItemCache).c_str());
frameCount= 0;
//nextUnitId= 0;
@ -519,6 +519,7 @@ void World::updateAllFactionUnits() {
Faction *faction = getFaction(i);
faction->clearUnitsPathfinding();
faction->clearAproxCanMoveSoonCached();
faction->clearWorldSynchThreadedLogList();
}
if(showPerfStats) {
@ -592,6 +593,8 @@ void World::updateAllFactionUnits() {
int totalUnitsProcessed = 0;
for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i);
faction->dumpWorldSynchThreadedLogList();
faction->clearUnitsPathfinding();
std::map<CommandClass,int> mapCommandCount;