public void RequestPath_SingleThread_NoExceptions() { var multithreadedPathfinder = PathfinderSetup.Create(1); multithreadedPathfinder.Start(); var pathRequest = PathRequest.Create(multithreadedPathfinder, null, null); pathRequest.WaitHandle.WaitOne(1000); Assert.AreEqual(PathRequestStatus.Solved, pathRequest.Status); }
public void Setup() { var factory = new DefinitionNodeGridFactory(); var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 320, 200); _definitionNodeGrid = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1)); _dijkstraNodeGrid = new DijkstraNodeGrid(_definitionNodeGrid, 1); _algorithm = new DijkstraAlgorithm(_definitionNodeGrid.NodeCount); _pathRequest = PathRequest.Create(Substitute.For <IPathfinder <NodePath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(319, 199)); _nodeNetwork = _dijkstraNodeGrid.GetCollisionLayerNetwork(_pathRequest.CollisionCategory); }
public void RequestPath_SingleThread_NoExceptions() { var manager = new PathfindaxManager(Substitute.For <IUpdatableSynchronizationContext>()); var multithreadedPathfinder = PathfinderSetup.Create(manager, 1); multithreadedPathfinder.Start(); var pathRequest = PathRequest.Create(multithreadedPathfinder, -1, -1); pathRequest.WaitHandle.WaitOne(1000); Assert.AreEqual(PathRequestStatus.Solved, pathRequest.Status); }
private PotentialField RunPotentialField(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes) { var potentialFieldAlgorithm = new PotentialFieldAlgorithm(0, definitionNodeGrid.NodeCount); var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y); var end = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y); var pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid, 5); var pathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1); return(potentialFieldAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes)); }
private NodePath RunAstar(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes) { var aStarAlgorithm = new AStarAlgorithm(definitionNodeGrid.NodeCount, new EuclideanDistance()); var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y); var end = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y); var pathfindingNetwork = new AstarNodeNetwork(definitionNodeGrid, new BrushfireClearanceGenerator(definitionNodeGrid, 5)); var pathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1); return(aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes)); }
public void Integration_StatusFlowToNoPathFound() { var manager = new PathfindaxManager(Substitute.For <IUpdatableSynchronizationContext>()); var pathfinder = PathfinderSetup.Create(manager, 1, false); var request = PathRequest.Create <IPath>(-1, -1); Assert.AreEqual(PathRequestStatus.Created, request.Status); pathfinder.RequestPath(request); Assert.AreEqual(PathRequestStatus.Solving, request.Status); pathfinder.Start(); request.WaitHandle.WaitOne(1000); Assert.AreEqual(PathRequestStatus.NoPathFound, request.Status); }
private WaypointPath RunDijkstra(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd) { var dijkstraAlgorithm = new DijkstraAlgorithm(definitionNodeGrid.NodeCount); var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y); var end = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y); var pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid, 5); var pathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1); var path = dijkstraAlgorithm.FindPath(pathfindingNetwork, pathRequest); return(path); }
public void Setup() { var factory = new DefinitionNodeGridFactory(); var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 320, 200); _definitionNodeGrid = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1)); _astarNodeNetwork = new AstarNodeNetwork(_definitionNodeGrid, new BrushfireClearanceGenerator(_definitionNodeGrid, 1)); _algorithm = new AStarAlgorithm(_definitionNodeGrid.NodeCount, new ManhattanDistance()); _longPathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(319, 199)); _shortPathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(20, 20)); _veryShortPathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(1, 0)); _zeroLengthPathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(0, 0)); }
public PathRequest <PotentialField> CreatePathRequest(IPathfinder <PotentialField> pathfinder, IDefinitionNodeNetwork definitionNodes, float x1, float y1, float x2, float y2, PathfindaxCollisionCategory collisionLayer = PathfindaxCollisionCategory.None, byte agentSize = 1) { switch (definitionNodes) { case IDefinitionNodeGrid definitionNodeGrid: var offset = -GridClearanceHelper.GridNodeOffset(agentSize, definitionNodeGrid.Transformer.Scale); var startNode = definitionNodeGrid.GetNode(x1 + offset.X, y1 + offset.Y); var endNode = definitionNodeGrid.GetNode(x2 + offset.X, y2 + offset.Y); return(PathRequest.Create(pathfinder, startNode, endNode, collisionLayer, agentSize)); default: throw new NotSupportedException($"{definitionNodes.GetType()} is not supported"); } }
public void Integration_AddCallbackAfterPathIsSolved_CallbackIsCalled() { var pathfinder = PathfinderSetup.Create(1); pathfinder.Start(); var request = PathRequest.Create(pathfinder, Substitute.For <IDefinitionNode>(), Substitute.For <IDefinitionNode>()); request.WaitHandle.WaitOne(1000); var done = false; request.AddCallback(x => done = true); Assert.AreEqual(true, done); }
public void Integration_AddCallbackAfterPathIsSolved_CallbackIsCalled() { var manager = new PathfindaxManager(Substitute.For <IUpdatableSynchronizationContext>()); var pathfinder = PathfinderSetup.Create(manager, 1); pathfinder.Start(); var request = PathRequest.Create(pathfinder, -1, -1); request.WaitHandle.WaitOne(1000); var done = false; request.AddCallback(x => done = true); Assert.AreEqual(true, done); }
public void Integration_AddCallbackBeforePathIsSolved_CallbackIsCalled() { var pathfinder = PathfinderSetup.Create(1); pathfinder.Start(); var request = PathRequest.Create <IPath>(Substitute.For <IDefinitionNode>(), Substitute.For <IDefinitionNode>()); var done = false; request.AddCallback(x => done = true); request.StartSolvePath(pathfinder); request.WaitHandle.WaitOne(1000); pathfinder.ProcessPaths(); //This should call the callback if the path is finished. Assert.AreEqual(true, done); }
public void Integration_AddCallbackBeforePathIsSolved_CallbackIsCalled() { var manager = new PathfindaxManager(new UpdatableSynchronizationContext()); var pathfinder = PathfinderSetup.Create(manager, 1); pathfinder.Start(); var request = PathRequest.Create <IPath>(-1, -1); var done = false; request.AddCallback(x => done = true); pathfinder.RequestPath(request); request.WaitHandle.WaitOne(1000); manager.Update(1f); //This should call the callback if the path is finished. Assert.AreEqual(true, done); }
private void RequestNewPath(int x, int y, int tx, int ty) { if (Request != null) { if (Request.State != PathRequestState.IDLE) { Debug.LogError("New path requested when the last path was in queue or processing! Not valid!"); return; } } if (!HasControl) { Debug.LogError("New bot path was requested when the bot naviagtion system was not in control!"); } Request = PathRequest.Create(x, y, tx, ty, PathDone); }
public void RequestPath_MultipleThreads_NoExceptions() { var multithreadedPathfinder = PathfinderSetup.Create(4); multithreadedPathfinder.Start(); var pathRequests = new PathRequest <IPath> [64]; for (var i = 0; i < pathRequests.Length; i++) { pathRequests[i] = PathRequest.Create(multithreadedPathfinder, null, null);; } WaitHandle.WaitAll(pathRequests.Select(x => x.WaitHandle).ToArray(), 2000); foreach (var pathRequest in pathRequests) { Assert.AreEqual(PathRequestStatus.Solved, pathRequest.Status); } }
public void RequestPath_MultipleThreads_NoExceptions() { var manager = new PathfindaxManager(Substitute.For <IUpdatableSynchronizationContext>()); var multithreadedPathfinder = PathfinderSetup.Create(manager, 4); multithreadedPathfinder.Start(); var pathRequests = new PathRequest <IPath> [64]; for (var i = 0; i < pathRequests.Length; i++) { pathRequests[i] = PathRequest.Create(multithreadedPathfinder, -1, -1);; } WaitHandle.WaitAll(pathRequests.Select(x => x.WaitHandle).ToArray(), 2000); foreach (var pathRequest in pathRequests) { Assert.AreEqual(PathRequestStatus.Solved, pathRequest.Status); } }