void m_map_AStarDone(AStarResult res) { var l = res.LastNode.Loc; var dirs = res.GetPathReverse(); m_path1.Points.Clear(); IntPoint2 p = new IntPoint2(l.X, l.Y); m_path1.Points.Add(new Point(p.X, p.Y)); foreach (var d in dirs) { var v = IntVector2.FromDirection(d); p += v; m_path1.Points.Add(new Point(p.X, p.Y)); } SetZ(m_path1, l.Z); }
void DoAStar(IntPoint3 src, IntPoint3 dst) { long startBytes, stopBytes; Stopwatch sw = new Stopwatch(); startBytes = GC.GetTotalMemory(true); sw.Start(); if (!this.Step) { m_result = AStarFinder.Find(this, src, this.SrcPos, dst, this.DstPos); sw.Stop(); stopBytes = GC.GetTotalMemory(true); this.MemUsed = stopBytes - startBytes; this.TicksUsed = sw.ElapsedTicks; this.Status = m_result.Status; m_nodes = m_result.Nodes; if (m_result.Status != AStarStatus.Found) { m_path = null; this.PathLength = 0; return; } var pathList = new List<IntPoint3>(); var n = m_result.LastNode; while (n.Parent != null) { pathList.Add(n.Loc); n = n.Parent; } m_path = pathList; this.PathLength = m_result.GetPathReverse().Count(); if (AStarDone != null) AStarDone(m_result); InvalidateTileData(); } else { m_contEvent.Reset(); Task.Factory.StartNew(() => m_result = AStarFinder.Find(this, src, this.SrcPos, dst, this.DstPos)) .ContinueWith((task) => { sw.Stop(); stopBytes = GC.GetTotalMemory(true); this.MemUsed = stopBytes - startBytes; this.TicksUsed = sw.ElapsedTicks; this.Status = m_result.Status; m_nodes = m_result.Nodes; if (m_result.Status != AStarStatus.Found) { m_path = null; this.PathLength = 0; return; } var pathList = new List<IntPoint3>(); var n = m_result.LastNode; while (n.Parent != null) { pathList.Add(n.Loc); n = n.Parent; } m_path = pathList; this.PathLength = m_result.GetPathReverse().Count(); if (AStarDone != null) AStarDone(m_result); InvalidateTileData(); }, TaskScheduler.FromCurrentSynchronizationContext()); } }