public bool LineIsWalkable(Position startPoint, Position targetPoint, Func <Position, bool> isWalkable) { if (!_ready) { InitializeAlgorithms(_contextManager.Current); } foreach (Position position in _rasterLineCreator.GetRasterLine(startPoint.x, startPoint.y, targetPoint.x, targetPoint.y)) { if (!isWalkable(position)) { return(false); } } return(true); }
public HashSet <Position> CalculateFov(Position observerPosition, int sightRange, Func <Position, bool> isPassingLight) { var positionsInFov = new HashSet <Position>(); IEnumerable <Position> outlineToCastRaysOn = _fovSquareOutlineCreator.CreateSquareOutline(observerPosition, sightRange); foreach (Position point in outlineToCastRaysOn) { IList <Position> bresenhamLineTiles = _rasterLineCreator .GetRasterLine(observerPosition.x, observerPosition.y, point.x, point.y, isPassingLight, sightRange, true); positionsInFov.UnionWith(bresenhamLineTiles); } IEnumerable <Position> visibleTilesFromPostProcessing = _basicFovPostprocessor.PostprocessBasicFov(positionsInFov, observerPosition, sightRange, isPassingLight); positionsInFov.UnionWith(visibleTilesFromPostProcessing); return(positionsInFov); }
private void PresentSelectionPath(Position playerPosition, Position newMarkerPosition) { Stopwatch stopwatch = Stopwatch.StartNew(); IList <Position> positions = _rasterLineCreator.GetRasterLine(playerPosition.x, playerPosition.y, newMarkerPosition.x, newMarkerPosition.y); // Debug.Log("raster: " + stopwatch.ElapsedMilliseconds); stopwatch.Restart(); _tileMatrixUpdater.ClearForTile(_gameConfig.Tileset.SelectionPathMarker); // Debug.Log("clean: " + stopwatch.ElapsedMilliseconds); stopwatch.Restart(); foreach (Position position in positions.Skip(1)) { _tileMatrixUpdater.Set(position, _gameConfig.Tileset.SelectionPathMarker); } _tileMatrixUpdater.Set(positions.Last(), _gameConfig.Tileset.SelectionFinishMarker); // Debug.Log("set: " + stopwatch.ElapsedMilliseconds); }