lighting system. light sources NYI

This commit is contained in:
Llywelwyn 2023-07-13 19:37:26 +01:00
parent 24417fbb05
commit 4dffdd361d
2 changed files with 12 additions and 3 deletions

View file

@ -26,6 +26,7 @@ pub struct Map {
pub height: i32, pub height: i32,
pub revealed_tiles: Vec<bool>, pub revealed_tiles: Vec<bool>,
pub visible_tiles: Vec<bool>, pub visible_tiles: Vec<bool>,
pub lit_tiles: Vec<bool>,
pub telepath_tiles: Vec<bool>, pub telepath_tiles: Vec<bool>,
pub red_offset: Vec<u8>, pub red_offset: Vec<u8>,
pub green_offset: Vec<u8>, pub green_offset: Vec<u8>,
@ -101,6 +102,7 @@ impl Map {
height: MAPHEIGHT as i32, height: MAPHEIGHT as i32,
revealed_tiles: vec![false; MAPCOUNT], revealed_tiles: vec![false; MAPCOUNT],
visible_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], telepath_tiles: vec![false; MAPCOUNT],
red_offset: vec![0; MAPCOUNT], red_offset: vec![0; MAPCOUNT],
green_offset: vec![0; MAPCOUNT], green_offset: vec![0; MAPCOUNT],

View file

@ -23,9 +23,16 @@ impl<'a> System<'a> for VisibilitySystem {
// FIXME: SymmetricShadowcasting seems to be responsible for an infrequent crash -- // FIXME: SymmetricShadowcasting seems to be responsible for an infrequent crash --
// but it could be unrelated to the FieldOfViewAlg being used. Needs some more testing! // 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. // Appeared first after switching, but can't seem to reproduce it.
viewshed.visible_tiles = let origin = Point::new(pos.x, pos.y);
SymmetricShadowcasting.field_of_view(Point::new(pos.x, pos.y), viewshed.range, &*map); 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); 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 // If this is the player, reveal what they can see
let _p: Option<&Player> = player.get(ent); let _p: Option<&Player> = player.get(ent);