public override void Initialize() { base.Initialize(); if (currentR != null && endingCondition.TargetFound(currentR)) { CompleteState = PathCompleteState.Complete; endNode = currentR.node; Trace(currentR); } }
/// <summary>The start node need to be special cased and checked here if it is a valid target</summary> protected override void CompletePathIfStartIsValidTarget() { var pNode = pathHandler.GetPathNode(startNode); if (endingCondition.TargetFound(pNode)) { ChangeEndNode(startNode); Trace(pNode); CompleteState = PathCompleteState.Complete; } }
public override void Initialize() { base.Initialize(); if (currentR != null && endingCondition.TargetFound(this, currentR)) { foundEnd = true; endNode = currentR.node; Trace(currentR); } }
public override void Initialize() { base.Initialize(); if (current != null && endingCondition.TargetFound(this, startNode)) { foundEnd = true; endNode = startNode; Trace(endNode); } }
/** The start node need to be special cased and checked here if it is a valid target */ protected override void CompletePathIfStartIsValidTarget() { var pNode = pathHandler.GetPathNode(startNode); if (endingCondition.TargetFound(pNode)) { endNode = pNode.node; endPoint = (Vector3)endNode.position; Trace(pNode); CompleteState = PathCompleteState.Complete; } }
public override void CalculateStep (long targetTick) { int counter = 0; //Continue to search while there hasn't ocurred an error and the end hasn't been found while (!IsDone()) { //@Performance Just for debug info searchedNodes++; //--- Here's the important stuff //Close the current node, if the current node satisfies the ending condition, the path is finished if (endingCondition.TargetFound (currentR)) { CompleteState = PathCompleteState.Complete; break; } //Add Node to allNodes allNodes.Add (currentR.node); #if ASTARDEBUG Debug.DrawRay ((Vector3)currentR.node.position,Vector3.up*5,Color.cyan); #endif //--- Here the important stuff ends //Loop through all walkable neighbours of the node and add them to the open list. currentR.node.Open (runData,currentR, Int3.zero ,this); //any nodes left to search? if (runData.open.numberOfItems <= 1) { CompleteState = PathCompleteState.Complete; break; } //Select the node with the lowest F score and remove it from the open list currentR = runData.open.Remove (); //Check for time every 500 nodes, roughly every 0.5 ms usually if (counter > 500) { //Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag if (System.DateTime.UtcNow.Ticks >= targetTick) { //Return instead of yield'ing, a separate function handles the yield (CalculatePaths) return; } counter = 0; } counter++; } if (CompleteState == PathCompleteState.Complete) { Trace (currentR); } }
protected override void CalculateStep(long targetTick) { int counter = 0; //Continue to search as long as we haven't encountered an error and we haven't found the target while (CompleteState == PathCompleteState.NotCalculated) { searchedNodes++; //--- Here's the important stuff //Close the current node, if the current node satisfies the ending condition, the path is finished if (endingCondition.TargetFound(currentR)) { CompleteState = PathCompleteState.Complete; break; } if (!currentR.flag1) { //Add Node to allNodes allNodes.Add(currentR.node); currentR.flag1 = true; } #if ASTARDEBUG Debug.DrawRay((Vector3)currentR.node.position, Vector3.up * 5, Color.cyan); #endif //--- Here the important stuff ends AstarProfiler.StartFastProfile(4); //Debug.DrawRay ((Vector3)currentR.node.Position, Vector3.up*2,Color.red); //Loop through all walkable neighbours of the node and add them to the open list. currentR.node.Open(this, currentR, pathHandler); AstarProfiler.EndFastProfile(4); //any nodes left to search? if (pathHandler.heap.isEmpty) { CompleteState = PathCompleteState.Complete; break; } //Select the node with the lowest F score and remove it from the open list AstarProfiler.StartFastProfile(7); currentR = pathHandler.heap.Remove(); AstarProfiler.EndFastProfile(7); //Check for time every 500 nodes, roughly every 0.5 ms usually if (counter > 500) { //Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag if (DateTime.UtcNow.Ticks >= targetTick) { //Return instead of yield'ing, a separate function handles the yield (CalculatePaths) return; } counter = 0; if (searchedNodes > 1000000) { throw new Exception("Probable infinite loop. Over 1,000,000 nodes searched"); } } counter++; } }
public override float CalculateStep(float remainingFrameTime) { System.DateTime startTime = System.DateTime.Now; System.Int64 maxTicks = (System.Int64)(remainingFrameTime * 10000); int counter = 0; //Continue to search while there hasn't ocurred an error and the end hasn't been found while (!foundEnd && !error) { //@Performance Just for debug info searchedNodes++; //--- Here's the important stuff //Close the current node, if the current node satisfies the ending condition, the path is finished if (endingCondition.TargetFound(this, current)) { foundEnd = true; break; } //Add Node to allNodes allNodes.Add(current); //--- Here the important stuff ends //Loop through all walkable neighbours of the node current.Open(open, hTarget, this); //any nodes left to search? if (open.numberOfItems <= 1) { //For this path type, this is actually a valid end foundEnd = true; break; } //Select the node with the lowest F score and remove it from the open list current = open.Remove(); //Check for time every 500 nodes if (counter > 500) { //Have we exceded the maxFrameTime, if so we should wait one frame before continuing the search since we don't want the game to lag if ((System.DateTime.Now.Ticks - startTime.Ticks) > maxTicks) //searchedNodesThisFrame > 20000) { { float durationThisFrame = (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F; duration += durationThisFrame; //Return instead of yield'ing, a separate function handles the yield (CalculatePaths) return(durationThisFrame); } counter = 0; } counter++; } if (foundEnd && !error) { Trace(endNode); } float durationThisFrame2 = (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F; duration += durationThisFrame2; //Return instead of yield'ing, a separate function handles the yield (CalculatePaths) return(durationThisFrame2); }