diff --git a/gui/map_view.cpp b/gui/map_view.cpp index 64c78ab..fcac5e6 100644 --- a/gui/map_view.cpp +++ b/gui/map_view.cpp @@ -61,7 +61,7 @@ namespace gui { void MapViewUI::render(sf::RenderWindow &window, int compass_dir) { $gui.render(window); System::draw_map($level, $map_tiles, $entity_map); - System::render_map($level, $map_tiles, $entity_map, *$map_render, compass_dir, $player_display); + System::render_map($map_tiles, $entity_map, *$map_render, compass_dir, $player_display); $map_sprite.setTexture($map_render->getTexture(), true); window.draw($map_sprite); // $gui.debug_layout(window); diff --git a/lights.cpp b/lights.cpp index 9fcf6df..ac797fa 100644 --- a/lights.cpp +++ b/lights.cpp @@ -50,7 +50,6 @@ namespace lighting { if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) { $lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y); } - $fow[it.y][it.x] = $lightmap[it.y][it.x]; } } } @@ -74,6 +73,14 @@ namespace lighting { $paths.set_target(at, value); } + void LightRender::update_fow(Point at, LightSource source) { + for(matrix::circle it{$lightmap, at, source.radius}; it.next();) { + for(auto x = it.left; x < it.right; x++) { + $fow[it.y][x] = $lightmap[it.y][x]; + } + } + } + void LightRender::path_light(Matrix &walls) { $paths.compute_paths(walls); } diff --git a/lights.hpp b/lights.hpp index d5bbfa6..ef0005b 100644 --- a/lights.hpp +++ b/lights.hpp @@ -33,8 +33,7 @@ namespace lighting { int light_level(int level, float distance, size_t x, size_t y); void render_light(LightSource source, Point at); void render_square_light(LightSource source, Point at, PointList &has_light); - void render_compass_light(LightSource source, Point at, PointList &has_light); - void render_circle_light(LightSource source, Point at, PointList &has_light); + void update_fow(Point player_pos, LightSource source); Matrix &lighting() { return $lightmap; } Matrix &paths() { return $paths.paths(); } }; diff --git a/systems.cpp b/systems.cpp index 9449851..eedc832 100644 --- a/systems.cpp +++ b/systems.cpp @@ -36,9 +36,14 @@ void System::lighting(GameLevel &level) { light.path_light(map.walls()); - world.query([&](auto, auto &position, auto &lightsource) { + world.query([&](auto ent, auto &position, auto &lightsource) { light.render_light(lightsource, position.location); + + if(ent == level.player) { + light.update_fow(position.location, lightsource); + } }); + } void System::generate_paths(GameLevel &level) { @@ -572,15 +577,12 @@ void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) { }); } -void System::render_map(GameLevel& level, Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) { +void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) { sf::Vector2i tile_sprite_dim{MAP_TILE_DIM,MAP_TILE_DIM}; unsigned int width = matrix::width(tiles); unsigned int height = matrix::height(tiles); sf::Vector2u dim{width * tile_sprite_dim.x, height * tile_sprite_dim.y}; auto render_size = render.getSize(); - Matrix &fow = level.lights->$fow; - (void)level; - (void)fow; if(render_size.x != width || render_size.y != height) { bool worked = render.resize(dim); diff --git a/systems.hpp b/systems.hpp index 3a95793..727d848 100644 --- a/systems.hpp +++ b/systems.hpp @@ -40,5 +40,5 @@ namespace System { bool inventory_occupied(GameLevel& level, Entity container_id, const std::string& name); void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map); - void render_map(GameLevel& level, Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display); + void render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display); } diff --git a/tests/map.cpp b/tests/map.cpp index 04d9dcc..c807c49 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -101,7 +101,7 @@ TEST_CASE("map image test", "[map-sprite]") { player_pos.location.x = it.x; player_pos.location.y = it.y; System::draw_map(level, map_tiles, entity_map); - System::render_map(level, map_tiles, entity_map, *render, 2, player_display); + System::render_map(map_tiles, entity_map, *render, 2, player_display); #ifdef TEST_RENDER // confirm we get two different maps