Fixed worldgen to only use tiles without collision in filling rooms, then a couple more changes to lighting so that if the light is <= 1 it just assumes the base light strength which ends up looking nicer and more like the kind of light I want.

This commit is contained in:
Zed A. Shaw 2024-12-29 04:53:59 -05:00
parent 59bbae0af0
commit 28d19d80a2
8 changed files with 36 additions and 29 deletions

View file

@ -14,6 +14,13 @@ namespace lighting {
}
}
/*
* NOTE: This really doesn't need to calculate light all the time. It doesn't
* change around the light source until the lightsource is changed, so the
* light levels could be placed in a Matrix inside LightSource, calculated once
* and then simply "applied" to the area where the entity is located. The only
* thing that would need to be calculated each time is the walls.
*/
void LightRender::render_light(LightSource source, Point at) {
Point min, max;
clear_light_target(at);
@ -21,22 +28,18 @@ namespace lighting {
render_square_light(source, at, has_light);
const int wall_light = source.strength + WALL_LIGHT_LEVEL;
for(auto point : has_light) {
for(matrix::compass it{$lightmap, point.x, point.y}; it.next();) {
if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) {
// BUG: include the distance in the list of walls to light
// so that they will be closer to the light level at that point
$lightmap[it.y][it.x] = light_level(wall_light, 1.0f, point.x, point.y);
$lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y);
}
}
}
}
int LightRender::light_level(int strength, float distance, size_t x, size_t y) {
int new_level = distance <= 1.0f ? strength : strength / sqrt(distance);
int cur_level = $lightmap[y][x];
int new_level = strength / sqrt(distance + 0.6f);
return cur_level < new_level ? new_level : cur_level;
}