/// <summary> /// Удаляет просканированную область /// </summary> /// <param name="leftBottomPoint">Левая нижняя точка выбранной местности</param> /// <param name="rightTopPoint">Правая верхняя точка выбранной иестности</param> /// <param name="callback">Уведомление о завершении операции</param> public void RemoveArea(Vector2 leftBottomPoint, Vector2 rightTopPoint, OnOperationComplete callback = null) { TaskFactory.Add(() => { var removedArea = new AABB(leftBottomPoint, rightTopPoint); var removedCells = CellTree.RemoveAll(removedArea); foreach (var removedCell in removedCells) { foreach (var item in removedCell.Neighbours) { item.Key.Neighbours.Remove(removedCell); } List <Cell> gosCellsList = GetCells(removedCell.GameObject); if (gosCellsList != null) { gosCellsList.Remove(removedCell); } } if (callback != null) { callback(); } }); }
/// <summary> /// Bulk get patches. First find patch for closest point and then finding path from closest to others and combine this patches /// </summary> /// <typeparam name="T">Used for param only. It does not matter for calculation</typeparam> /// <param name="objectsStartPosition">Key is a parameter necessary to determine the object for which the path would calculated. Value is start position of this object</param> /// <param name="goalPosition">Goal position of path finding</param> /// <param name="callback">Callback for call after path was calculated</param> /// <param name="param">Parameter to determine calculation operation. Used in callback</param> /// <param name="accuracy">Accuracy. Larger - faster, but path maybe not correct</param> /// <returns>Thread id for cancelation calculation</returns> public BulkPathTask <T> GetPathesAsync <T>(IDictionary <T, Vector2> objectsStartPosition, Vector2 goalPosition, double accuracy = 1) { var thrId = Interlocked.Increment(ref _threadIdGenerator); var bulkPathTask = new BulkPathTask <T>(thrId, this); _runnedThreads.Add(thrId); TaskFactory.Add(() => GetPathesInternalTask(objectsStartPosition, goalPosition, accuracy, bulkPathTask)); return(bulkPathTask); }
public SinglePathTask GetPathAsync(Vector2 startPosition, Vector2 goalPosition, double accuracy = 1) { var thrId = Interlocked.Increment(ref _threadIdGenerator); _runnedThreads.Add(thrId); var pathTask = new SinglePathTask(thrId, this); TaskFactory.Add(() => GetPathInternalTask(startPosition, goalPosition, accuracy, pathTask)); return(pathTask); }
/// <summary> /// Выполняет сканирование и обработку местности /// </summary> /// <param name="leftBottomPoint">Левая нижняя точка выбранной местности</param> /// <param name="rightTopPoint">Правая верхняя точка выбранной иестности</param> /// <param name="scanAccuracy"></param> /// <param name="callback">Уведомление о завершении операции</param> /// <param name="addToExistingMap">Добавить в уже существующую карту</param> public void ScanArea(Vector2 leftBottomPoint, Vector2 rightTopPoint, float scanAccuracy = MinScanAccuracy * 50f, OnOperationComplete callback = null, bool addToExistingMap = true) { if (!addToExistingMap) { //CellTree.Clear(); CellTree = new AABBTree <Cell>(new InsertStrategyArea <Cell>()); CellsFromGameobject.Clear(); } var scanAreaBounds = new AABB(leftBottomPoint, rightTopPoint); //for debug //scanAreaBounds = new AABB(leftBottomPoint/10f, rightTopPoint/10f); if (scanAccuracy > scanAreaBounds.width) { scanAccuracy = scanAreaBounds.width - MinScanAccuracy; } if (scanAccuracy > scanAreaBounds.height) { scanAccuracy = scanAreaBounds.height - MinScanAccuracy; } ScanArea(scanAreaBounds /*, hitsTree*/, scanAccuracy); //todo: scan in thread TaskFactory.Add( () => { //CellTree.Build(); //CellTree.Balance(); //foreach (var node in CellTree) //{ // //TaskFactory.Add(() => // //{ // addNeighbours(node); // //}); //} if (callback != null) { callback(); } }); Debug.Log(CellTree.Count); //Debug.Log(CellTree.Height); }