Example #1
0
        internal AStarResult(IDictionary<IntPoint3, AStarNode> nodes, AStarNode lastNode, AStarStatus status)
        {
            if (nodes == null)
                throw new ArgumentNullException();

            this.Nodes = nodes;
            this.LastNode = lastNode;
            this.Status = status;
        }
Example #2
0
 // Constructor
 public AINodeData(int column, int row)
 {
     coordinate = new Haxxit.Maps.Point(column, row);
     isAvailable = false;
     hasSilicoin = false;
     hasData = false;
     isSpawn = false;
     occupiedBy = null;
     aStarTrackStatus = AStarStatus.Unlisted;
     parent = null;
     f = int.MaxValue;
     g = int.MaxValue;
     h = int.MaxValue;
 }
Example #3
0
        void DoAStar(IntVector3 src, IntVector3 dst)
        {
            long      startBytes, stopBytes;
            Stopwatch sw = new Stopwatch();

            GC.Collect();
            startBytes = GC.GetTotalMemory(true);
            int gc0 = GC.CollectionCount(0);
            int gc1 = GC.CollectionCount(1);
            int gc2 = GC.CollectionCount(2);

            sw.Start();

            var initLocs = this.SrcPos.ToDirections().Select(d => src + d)
                           .Where(p => m_map.Bounds.Contains(p) && !m_map.GetBlocked(p));

            var astar = new AStar(initLocs, new MyTarget(m_map, dst, this.DstPos));

            if (!this.Step)
            {
                var status = astar.Find();

                sw.Stop();
                gc0       = GC.CollectionCount(0) - gc0;
                gc1       = GC.CollectionCount(1) - gc1;
                gc2       = GC.CollectionCount(2) - gc2;
                stopBytes = GC.GetTotalMemory(true);

                this.MemUsed       = stopBytes - startBytes;
                this.TicksUsed     = sw.ElapsedTicks;
                this.GCCollections = String.Format("{0}/{1}/{2}", gc0, gc1, gc2);

                this.Status = status;
                m_nodes     = astar.NodeMap;

                if (status != AStarStatus.Found)
                {
                    m_path          = null;
                    this.PathLength = 0;
                    this.NodeCount  = 0;
                    return;
                }

                m_path = new HashSet <IntVector3>(astar.GetPathLocationsReverse());
                var dirs = astar.GetPathReverse().ToArray();

                this.PathLength = dirs.Length;
                this.NodeCount  = astar.NodeMap.Count;

                InvalidateTileData();

                Trace.TraceInformation("Ticks {0}, Mem {1}, Len {2}, NodeCount {3}, GC {4}", this.TicksUsed, this.MemUsed,
                                       this.PathLength, this.NodeCount, this.GCCollections);
            }
            else
            {
                astar.DebugCallback = AStarDebugCallback;

                m_contEvent.Reset();

                AStarStatus status = AStarStatus.NotFound;

                Task.Factory.StartNew(() =>
                {
                    status = astar.Find();
                })
                .ContinueWith((task) =>
                {
                    sw.Stop();
                    stopBytes = GC.GetTotalMemory(true);

                    this.MemUsed   = stopBytes - startBytes;
                    this.TicksUsed = sw.ElapsedTicks;

                    this.Status = status;
                    m_nodes     = astar.NodeMap;

                    if (status != AStarStatus.Found)
                    {
                        m_path          = null;
                        this.PathLength = 0;
                        this.NodeCount  = 0;
                        return;
                    }

                    m_path   = new HashSet <IntVector3>(astar.GetPathLocationsReverse());
                    var dirs = astar.GetPathReverse().ToArray();

                    this.PathLength = dirs.Length;
                    this.NodeCount  = astar.NodeMap.Count;

                    InvalidateTileData();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
Example #4
0
 internal AStarResult(AStarStatus status, AStarNode lastNode)
 {
     this.LastNode = lastNode;
     this.Status   = status;
 }
Example #5
0
 internal AStarResult(AStarStatus status, AStarNode lastNode)
 {
     this.LastNode = lastNode;
     this.Status = status;
 }