Remove() public méthode

public Remove ( ) : GraphNode
Résultat GraphNode
Exemple #1
0
        /** Initializes the path. Sets up the open list and adds the first node to it */
        public virtual void Initialize()
        {
            System.DateTime startTime = System.DateTime.Now;

            //Resets the binary heap, don't clear it 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

            open = AstarPath.active.binaryHeap;
            open.numberOfItems = 1;

            if (hasEndPoint && startNode == endNode)
            {
                endNode.parent = null;
                endNode.h      = 0;
                endNode.g      = 0;
                Trace(endNode);
                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;
            startNode.pathID = pathID;
            startNode.parent = null;
            startNode.cost   = 0;
            startNode.g      = startNode.penalty;
            startNode.UpdateH(hTarget, heuristic, heuristicScale);

            if (recalcStartEndCosts)
            {
                startNode.InitialOpen(open, hTarget, startIntPoint, this, true);
            }
            else
            {
                startNode.Open(open, hTarget, this);
            }

            searchedNodes++;

            //any nodes left to search?
            if (open.numberOfItems <= 1)
            {
                LogError("No open points, the start node didn't open any nodes");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            current = open.Remove();

            duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
        }
Exemple #2
0
        /** Initializes the path. Sets up the open list and adds the first node to it */
        public virtual void Initialize()
        {
            System.DateTime startTime = System.DateTime.Now;

            //Resets the binary heap, don't clear it 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

            open = AstarPath.active.binaryHeap;
            open.numberOfItems = 1;

            if (hasEndPoint && startNode == endNode)
            {
                endNode.parent = null;
                endNode.h = 0;
                endNode.g = 0;
                Trace(endNode);
                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;
            startNode.pathID = pathID;
            startNode.parent = null;
            startNode.cost = 0;
            startNode.g = startNode.penalty;
            startNode.UpdateH(hTarget, heuristic, heuristicScale);

            if (recalcStartEndCosts)
            {
                startNode.InitialOpen(open, hTarget, startIntPoint, this, true);
            }
            else
            {
                startNode.Open(open, hTarget, this);
            }

            searchedNodes++;

            //any nodes left to search?
            if (open.numberOfItems <= 1)
            {
                LogError("No open points, the start node didn't open any nodes");

                duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                return;
            }

            current = open.Remove();

            duration += (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
        }
Exemple #3
0
        /*public void CalculateStepMultiple (bool randomVar) {
         *
         *      //@float startTime = Time.realtimeSinceStartup;
         *      //start.script = this;
         *      //start.parent = null;
         *
         *      int searchedNodesThisFrame = 0;
         *      //Continue to search while there hasn't ocurred an error and the end hasn't been found
         *      while (!foundEnd && !error) {
         *
         *              //Close the current node, if the current node is the target node then the path is finnished
         *              for (int i=0;i<endNodes.Length;i++) {
         *                      if (current == endNodes[i]) {
         *                              endsFound++;
         *                              Trace (current);
         *
         *                              if (seekers[i] != null) {
         *                                      seekers[i].OnComplete (this);
         *                              }
         *                      }
         *
         *                      if (endsFound == endNodes.Length) {
         *                              break;
         *                      }
         *              }
         *
         *              if (current == null) {
         *                      Debug.LogWarning ("Current is Null");
         *                      return;
         *              }
         *
         *              //Debug.DrawRay ( current.position, Vector3.up*10,Color.cyan);
         *
         *              //@Performance Just for debug info
         *              searchedNodes++;
         *
         *              searchedNodesThisFrame++;
         *              //Loop through all walkable neighbours of the node
         *
         *              current.Open (open, endNode,this);
         *
         *              //any nodes left to search?
         *              if (open.numberOfItems <= 1) {
         *                      Debug.LogWarning ("No open points, whole area searched");
         *                      error = true;
         *                      return;
         *              }
         *
         *              //Select the node with the lowest F score and remove it from the open array
         *              current = open.Remove ();
         *
         *              //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 (Time.realtimeSinceStartup-startTime >= maxFrameTime) {
         *              if (searchedNodesThisFrame > 1000) {
         *                      //@duration += Time.realtimeSinceStartup-startTime;
         *
         *                      //Return instead of yield'ing, a separate function handles the yield (CalculatePaths)
         *                      return;
         *              }
         *
         *      }
         *
         *      if (foundEnd && !error) {
         *              Trace (endNode);
         *      }
         *      //@duration += Time.realtimeSinceStartup-startTime;
         *
         *      //Send the computed path to the seeker
         *      if (seeker != null) {
         *              seeker.OnComplete (this);
         *      }
         *
         * }*/

        public virtual float CalculateStep(float remainingFrameTime)
        {
            System.DateTime startTime = System.DateTime.Now;

            System.Int64 maxTicks = (System.Int64)(remainingFrameTime * 10000);


            //start.script = this;
            //start.parent = null;


            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++;

                //Close the current node, if the current node is the target node then the path is finnished
                if (current == endNode)
                {
                    foundEnd = true;
                    break;
                }

                /*if (current == null) {
                 *      Debug.LogWarning ("Current is Null");
                 *      return;
                 * }*/

                //Debug.DrawRay ( current.position, Vector3.up*10,Color.cyan);


                //Loop through all walkable neighbours of the node

                current.Open(open, hTarget, this);

                //any nodes left to search?
                if (open.numberOfItems <= 1)
                {
                    LogError("No open points, whole area searched");

                    float durationThisFrame = (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                    duration += durationThisFrame;

                    return(durationThisFrame);
                }

                //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;

            //When using multithreading, this signals that another function should call the callback function for this path
            //sendCompleteCall = true;

            //Return instead of yield'ing, a separate function handles the yield (CalculatePaths)
            return(durationThisFrame2);
        }
Exemple #4
0
        /** Calculates the path until completed or until the function duration has exceeded \a remainingFrameTime.
         * Usually a check is only done every 500 nodes if the time has exceeded \a remainingFrameTime. */
        public virtual 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++;

                //Close the current node, if the current node is the target node then the path is finnished
                if (current == endNode)
                {
                    foundEnd = true;
                    break;
                }

                //Loop through all walkable neighbours of the node and add them to the open list.
                current.Open(open, hTarget, this);

                //any nodes left to search?
                if (open.numberOfItems <= 1)
                {
                    LogError("No open points, whole area searched");

                    float durationThisFrame = (System.DateTime.Now.Ticks - startTime.Ticks) * 0.0001F;
                    duration += durationThisFrame;

                    return(durationThisFrame);
                }

                //Select the node with the lowest F score and remove it from the open list
                current = open.Remove();

                //Check for time every 500 nodes, roughly every 0.5 ms
                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)
                    {
                        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 yielding, a separate function handles the yield (CalculatePaths or CalculatePathsThreaded in AstarPath.cs)
            return(durationThisFrame2);
        }