Lighting is now in its own class using the new Pathing class. This should allow me to make it more consistent and possibly make Pathing more efficient.

This commit is contained in:
Zed A. Shaw 2024-12-01 17:54:43 -05:00
parent e05335b153
commit 3f7a9cc124
18 changed files with 209 additions and 257 deletions

View file

@ -18,17 +18,17 @@ using namespace components;
using ftxui::Color;
using lighting::LightSource;
void System::lighting(DinkyECS::World &world, Map &game_map, Player &player) {
game_map.reset_light();
void System::lighting(DinkyECS::World &world, Map &game_map, LightRender &light, Player &player) {
light.reset_light();
world.query<Position, LightSource>([&](const auto &ent, auto &position, auto &lightsource) {
game_map.set_light_target(position.location);
light.set_light_target(position.location);
});
game_map.path_light();
light.path_light(game_map.walls());
world.query<Position, LightSource>([&](const auto &ent, auto &position, auto &lightsource) {
game_map.render_light(lightsource, position.location);
light.render_light(lightsource, position.location);
});
}
@ -148,9 +148,7 @@ void System::collision(DinkyECS::World &world, Player &player) {
}
}
void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) {
const auto &lighting = game_map.lighting();
void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) {
world.query<Position, Tile>([&](const auto &ent, auto &pos, auto &tile) {
if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x
&& pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y) {
@ -167,14 +165,13 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas
});
}
void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, size_t view_x, size_t view_y) {
void System::draw_map(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, size_t view_x, size_t view_y) {
const auto& config = world.get_the<MapConfig>();
const auto& player = world.get_the<Player>();
const auto& player_position = world.get<Position>(player.entity);
Point start = game_map.center_camera(player_position.location, view_x, view_y);
auto &walls = game_map.walls();
auto &paths = game_map.paths();
auto &lighting = game_map.lighting();
size_t end_x = std::min(view_x, game_map.width() - start.x);
size_t end_y = std::min(view_y, game_map.height() - start.y);
@ -207,5 +204,5 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv
}
}
System::draw_entities(world, game_map, canvas, start, view_x, view_y);
System::draw_entities(world, game_map, lighting, canvas, start, view_x, view_y);
}