- removed debug code

This commit is contained in:
Mark Vejvoda 2013-11-14 13:17:58 +00:00
parent d48d63b1fa
commit 3671bd0617
2 changed files with 38 additions and 445 deletions

View File

@ -129,7 +129,6 @@ void PathFinder::removeUnitPrecache(Unit *unit) {
TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStuck, int frameIndex) {
TravelState ts = tsImpossible;
string codeLocation = "1";
try {
int factionIndex = unit->getFactionIndex();
@ -143,18 +142,14 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
unit->setCurrentPathFinderDesiredFinalPos(finalPos);
codeLocation = "2";
if(frameIndex >= 0) {
codeLocation = "2";
clearUnitPrecache(unit);
}
if(unit->getFaction()->canUnitsPathfind() == true) {
codeLocation = "3";
unit->getFaction()->addUnitToPathfindingList(unit->getId());
}
else {
codeLocation = "4";
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"canUnitsPathfind() == false");
@ -173,9 +168,7 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
//route cache
if(finalPos == unit->getPos()) {
codeLocation = "5";
if(frameIndex < 0) {
codeLocation = "6";
//if arrived
unit->setCurrSkill(scStop);
@ -200,20 +193,15 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
return tsArrived;
}
codeLocation = "7";
UnitPathInterface *path= unit->getPath();
if(path->isEmpty() == false) {
codeLocation = "8";
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
codeLocation = "9";
//route cache
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
Vec2i pos= basicPath->pop(frameIndex < 0);
if(map->canMove(unit, unit->getPos(), pos)) {
codeLocation = "10";
if(frameIndex < 0) {
codeLocation = "11";
unit->setTargetPos(pos);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
@ -228,12 +216,10 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
}
else if(dynamic_cast<UnitPath *>(path) != NULL) {
codeLocation = "12";
UnitPath *advPath = dynamic_cast<UnitPath *>(path);
//route cache
Vec2i pos= advPath->peek();
if(map->canMove(unit, unit->getPos(), pos)) {
codeLocation = "13";
if(frameIndex < 0) {
advPath->pop();
unit->setTargetPos(pos);
@ -247,11 +233,9 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
}
codeLocation = "14";
if(path->isStuck() == true &&
(unit->getLastStuckPos() == finalPos || path->getBlockCount() > 500) &&
unit->isLastStuckFrameWithinCurrentFrameTolerance(frameIndex >= 0) == true) {
codeLocation = "15";
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]",unit->getLastStuckPos().getString().c_str(),finalPos.getString().c_str(),path->getBlockCount());
@ -262,10 +246,8 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
//route cache miss
codeLocation = "16";
int maxNodeCount=-1;
if(unit->getUsePathfinderExtendedMaxNodes() == true) {
codeLocation = "17";
maxNodeCount= PathFinder::pathFindNodesAbsoluteMax;
@ -276,7 +258,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
}
codeLocation = "18";
bool minorDebugPathfinderPerformance = false;
Chrono chrono;
if(minorDebugPathfinderPerformance) chrono.start();
@ -291,20 +272,16 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
}
codeLocation = "19";
ts = aStar(unit, finalPos, false, frameIndex, maxNodeCount,&searched_node_count);
codeLocation = "20";
//post actions
switch(ts) {
case tsBlocked:
case tsArrived:
codeLocation = "21";
// The unit is stuck (not only blocked but unable to go anywhere for a while)
// We will try to bail out of the immediate area
if( ts == tsBlocked && unit->getInBailOutAttempt() == false &&
path->isStuck() == true) {
codeLocation = "22";
if(minorDebugPathfinder) printf("Pathfind Unit [%d - %s] START BAILOUT ATTEMPT frameIndex = %d\n",unit->getId(),unit->getType()->getName(false).c_str(),frameIndex);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
@ -319,7 +296,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
unit->setInBailOutAttempt(true);
codeLocation = "23";
bool unitImmediatelyBlocked = false;
// First check if unit currently blocked all around them, if so don't try to pathfind
@ -327,7 +303,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
int failureCount = 0;
int cellCount = 0;
codeLocation = "24";
for(int i = -1; i <= 1; ++i) {
for(int j = -1; j <= 1; ++j) {
Vec2i pos = unitPos + Vec2i(i, j);
@ -342,7 +317,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
unitImmediatelyBlocked = (failureCount == cellCount);
if(unitImmediatelyBlocked == false) {
codeLocation = "25";
int factionIndex = unit->getFactionIndex();
FactionState &faction = factions.getFactionState(factionIndex);
@ -353,7 +327,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
if(tryRadius > 0) {
for(int bailoutX = -PathFinder::pathFindBailoutRadius; bailoutX <= PathFinder::pathFindBailoutRadius && ts == tsBlocked; ++bailoutX) {
for(int bailoutY = -PathFinder::pathFindBailoutRadius; bailoutY <= PathFinder::pathFindBailoutRadius && ts == tsBlocked; ++bailoutY) {
codeLocation = "26";
const Vec2i newFinalPos = finalPos + Vec2i(bailoutX,bailoutY);
bool canUnitMove = map->canMove(unit, unit->getPos(), newFinalPos);
@ -365,7 +338,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
if(canUnitMove) {
codeLocation = "27";
int maxBailoutNodeCount = (PathFinder::pathFindBailoutRadius * 2);
@ -376,16 +348,13 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
ts= aStar(unit, newFinalPos, true, frameIndex, maxBailoutNodeCount,&searched_node_count);
codeLocation = "28";
}
}
}
}
else {
codeLocation = "29";
for(int bailoutX = PathFinder::pathFindBailoutRadius; bailoutX >= -PathFinder::pathFindBailoutRadius && ts == tsBlocked; --bailoutX) {
for(int bailoutY = PathFinder::pathFindBailoutRadius; bailoutY >= -PathFinder::pathFindBailoutRadius && ts == tsBlocked; --bailoutY) {
codeLocation = "30";
const Vec2i newFinalPos = finalPos + Vec2i(bailoutX,bailoutY);
bool canUnitMove = map->canMove(unit, unit->getPos(), newFinalPos);
@ -397,7 +366,6 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
if(canUnitMove) {
codeLocation = "31";
int maxBailoutNodeCount = (PathFinder::pathFindBailoutRadius * 2);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
@ -407,40 +375,33 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
ts= aStar(unit, newFinalPos, true, frameIndex, maxBailoutNodeCount,&searched_node_count);
codeLocation = "32";
}
}
}
}
}
codeLocation = "33";
unit->setInBailOutAttempt(false);
if(ts == tsBlocked) {
codeLocation = "34";
unit->setLastStuckFrameToCurrentFrame();
unit->setLastStuckPos(finalPos);
}
}
if(ts == tsArrived || ts == tsBlocked) {
if(frameIndex < 0) {
codeLocation = "35";
unit->setCurrSkill(scStop);
}
}
break;
case tsMoving:
{
codeLocation = "36";
if(dynamic_cast<UnitPathBasic *>(path) != NULL) {
UnitPathBasic *basicPath = dynamic_cast<UnitPathBasic *>(path);
Vec2i pos;
if(frameIndex < 0) {
codeLocation = "37";
pos = basicPath->pop(frameIndex < 0);
}
else {
codeLocation = "38";
if(faction.precachedPath[unit->getId()].size() <= 0) {
throw megaglest_runtime_error("factions[unit->getFactionIndex()].precachedPath[unit->getId()].size() <= 0!");
@ -448,20 +409,15 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
pos = faction.precachedPath[unit->getId()][0];
codeLocation = "39";
}
codeLocation = "40";
if(map->canMove(unit, unit->getPos(), pos)) {
if(frameIndex < 0) {
codeLocation = "41";
unit->setTargetPos(pos);
}
}
else {
codeLocation = "42";
if(frameIndex < 0) {
codeLocation = "43";
unit->setCurrSkill(scStop);
}
@ -477,19 +433,16 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
}
else if(dynamic_cast<UnitPath *>(path) != NULL) {
codeLocation = "44";
UnitPath *advPath = dynamic_cast<UnitPath *>(path);
Vec2i pos= advPath->peek();
if(map->canMove(unit, unit->getPos(), pos)) {
if(frameIndex < 0) {
codeLocation = "45";
advPath->pop();
unit->setTargetPos(pos);
}
}
else {
if(frameIndex < 0) {
codeLocation = "46";
unit->setCurrSkill(scStop);
}
@ -505,21 +458,20 @@ TravelState PathFinder::findPath(Unit *unit, const Vec2i &finalPos, bool *wasStu
}
break;
}
codeLocation = "47";
if(minorDebugPathfinderPerformance && chrono.getMillis() >= 1) printf("Unit [%d - %s] astar took [%lld] msecs, ts = %d searched_node_count = %d.\n",unit->getId(),unit->getType()->getName(false).c_str(),(long long int)chrono.getMillis(),ts,searched_node_count);
}
catch(const exception &ex) {
//setRunningStatus(false);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Loc [%s] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str(),ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw megaglest_runtime_error(ex.what());
}
catch(...) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error Loc [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str());
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw megaglest_runtime_error(szBuf);
}
@ -534,7 +486,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
int frameIndex, int maxNodeCount, uint32 *searched_node_count) {
TravelState ts = tsImpossible;
string codeLocation = "1";
try {
int unitFactionIndex = unit->getFactionIndex();
@ -554,10 +505,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
throw megaglest_runtime_error("map == NULL");
}
codeLocation = "2";
if(maxNodeCount < 0) {
codeLocation = "3";
int factionIndex = unit->getFactionIndex();
FactionState &faction = factions.getFactionState(factionIndex);
@ -569,7 +518,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
maxNodeCount = 200;
}
codeLocation = "4";
UnitPathInterface *path= unit->getPath();
faction.nodePoolCount= 0;
@ -577,14 +525,11 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
faction.openPosList.clear();
faction.closedNodesList.clear();
codeLocation = "5";
// check the pre-cache to see if we can re-use a cached path
if(frameIndex < 0) {
codeLocation = "6";
bool foundPrecacheTravelState = (faction.precachedTravelState.find(unit->getId()) != faction.precachedTravelState.end());
if(foundPrecacheTravelState == true) {
codeLocation = "7";
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
// char szBuf[8096]="";
@ -594,7 +539,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
bool foundPrecacheTravelStateIsMoving = (faction.precachedTravelState[unit->getId()] == tsMoving);
if(foundPrecacheTravelStateIsMoving == true) {
codeLocation = "8";
bool canMoveToCells = true;
Vec2i lastPos = unit->getPos();
@ -602,7 +546,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
int unitPrecachePathSize = (int)faction.precachedPath[unit->getId()].size();
for(int i=0; i < unitPrecachePathSize; i++) {
codeLocation = "9";
Vec2i nodePos = faction.precachedPath[unit->getId()][i];
@ -613,7 +556,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(i < unit->getPathFindRefreshCellCount() ||
(unitPrecachePathSize >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(faction))) {
codeLocation = "10";
if(canUnitMoveSoon(unit, lastPos, nodePos) == false) {
canMoveToCells = false;
@ -626,16 +568,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
}
codeLocation = "11";
if(canMoveToCells == true) {
codeLocation = "12";
path->clear();
UnitPathBasic *basicPathFinder = dynamic_cast<UnitPathBasic *>(path);
int unitPrecachePathSize = (int)faction.precachedPath[unit->getId()].size();
for(int i=0; i < unitPrecachePathSize; i++) {
codeLocation = "13";
Vec2i nodePos = faction.precachedPath[unit->getId()][i];
@ -647,11 +586,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(i < unit->getPathFindRefreshCellCount() ||
(unitPrecachePathSize >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(faction))) {
codeLocation = "14";
path->add(nodePos);
}
}
codeLocation = "16";
unit->setUsePathfinderExtendedMaxNodes(false);
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
@ -660,21 +597,17 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
// unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
// }
codeLocation = "17";
return faction.precachedTravelState[unit->getId()];
}
else {
codeLocation = "18";
clearUnitPrecache(unit);
}
}
else {
codeLocation = "19";
bool foundPrecacheTravelStateIsBlocked = (faction.precachedTravelState[unit->getId()] == tsBlocked);
if(foundPrecacheTravelStateIsBlocked == true) {
codeLocation = "20";
path->incBlockCount();
unit->setUsePathfinderExtendedMaxNodes(false);
@ -684,14 +617,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
// unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
// }
codeLocation = "21";
return faction.precachedTravelState[unit->getId()];
}
}
}
}
else {
codeLocation = "22";
clearUnitPrecache(unit);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
@ -701,11 +632,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
}
codeLocation = "23";
const Vec2i unitPos = unit->getPos();
const Vec2i finalPos= computeNearestFreePos(unit, targetPos);
codeLocation = "24";
float dist= unitPos.dist(finalPos);
faction.useMaxNodeCount = PathFinder::pathFindNodesMax;
@ -713,7 +642,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
//path find algorithm
codeLocation = "26";
//a) push starting pos into openNodes
Node *firstNode= newNode(faction,maxNodeCount);
@ -732,7 +660,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
faction.openNodesList[firstNode->heuristic].push_back(firstNode);
faction.openPosList[firstNode->pos] = true;
codeLocation = "27";
//b) loop
bool pathFound = true;
bool nodeLimitReached = false;
@ -742,7 +669,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
// First check if unit currently blocked all around them, if so don't try to pathfind
if(inBailout == false && unitPos != finalPos) {
codeLocation = "28";
int failureCount = 0;
int cellCount = 0;
@ -769,9 +695,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unit->getId(),unit->getFullName(false).c_str(), unitPos.getString().c_str(), finalPos.getString().c_str(), dist,(long long int)chrono.getMillis(),nodeLimitReached,failureCount);
codeLocation = "29";
if(nodeLimitReached == false) {
codeLocation = "30";
// First check if final destination blocked
failureCount = 0;
cellCount = 0;
@ -809,7 +733,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
//
codeLocation = "31";
// START
std::map<std::pair<Vec2i,Vec2i> ,bool> canAddNode;
std::map<Vec2i,bool> closedNodes;
@ -819,7 +742,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
// Do the a-star base pathfind work if required
int whileLoopCount = 0;
if(nodeLimitReached == false) {
codeLocation = "32";
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
@ -832,22 +754,18 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
pathFound, node, finalPos,
closedNodes, cameFrom, canAddNode, unit, maxNodeCount,frameIndex);
codeLocation = "33";
if(searched_node_count != NULL) {
*searched_node_count = whileLoopCount;
}
// Now see if the unit is eligible for pathfind max nodes boost?
if(nodeLimitReached == true) {
codeLocation = "34";
unit->incrementPathfindFailedConsecutiveFrameCount();
}
else {
codeLocation = "35";
unit->resetPathfindFailedConsecutiveFrameCount();
}
codeLocation = "36";
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"Calling doAStarPathSearch nodeLimitReached: %d whileLoopCount: %d unitFactionIndex: %d pathFound: %d finalPos [%s] maxNodeCount: %d pathFindNodesAbsoluteMax: %d frameIndex: %d",nodeLimitReached, whileLoopCount, unitFactionIndex,
@ -856,11 +774,8 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
if(nodeLimitReached == true && maxNodeCount != pathFindNodesAbsoluteMax) {
codeLocation = "37";
if(unit->isLastPathfindFailedFrameWithinCurrentFrameTolerance() == true) {
codeLocation = "38";
if(frameIndex < 0) {
codeLocation = "39";
unit->setLastPathfindFailedFrameToCurrentFrame();
unit->setLastPathfindFailedPos(finalPos);
}
@ -883,19 +798,15 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
}
codeLocation = "40";
Node *lastNode= node;
//if consumed all nodes find best node (to avoid strange behaviour)
if(nodeLimitReached == true) {
codeLocation = "41";
if(faction.closedNodesList.empty() == false) {
codeLocation = "42";
float bestHeuristic = faction.closedNodesList.begin()->first;
if(bestHeuristic < lastNode->heuristic) {
codeLocation = "43";
lastNode= faction.closedNodesList.begin()->second[0];
}
}
@ -903,11 +814,9 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
codeLocation = "44";
//check results of path finding
ts = tsImpossible;
if(pathFound == false || lastNode == firstNode) {
codeLocation = "45";
if(minorDebugPathfinder) printf("Legacy Pathfind Unit [%d - %s] NOT FOUND PATH count = %d frameIndex = %d\n",unit->getId(),unit->getType()->getName().c_str(),whileLoopCount,frameIndex);
//blocked
@ -926,20 +835,17 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
if(frameIndex < 0) {
codeLocation = "46";
unit->setUsePathfinderExtendedMaxNodes(false);
}
ts= tsBlocked;
if(frameIndex < 0) {
codeLocation = "47";
path->incBlockCount();
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
}
else {
codeLocation = "48";
if(minorDebugPathfinder) printf("Legacy Pathfind Unit [%d - %s] FOUND PATH count = %d frameIndex = %d\n",unit->getId(),unit->getType()->getName().c_str(),whileLoopCount,frameIndex);
//on the way
ts= tsMoving;
@ -951,34 +857,27 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
currNode= currNode->prev;
}
codeLocation = "49";
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(frameIndex < 0) {
codeLocation = "50";
if(maxNodeCount == pathFindNodesAbsoluteMax) {
codeLocation = "51";
unit->setUsePathfinderExtendedMaxNodes(true);
}
else {
codeLocation = "52";
unit->setUsePathfinderExtendedMaxNodes(false);
}
}
//store path
if(frameIndex < 0) {
codeLocation = "53";
path->clear();
}
codeLocation = "54";
UnitPathBasic *basicPathFinder = dynamic_cast<UnitPathBasic *>(path);
currNode= firstNode;
for(int i=0; currNode->next != NULL; currNode= currNode->next, i++) {
codeLocation = "55";
Vec2i nodePos = currNode->next->pos;
if(map->isInside(nodePos) == false || map->isInsideSurface(map->toSurfCoords(nodePos)) == false) {
throw megaglest_runtime_error("Pathfinder invalid node path position = " + nodePos.getString() + " i = " + intToStr(i));
@ -987,16 +886,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(minorDebugPathfinder) printf("nodePos [%s]\n",nodePos.getString().c_str());
if(frameIndex >= 0) {
codeLocation = "56";
faction.precachedPath[unit->getId()].push_back(nodePos);
}
else {
codeLocation = "57";
if(i < unit->getPathFindRefreshCellCount() ||
(whileLoopCount >= pathFindExtendRefreshForNodeCount &&
i < getPathFindExtendRefreshNodeCount(faction))) {
codeLocation = "58";
path->add(nodePos);
}
}
@ -1034,7 +930,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
}
codeLocation = "60";
faction.openNodesList.clear();
faction.openPosList.clear();
@ -1043,7 +938,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] ---------------------------\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(frameIndex >= 0) {
codeLocation = "61";
FactionState &faction = factions.getFactionState(factionIndex);
faction.precachedTravelState[unit->getId()] = ts;
@ -1061,14 +955,14 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Loc [%s] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str(),ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw megaglest_runtime_error(ex.what());
}
catch(...) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error Loc [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str());
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw megaglest_runtime_error(szBuf);
}
@ -1077,45 +971,37 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
}
void PathFinder::processNearestFreePos(const Vec2i &finalPos, int i, int j, int size, Field field, int teamIndex,Vec2i unitPos, Vec2i &nearestPos, float &nearestDist) {
string codeLocation = "1";
try {
Vec2i currPos= finalPos + Vec2i(i, j);
codeLocation = "2";
if(map->isAproxFreeCells(currPos, size, field, teamIndex)) {
codeLocation = "3";
float dist= currPos.dist(finalPos);
codeLocation = "4";
//if nearer from finalPos
if(dist < nearestDist){
codeLocation = "5";
nearestPos= currPos;
nearestDist= dist;
}
//if the distance is the same compare distance to unit
else if(dist == nearestDist){
codeLocation = "6";
if(currPos.dist(unitPos) < nearestPos.dist(unitPos)) {
codeLocation = "7";
nearestPos= currPos;
}
}
codeLocation = "8";
}
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Loc [%s] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str(),ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw megaglest_runtime_error(ex.what());
}
catch(...) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error Loc [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str());
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw megaglest_runtime_error(szBuf);
}
@ -1123,7 +1009,6 @@ void PathFinder::processNearestFreePos(const Vec2i &finalPos, int i, int j, int
}
Vec2i PathFinder::computeNearestFreePos(const Unit *unit, const Vec2i &finalPos) {
string codeLocation = "1";
Vec2i nearestPos(0,0);
try {
@ -1132,47 +1017,39 @@ Vec2i PathFinder::computeNearestFreePos(const Unit *unit, const Vec2i &finalPos)
throw megaglest_runtime_error("map == NULL");
}
codeLocation = "2";
//unit data
int size= unit->getType()->getSize();
Field field= unit->getCurrField();
int teamIndex= unit->getTeam();
codeLocation = "3";
//if finalPos is free return it
if(map->isAproxFreeCells(finalPos, size, field, teamIndex)) {
codeLocation = "4";
return finalPos;
}
codeLocation = "5";
//find nearest pos
Vec2i unitPos= unit->getPosNotThreadSafe();
nearestPos= unitPos;
codeLocation = "6";
float nearestDist= unitPos.dist(finalPos);
codeLocation = "7";
for(int i= -maxFreeSearchRadius; i <= maxFreeSearchRadius; ++i) {
for(int j= -maxFreeSearchRadius; j <= maxFreeSearchRadius; ++j) {
codeLocation = "8";
processNearestFreePos(finalPos, i, j, size, field, teamIndex, unitPos, nearestPos, nearestDist);
}
}
codeLocation = "9";
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Loc [%s] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str(),ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw megaglest_runtime_error(ex.what());
}
catch(...) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error Loc [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str());
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw megaglest_runtime_error(szBuf);
}
@ -1211,20 +1088,16 @@ int PathFinder::findNodeIndex(Node *node, std::vector<Node> &nodeList) {
bool PathFinder::unitCannotMove(Unit *unit) {
bool unitImmediatelyBlocked = false;
string codeLocation = "1";
try {
// First check if unit currently blocked all around them, if so don't try to pathfind
const Vec2i unitPos = unit->getPos();
int failureCount = 0;
int cellCount = 0;
codeLocation = "2";
for(int i = -1; i <= 1; ++i) {
for(int j = -1; j <= 1; ++j) {
codeLocation = "3";
Vec2i pos = unitPos + Vec2i(i, j);
if(pos != unitPos) {
codeLocation = "4";
bool canUnitMoveToCell = map->aproxCanMove(unit, unitPos, pos);
if(canUnitMoveToCell == false) {
failureCount++;
@ -1233,21 +1106,20 @@ bool PathFinder::unitCannotMove(Unit *unit) {
}
}
}
codeLocation = "5";
unitImmediatelyBlocked = (failureCount == cellCount);
}
catch(const exception &ex) {
//setRunningStatus(false);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Loc [%s] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str(),ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw megaglest_runtime_error(ex.what());
}
catch(...) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error Loc [%s]\n",__FILE__,__FUNCTION__,__LINE__,codeLocation.c_str());
snprintf(szBuf,8096,"In [%s::%s %d] UNKNOWN error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
throw megaglest_runtime_error(szBuf);
}

File diff suppressed because it is too large Load Diff