Better lighting and a circle algorithm that works more reliably.

This commit is contained in:
Zed A. Shaw 2024-12-25 00:27:45 -05:00
parent 03fe9b3d01
commit 35f2defc11
9 changed files with 97 additions and 87 deletions

View file

@ -5,18 +5,50 @@
using std::vector;
namespace lighting {
void LightRender::render_light(LightSource source, Point at) {
Point min, max;
clear_light_target(at);
vector<Point> has_light;
void LightRender::render_circle_light(LightSource source, Point at, PointList &has_light) {
for(matrix::circle it{at, source.distance + 1}; it.next();) {
for(int x = it.left; x < it.right; x++) {
if(matrix::inbounds($paths.$paths, x, it.y) &&
$paths.$paths[it.y][x] != WALL_PATH_LIMIT)
{
$lightmap[it.y][x] = light_level(source.strength, x, it.y);
has_light.push_back({(size_t)x, (size_t)it.y});
}
}
}
}
void LightRender::render_compass_light(LightSource source, Point at, PointList &has_light) {
for(matrix::compass it{$lightmap, at.x, at.y}; 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});
}
}
}
void LightRender::render_square_light(LightSource source, Point at, PointList &has_light) {
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});
}
}
}
void LightRender::render_light(LightSource source, Point at) {
Point min, max;
clear_light_target(at);
PointList has_light;
if(source.distance == 0) {
render_compass_light(source, at, has_light);
} else if(source.distance == 1) {
render_square_light(source, at, has_light);
} else {
render_circle_light(source, at, has_light);
}
const int wall_light = source.strength + WALL_LIGHT_LEVEL;
for(auto point : has_light) {