Exemple #1
0
        /// <summary>
        /// Resets the graph and the AStar instance so that pathfinding can be run again
        /// </summary>
        private void ResetGraph()
        {
            m_SolverFactory.CreateSolver(m_AlgorithmType, m_Grid, Heuristic, out m_PathFinder, out m_PathFindingListener);

            ResetNodes();

            if (GenerateWalls)
            {
                GenerateRandomWalls();
            }

            if (!SaveEndPoints)
            {
                SetStartAndEnd();
            }
            else
            {
                //The call to ResetNodes set everything the CellState.None, so we must reset these
                m_Grid.Set(m_Start, CellState.Start);
                m_Grid.Set(m_End, CellState.End);
            }
            m_GraphState = PathfindingGraphState.Ready;
        }
Exemple #2
0
        /// <summary>
        /// Runs a single step of the pathfinding process
        /// </summary>
        private void RunOneStep()
        {
            m_Stopwatch.Start();
            var path = m_PathFinder.PathFindOneStep(m_Start, m_End);
            m_Stopwatch.Stop();

            if (path != null)
            {
                ReportPathFinished(path);
            }
            else
            {
                m_GraphState = PathfindingGraphState.InProgress;
                ColorGridFromPathData(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Performs any necessary cleanup at the end of pathfinding and 
        /// populates the member PathFindingData instance with relevant data
        /// </summary>
        private void ReportPathFinished(Stack<Vector2i> path)
        {
            m_GraphState = PathfindingGraphState.Finished;
            var pathFindingTime = m_Stopwatch.Elapsed;
            m_Stopwatch.Reset();

            var pathLength = path.Count;
            var nodesVisited = m_PathFindingListener.Open.Count + m_PathFindingListener.Closed.Count;

            ColorGridFromPathData(path);

            Data.GraphSize = m_Grid.Count;
            Data.PathfindingTime = pathFindingTime;
            Data.TotalPathfindingTime += pathFindingTime;
            Data.PathLength = pathLength;
            Data.NodesVisited = nodesVisited;
            Data.TotalNodesVisited += nodesVisited;
            Data.TotalPathsComputed++;
        }