public override void Initialize() { if (hasEndPoint && startNode == endNode) { NodeRun endNodeR = endNode.GetNodeRun(runData); endNodeR.parent = null; endNodeR.h = 0; endNodeR.g = 0; Trace(endNodeR); CompleteState = PathCompleteState.Complete; return; } //Adjust the costs for the end node /*if (hasEndPoint && recalcStartEndCosts) { * endNodeCosts = endNode.InitialOpen (open,hTarget,(Int3)endPoint,this,false); * callback += ResetCosts; /* \todo Might interfere with other paths since other paths might be calculated before #callback is called * * }*/ NodeRun startRNode = startNode.GetNodeRun(runData); startRNode.pathID = pathID; startRNode.parent = null; startRNode.cost = 0; startRNode.g = startNode.penalty; startNode.UpdateH(hTarget, heuristic, heuristicScale, startRNode); /*if (recalcStartEndCosts) { * startNode.InitialOpen (open,hTarget,startIntPoint,this,true); * } else {*/ startNode.Open(runData, startRNode, hTarget, this); //} searchedNodes++; partialBestTarget = startRNode; //any nodes left to search? if (runData.open.numberOfItems <= 1) { if (calculatePartial) { CompleteState = PathCompleteState.Partial; Trace(partialBestTarget); } else { Error(); LogError("No open points, the start node didn't open any nodes"); return; } } currentR = runData.open.Remove(); }
/** Initializes the path. Sets up the open list and adds the first node to it */ public virtual void Initialize() { runData.pathID = pathID; //Resets the binary heap, don't clear everything because that takes an awful lot of time, instead we can just change the numberOfItems in it (which is just an int) //Binary heaps are just like a standard array but are always sorted so the node with the lowest F value can be retrieved faster runData.open.Clear(); if (hasEndPoint && startNode == endNode) { NodeRun endNodeR = endNode.GetNodeRun(runData); endNodeR.parent = null; endNodeR.h = 0; endNodeR.g = 0; Trace(endNodeR); foundEnd = true; return; } //Adjust the costs for the end node /*if (hasEndPoint && recalcStartEndCosts) { * endNodeCosts = endNode.InitialOpen (open,hTarget,(Int3)endPoint,this,false); * callback += ResetCosts; /* \todo Might interfere with other paths since other paths might be calculated before #callback is called * * }*/ //Node.activePath = this; NodeRun startRNode = startNode.GetNodeRun(runData); startRNode.pathID = pathID; startRNode.parent = null; startRNode.cost = 0; startRNode.g = startNode.penalty; startNode.UpdateH(hTarget, heuristic, heuristicScale, startRNode); /*if (recalcStartEndCosts) { * startNode.InitialOpen (open,hTarget,startIntPoint,this,true); * } else {*/ startNode.Open(runData, startRNode, hTarget, this); //} searchedNodes++; //any nodes left to search? if (runData.open.numberOfItems <= 1) { LogError("No open points, the start node didn't open any nodes"); return; } currentR = runData.open.Remove(); }
/** Returns if the node is in the search tree of the path. * Only guaranteed to be correct if \a path is the latest path calculated. * Use for gizmo drawing only. */ public bool InSearchTree(Node node, Path path) { if (path == null || path.runData == null) { return(true); } NodeRun nodeR = node.GetNodeRun(path.runData); return(nodeR.pathID == path.pathID); }
public virtual void OnDrawGizmos(bool drawNodes) { if (nodes == null || !drawNodes) { if (!Application.isPlaying) { //Scan (0); } return; } for (int i = 0; i < nodes.Length; i++) { Node node = nodes[i]; if (node.connections != null) { Gizmos.color = NodeColor(node, AstarPath.active.debugPathData); if (AstarPath.active.showSearchTree && !InSearchTree(node, AstarPath.active.debugPath)) { return; } if (AstarPath.active.showSearchTree && AstarPath.active.debugPathData != null && node.GetNodeRun(AstarPath.active.debugPathData).parent != null) { Gizmos.DrawLine((Vector3)node.position, (Vector3)node.GetNodeRun(AstarPath.active.debugPathData).parent.node.position); } else { for (int q = 0; q < node.connections.Length; q++) { Gizmos.DrawLine((Vector3)node.position, (Vector3)node.connections[q].position); } } } } }
/** Initializes the path. * Sets up the open list and adds the first node to it */ public override void Initialize () { NodeRun startRNode = startNode.GetNodeRun (runData); startRNode.pathID = pathID; startRNode.parent = null; startRNode.cost = 0; startRNode.g = startNode.penalty; startNode.UpdateH (Int3.zero,heuristic,heuristicScale, startRNode); startNode.Open (runData,startRNode,Int3.zero,this); searchedNodes++; allNodes.Add (startNode); //any nodes left to search? if (runData.open.numberOfItems <= 1) { CompleteState = PathCompleteState.Complete; return; } currentR = runData.open.Remove (); }
/// <summary> /// Returns a color to be used for the specified node with the current debug settings (editor only) /// </summary> /// <param name="node"> /// A <see cref="Node"/> /// </param> /// <returns> /// A <see cref="Color"/> /// </returns> public virtual Color NodeColor(Node node, NodeRunData data) { #if !PhotonImplementation Color c = AstarColor.NodeConnection; bool colSet = false; if (node == null) { return(AstarColor.NodeConnection); } switch (AstarPath.active.debugMode) { case GraphDebugMode.Areas: c = AstarColor.GetAreaColor(node.area); colSet = true; break; case GraphDebugMode.Penalty: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (float)node.penalty / (float)AstarPath.active.debugRoof); colSet = true; break; case GraphDebugMode.Tags: c = Mathfx.IntToColor(node.tags, 0.5F); colSet = true; break; /* Wasn't really usefull * case GraphDebugMode.Position: * float r = Mathf.PingPong (node.position.x/10000F,1F) + Mathf.PingPong (node.position.x/300000F,1F); * float g = Mathf.PingPong (node.position.y/10000F,1F) + Mathf.PingPong (node.position.y/200000F,1F); * float b = Mathf.PingPong (node.position.z/10000F,1F) + Mathf.PingPong (node.position.z/100000F,1F); * * * c = new Color (r,g,b); * break; */ } if (!colSet) { if (data == null) { return(AstarColor.NodeConnection); } NodeRun nodeR = node.GetNodeRun(data); if (nodeR == null) { return(AstarColor.NodeConnection); } switch (AstarPath.active.debugMode) { case GraphDebugMode.G: //c = Mathfx.IntToColor (node.g,0.5F); c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (float)nodeR.g / (float)AstarPath.active.debugRoof); break; case GraphDebugMode.H: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (float)nodeR.h / (float)AstarPath.active.debugRoof); break; case GraphDebugMode.F: c = Color.Lerp(AstarColor.ConnectionLowLerp, AstarColor.ConnectionHighLerp, (float)nodeR.f / (float)AstarPath.active.debugRoof); break; } } c.a *= 0.5F; return(c); #else return(new Color(1, 1, 1)); #endif }
/// <summary> /// Returns a color to be used for the specified node with the current debug settings (editor only) /// </summary> /// <param name="node"> /// A <see cref="Node"/> /// </param> /// <returns> /// A <see cref="Color"/> /// </returns> public virtual Color NodeColor(Node node, NodeRunData data) { Color c = AstarColor.NodeConnection; bool colSet = false; if (node == null) return AstarColor.NodeConnection; switch (AstarPath.active.debugMode) { case GraphDebugMode.Areas: c = AstarColor.GetAreaColor (node.area); colSet = true; break; case GraphDebugMode.Penalty: c = Color.Lerp (AstarColor.ConnectionLowLerp,AstarColor.ConnectionHighLerp, (float)node.penalty / (float)AstarPath.active.debugRoof); colSet = true; break; case GraphDebugMode.Tags: c = Mathfx.IntToColor (node.tags,0.5F); colSet = true; break; /* Wasn't really usefull case GraphDebugMode.Position: float r = Mathf.PingPong (node.position.x/10000F,1F) + Mathf.PingPong (node.position.x/300000F,1F); float g = Mathf.PingPong (node.position.y/10000F,1F) + Mathf.PingPong (node.position.y/200000F,1F); float b = Mathf.PingPong (node.position.z/10000F,1F) + Mathf.PingPong (node.position.z/100000F,1F); c = new Color (r,g,b); break; */ } if (!colSet) { if (data == null) return AstarColor.NodeConnection; NodeRun nodeR = node.GetNodeRun (data); if (nodeR == null) return AstarColor.NodeConnection; switch (AstarPath.active.debugMode) { case GraphDebugMode.G: //c = Mathfx.IntToColor (node.g,0.5F); c = Color.Lerp (AstarColor.ConnectionLowLerp,AstarColor.ConnectionHighLerp, (float)nodeR.g / (float)AstarPath.active.debugRoof); break; case GraphDebugMode.H: c = Color.Lerp (AstarColor.ConnectionLowLerp,AstarColor.ConnectionHighLerp, (float)nodeR.h / (float)AstarPath.active.debugRoof); break; case GraphDebugMode.F: c = Color.Lerp (AstarColor.ConnectionLowLerp,AstarColor.ConnectionHighLerp, (float)nodeR.f / (float)AstarPath.active.debugRoof); break; } } c.a *= 0.5F; return c; }
/** Returns if the node is in the search tree of the path. * Only guaranteed to be correct if \a path is the latest path calculated. * Use for gizmo drawing only. */ public bool InSearchTree(Node node, Path path) { if (path == null || path.runData == null) return true; NodeRun nodeR = node.GetNodeRun (path.runData); return nodeR.pathID == path.pathID; }
/** Opens the nodes connected to this node. This is a base call and can be called by node classes overriding the Open function to open all connections in the #connections array. * \see #connections * \see Open */ public void BaseOpen(NodeRunData nodeRunData, NodeRun nodeR, Int3 targetPosition, Path path) { if (connections == null) { return; } for (int i = 0; i < connections.Length; i++) { Node node = connections[i]; if (!path.CanTraverse(node)) { continue; } NodeRun nodeR2 = node.GetNodeRun(nodeRunData); if (nodeR2.pathID != nodeRunData.pathID) { nodeR2.parent = nodeR; nodeR2.pathID = nodeRunData.pathID; nodeR2.cost = (uint)connectionCosts[i]; node.UpdateH(targetPosition, path.heuristic, path.heuristicScale, nodeR2); node.UpdateG(nodeR2, nodeRunData); nodeRunData.open.Add(nodeR2); //Debug.DrawLine (position,node.position,Color.cyan); //Debug.Log ("Opening Node "+node.position.ToString ()+" "+g+" "+node.cost+" "+node.g+" "+node.f); } else { //If not we can test if the path from the current node to this one is a better one then the one already used uint tmpCost = (uint)connectionCosts[i]; if (nodeR.g + tmpCost + node.penalty #if !NoTagPenalty + path.GetTagPenalty(node.tags) #endif < nodeR2.g) { nodeR2.cost = tmpCost; nodeR2.parent = nodeR; //TODO!!!!! ?? node.UpdateAllG(nodeR2, nodeRunData); nodeRunData.open.Add(nodeR2); } else if (nodeR2.g + tmpCost + penalty #if !NoTagPenalty + path.GetTagPenalty(tags) #endif < nodeR.g) //Or if the path from this node ("node") to the current ("current") is better { bool contains = node.ContainsConnection(this); //Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be moved to from the other Node. /*if (node.connections != null) { * for (int y=0;y<node.connections.Length;y++) { * if (node.connections[y] == this) { * contains = true; * break; * } * } * }*/ if (!contains) { continue; } nodeR.parent = nodeR2; nodeR.cost = tmpCost; //TODO!!!!!!! ?? UpdateAllG(nodeR, nodeRunData); nodeRunData.open.Add(nodeR); } } } }
public override bool Suitable(Node node) { return(node.GetNodeRun(path.runData).pathID == path.pathID && base.Suitable(node)); }
public override bool Suitable(Node node) { return node.GetNodeRun(path.runData).pathID == path.pathID && base.Suitable (node); }