/* * calculate requested vertex */ void CPathEstimator::CalculateVertex(const MoveData& moveData, int parentBlockX, int parentBlockZ, unsigned int direction, int threadID) { // initial calculations int parentBlocknr = parentBlockZ * nbrOfBlocksX + parentBlockX; int childBlockX = parentBlockX + directionVector[direction].x; int childBlockZ = parentBlockZ + directionVector[direction].y; int vertexNbr = moveData.pathType * nbrOfBlocks * PATH_DIRECTION_VERTICES + parentBlocknr * PATH_DIRECTION_VERTICES + direction; // outside map? if (childBlockX < 0 || childBlockZ < 0 || childBlockX >= nbrOfBlocksX || childBlockZ >= nbrOfBlocksZ) { vertex[vertexNbr] = PATHCOST_INFINITY; return; } // start position int parentXSquare = blockState[parentBlocknr].sqrCenter[moveData.pathType].x; int parentZSquare = blockState[parentBlocknr].sqrCenter[moveData.pathType].y; float3 startPos = SquareToFloat3(parentXSquare, parentZSquare); // goal position int childBlocknr = childBlockZ * nbrOfBlocksX + childBlockX; int childXSquare = blockState[childBlocknr].sqrCenter[moveData.pathType].x; int childZSquare = blockState[childBlocknr].sqrCenter[moveData.pathType].y; float3 goalPos = SquareToFloat3(childXSquare, childZSquare); // PathFinder definition CRangedGoalWithCircularConstraint pfDef(startPos, goalPos, 0, 1.1f, 2); // the path to find Path path; SearchResult result; if (threadID >= 0) { // since CPathFinder::GetPath() is not thread-safe, // use this thread's "private" CPathFinder instance // (rather than locking pathFinder->GetPath()) if we // are in one result = pathFinders[threadID]->GetPath(moveData, startPos, pfDef, path, false, true, 10000, false); } else { // otherwise use the pathFinder instance passed to // the constructor of this CPathEstimator object result = pathFinder->GetPath(moveData, startPos, pfDef, path, false, true, 10000, false); } // store the result if (result == Ok) { vertex[vertexNbr] = path.pathCost; } else { vertex[vertexNbr] = PATHCOST_INFINITY; } }
/** * Calculate requested vertex */ void CPathEstimator::CalculateVertex(const MoveData& moveData, int parentBlockX, int parentBlockZ, unsigned int direction, int thread) { // initial calculations const int parentBlocknr = parentBlockZ * nbrOfBlocksX + parentBlockX; const int childBlockX = parentBlockX + directionVector[direction].x; const int childBlockZ = parentBlockZ + directionVector[direction].y; const int vertexNbr = moveData.pathType * blockStates.GetSize() * PATH_DIRECTION_VERTICES + parentBlocknr * PATH_DIRECTION_VERTICES + direction; // outside map? if (childBlockX < 0 || childBlockZ < 0 || childBlockX >= nbrOfBlocksX || childBlockZ >= nbrOfBlocksZ) { vertices[vertexNbr] = PATHCOST_INFINITY; return; } // start position const int parentXSquare = blockStates[parentBlocknr].nodeOffsets[moveData.pathType].x; const int parentZSquare = blockStates[parentBlocknr].nodeOffsets[moveData.pathType].y; const float3 startPos = SquareToFloat3(parentXSquare, parentZSquare); // goal position const int childBlocknr = childBlockZ * nbrOfBlocksX + childBlockX; const int childXSquare = blockStates[childBlocknr].nodeOffsets[moveData.pathType].x; const int childZSquare = blockStates[childBlocknr].nodeOffsets[moveData.pathType].y; const float3 goalPos = SquareToFloat3(childXSquare, childZSquare); // PathFinder definition CRangedGoalWithCircularConstraint pfDef(startPos, goalPos, 0, 1.1f, 2); // the path to find IPath::Path path; IPath::SearchResult result; // since CPathFinder::GetPath() is not thread-safe, // use this thread's "private" CPathFinder instance // (rather than locking pathFinder->GetPath()) if we // are in one result = pathFinders[thread]->GetPath(moveData, startPos, pfDef, path, false, true, MAX_SEARCHED_NODES_PE, false, 0, true); // store the result if (result == IPath::Ok) vertices[vertexNbr] = path.pathCost; else vertices[vertexNbr] = PATHCOST_INFINITY; }
/* Calculate requested vertex. */ void CPathEstimator::CalculateVertex(const MoveData& moveData, int parentBlockX, int parentBlockZ, unsigned int direction) { //Initial calculations. int parentBlocknr = parentBlockZ * nbrOfBlocksX + parentBlockX; int childBlockX = parentBlockX + directionVector[direction].x; int childBlockZ = parentBlockZ + directionVector[direction].y; int vertexNbr = moveData.pathType * nbrOfBlocks * PATH_DIRECTION_VERTICES + parentBlocknr * PATH_DIRECTION_VERTICES + direction; //Outside map? if(childBlockX < 0 || childBlockZ < 0 || childBlockX >= nbrOfBlocksX || childBlockZ >= nbrOfBlocksZ) { vertex[vertexNbr] = PATHCOST_INFINITY; return; } //Starting position. int parentXSquare = blockState[parentBlocknr].sqrCenter[moveData.pathType].x; int parentZSquare = blockState[parentBlocknr].sqrCenter[moveData.pathType].y; float3 startPos = SquareToFloat3(parentXSquare, parentZSquare); //Goal position. int childBlocknr = childBlockZ * nbrOfBlocksX + childBlockX; int childXSquare = blockState[childBlocknr].sqrCenter[moveData.pathType].x; int childZSquare = blockState[childBlocknr].sqrCenter[moveData.pathType].y; float3 goalPos = SquareToFloat3(childXSquare, childZSquare); //PathFinder definiton. CRangedGoalWithCircularConstraint pfDef(startPos, goalPos, 0, 1.1f,2); //Path Path path; //Performs the search. SearchResult result = pathFinder->GetPath(moveData, startPos, pfDef, path, false, true,10000,false); //Store the result. if(result == Ok) { vertex[vertexNbr] = path.pathCost; } else { vertex[vertexNbr] = PATHCOST_INFINITY; } }