From 4dffdd361d879f5c94a1a75ac52c2069c28b5bae Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Thu, 13 Jul 2023 19:37:26 +0100 Subject: [PATCH] lighting system. light sources NYI --- src/map.rs | 2 ++ src/visibility_system.rs | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/map.rs b/src/map.rs index 8895404..038e768 100644 --- a/src/map.rs +++ b/src/map.rs @@ -26,6 +26,7 @@ pub struct Map { pub height: i32, pub revealed_tiles: Vec, pub visible_tiles: Vec, + pub lit_tiles: Vec, pub telepath_tiles: Vec, pub red_offset: Vec, pub green_offset: Vec, @@ -101,6 +102,7 @@ impl Map { height: MAPHEIGHT as i32, revealed_tiles: vec![false; MAPCOUNT], visible_tiles: vec![false; MAPCOUNT], + lit_tiles: vec![true; MAPCOUNT], // NYI: Light sources. Once those exist, we can set this to false. telepath_tiles: vec![false; MAPCOUNT], red_offset: vec![0; MAPCOUNT], green_offset: vec![0; MAPCOUNT], diff --git a/src/visibility_system.rs b/src/visibility_system.rs index dbcc030..96e92b9 100644 --- a/src/visibility_system.rs +++ b/src/visibility_system.rs @@ -23,9 +23,16 @@ impl<'a> System<'a> for VisibilitySystem { // FIXME: SymmetricShadowcasting seems to be responsible for an infrequent crash -- // but it could be unrelated to the FieldOfViewAlg being used. Needs some more testing! // Appeared first after switching, but can't seem to reproduce it. - viewshed.visible_tiles = - SymmetricShadowcasting.field_of_view(Point::new(pos.x, pos.y), viewshed.range, &*map); - viewshed.visible_tiles.retain(|p| p.x >= 0 && p.x < map.width && p.y >= 0 && p.y < map.height); + let origin = Point::new(pos.x, pos.y); + viewshed.visible_tiles = SymmetricShadowcasting.field_of_view(origin, viewshed.range, &*map); + viewshed.visible_tiles.retain(|p| { + p.x >= 0 + && p.x < map.width + && p.y >= 0 + && p.y < map.height + && (map.lit_tiles[map.xy_idx(p.x, p.y)] == true + || rltk::DistanceAlg::Pythagoras.distance2d(Point::new(p.x, p.y), origin) < 1.5) + }); // If this is the player, reveal what they can see let _p: Option<&Player> = player.get(ent);