/// <summary> /// Initializes (or re-intializes) a pathfinding task. Use this if ïf the PFTask was default constructed or you wish the re-initialize an instance PFTask. /// </summary> /// <param name="startPoint">Starting point of the path.</param> /// <param name="targetPoint">Target point of the path.</param> /// <param name="map">Topographic data to use for pathfinding. Must inheirit from interface: IPFMap.</param> /// <param name="wait">Wait for completion of current pathfinding.</param> /// <param name="includeDiagonals"></param> /// <param name="nodeBaseCost"></param> /// <param name="useFailsafe"></param> /// <returns></returns> public bool Initialize(IPFVector startPoint, IPFVector targetPoint, IOPFMap map, bool wait = false, bool includeDiagonals = true, bool useFailsafe = false) { if (!isDone) { if (!wait) { return(false); } if (!WaitJoin()) { return(false); } } PFThreadDeleteTID(instanceData); pfStatus = OPFStatus.TaskIsRunning; if (!useFailsafe) { instanceData = FindPathExThreaded(startPoint.IntX, startPoint.IntY, targetPoint.IntX, targetPoint.IntY, map.GetLinearTopography(), map.Width, map.Height, (int)map.MaxPathlength, includeDiagonals, map.NodeBaseCost); } else { instanceData = FindPathExThreadedFailsafe(startPoint.IntX, startPoint.IntY, targetPoint.IntX, targetPoint.IntY, map.GetLinearTopography(), map.Width, map.Height, (int)map.MaxPathlength, includeDiagonals, map.NodeBaseCost); } return(true); }
/// <summary> /// Starts a new threaded pathfinding task. /// </summary> /// <param name="startPoint">Starting point of the path.</param> /// <param name="targetPoint">Target point of the path.</param> /// <param name="map">Topographic data to use for pathfinding. Must inheirit from interface: IPFMap.</param> /// <param name="includeDiagonals"></param> /// <param name="useFailsafe"></param> public PFTask(IPFVector startPoint, IPFVector targetPoint, IOPFMap map, bool includeDiagonals = true, bool useFailsafe = false) { pfStatus = OPFStatus.TaskIsRunning; byte[] linearTopography = map.GetLinearTopography(); if (!useFailsafe) { instanceData = FindPathExThreaded(startPoint.IntX, startPoint.IntY, targetPoint.IntX, targetPoint.IntY, linearTopography, map.Width, map.Height, (int)map.MaxPathlength, includeDiagonals, map.NodeBaseCost); } else { instanceData = FindPathExThreadedFailsafe(startPoint.IntX, startPoint.IntY, targetPoint.IntX, targetPoint.IntY, linearTopography, map.Width, map.Height, (int)map.MaxPathlength, includeDiagonals, map.NodeBaseCost); } }