Esempio n. 1
0
        public HashSet <Vector2Int> CalculateFov(Vector2Int fovCenter, int rayLength, Func <Vector2Int, bool> isWalkable)
        {
            var visibleTiles = new HashSet <Vector2Int>();
            HashSet <Vector2Int> outlineToCastRaysOn = _fovSquareOutlineCreator.CreateSquareOutline(fovCenter, rayLength);

            foreach (Vector2Int point in outlineToCastRaysOn)
            {
                IList <Vector2Int> bresenhamLineTiles = _bresenhamLineCreator.GetBresenhamLine(fovCenter.x, fovCenter.y, point.x, point.y, rayLength, isWalkable);
                visibleTiles.UnionWith(bresenhamLineTiles);
            }

            IEnumerable <Vector2Int> visibleTilesFromPostProcessing =
                _basicFovPostprocessor.PostprocessBasicFov(visibleTiles, fovCenter, rayLength, isWalkable);

            visibleTiles.UnionWith(visibleTilesFromPostProcessing);
            return(visibleTiles);
        }
Esempio n. 2
0
        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);
        }