public List <MapCoordinate> FovFrom(IPositionSystem positionSystem, MapCoordinate mapCoordinate, int range, Func <Vector, bool> transparentTest = null) { var cachedFov = FovCache.TryGetCachedFov(mapCoordinate, range); if (cachedFov != null) { return(cachedFov); } if (mapCoordinate.Key != MapKey) { return(new List <MapCoordinate>()); } if (transparentTest == null) { transparentTest = (Vector v) => { var entities = positionSystem.EntitiesAt(mapCoordinate + v); var physicals = entities.Select(e => e.TryGet <Physical>()).Where(p => p != null); return(!physicals.Any(p => p.Transparent == false)); }; } var visibleVectors = ShadowcastingFovCalculator.InFov(range, transparentTest); var visibleCells = visibleVectors.Select(v => mapCoordinate + v).ToList(); FovCache.Cache(mapCoordinate, range, visibleCells); return(visibleCells); }
public void Cache_SavesFov() { var coord = new MapCoordinate(MAP_KEY, 0, 0); var fov = new List <MapCoordinate> { coord }; _fovCache.TryGetCachedFov(coord, 1).Should().BeNull(); _fovCache.Cache(coord, 1, fov); _fovCache.TryGetCachedFov(coord, 1).Should().BeEquivalentTo(fov); }