private void CompleteRequest(PathingStatus status) { if (status == PathingStatus.Complete) { StackWithLookAhead<IPositioned> path; var maxPathLength = Mathf.CeilToInt(_goal.g / (_goal.parent.cellSize * _costProvider.baseMoveCost)); //Fix the actual destination so it does not overlap obstructions FixupGoal(_currentRequest); if (_currentRequest.usePathSmoothing) { path = _smoother.Smooth(_goal, maxPathLength, _currentRequest); } else { path = new StackWithLookAhead<IPositioned>(maxPathLength); //Push the actual end position as the goal path.Push(new Position(_currentRequest.to)); IPathNode current = _goal.predecessor; while (current != null) { path.Push(current); current = current.predecessor; } //Instead of testing for it in the while loop, just pop off the start node and replace it with the actual start position if (path.count > 1) { path.Pop(); } path.Push(new Position(_currentRequest.from)); } _currentRequest.Complete(status, path); } else { _currentRequest.Complete(status, null); } _currentRequest = null; }
private void ConsumeResult() { //Consume way points if appropriate. This must be done prior to the processing of the result, since if the request was a way point request, the first item in line is the one the result concerns. if (_pendingResult.originalRequest.type == RequestType.Waypoint) { _wayPoints.Dequeue(); } else if (_pendingResult.originalRequest.type == RequestType.PathboundWaypoint) { _pathboundWayPoints.Dequeue(); } //Reset current destination no matter what _currentDestination = null; //Since result processing may actually repath and consequently a new result may arrive we need to operate on locals and null the pending result var result = _pendingResult; _pendingResult = null; //Process the result if (!ProcessAndValidateResult(result)) { return; } //Consume the result _currentPath = result.path; _currentGrid = result.originalRequest.fromGrid; _endOfResolvedPath = _currentPath.Last().position; _endOfPath = _endOfResolvedPath; //Update pending way points UpdatePathboundWaypoints(result.pendingWaypoints); //The first point on the path is always the origin of the request, so we want to skip that. _currentPath.Pop(); }