Beispiel #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;
        }