From 547be19e68a4f1e72e903b688bbdf982baa1fa5f Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 15 Dec 2024 19:54:16 -0500 Subject: [PATCH] Lighting now uses the new box iterator, although it'll be replaced soon by the flood or random iterator. --- lights.cpp | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/lights.cpp b/lights.cpp index d5c3e68..769fceb 100644 --- a/lights.cpp +++ b/lights.cpp @@ -10,34 +10,19 @@ namespace lighting { clear_light_target(at); vector has_light; - matrix::in_box it{$lightmap, at.x, at.y, (size_t)source.distance}; - light_box(source, at, min, max); - dbc::check(it.x+1 == min.x, "box min x different"); - dbc::check(it.y == min.y, "box min y different"); - dbc::check(it.right == max.x + 1, "box max.x/right different"); - dbc::check(it.bottom == max.y + 1, "box max.y/bottom different"); - - while(it.next()) { - auto &light_row = $lightmap[it.y]; - auto &path_row = $paths.$paths[it.y]; - - if(path_row[it.x] != WALL_PATH_LIMIT) { - light_row[it.x] = light_level(source.strength, it.x, it.y); + for(matrix::in_box it{$lightmap, at.x, at.y, (size_t)source.distance}; it.next();) { + if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) { + $lightmap[it.y][it.x] = light_level(source.strength, it.x, it.y); has_light.push_back({it.x, it.y}); } } const int wall_light = source.strength + WALL_LIGHT_LEVEL; for(auto point : has_light) { - for(int j = -1;point.y+j >= 0 && j <= 1 && point.y+j < $height; j++) { - auto &path_row = $paths.$paths[point.y+j]; - auto &light_row = $lightmap[point.y+j]; - - for(int i = -1; point.x+i >= 0 && i <= 1 && point.x+i < $width; i++) { - if(path_row[point.x+i] == WALL_PATH_LIMIT) { - light_row[point.x+i] = light_level(wall_light, point.x, point.y); - } + for(matrix::in_box it{$lightmap, point.x, point.y, 1}; it.next();) { + if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) { + $lightmap[it.y][it.x] = light_level(wall_light, point.x, point.y); } } } @@ -68,12 +53,4 @@ namespace lighting { void LightRender::path_light(Matrix &walls) { $paths.compute_paths(walls); } - - void LightRender::light_box(LightSource source, Point from, Point &min_out, Point &max_out) { - using std::min, std::max; - min_out.x = max(int(from.x), source.distance) - source.distance; - max_out.x = min(from.x + source.distance, $width - 1); - min_out.y = max(int(from.y), source.distance) - source.distance; - max_out.y = min(from.y + source.distance, $height - 1); - } }