Lighting now uses the new box iterator, although it'll be replaced soon by the flood or random iterator.

main
Zed A. Shaw 6 days ago
parent 70cd963e5c
commit 547be19e68
  1. 35
      lights.cpp

@ -10,34 +10,19 @@ namespace lighting {
clear_light_target(at);
vector<Point> 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);
}
}

Loading…
Cancel
Save