This implements base ambient lighting for tiles which helps with tiles like lava and ceiling lights.

This commit is contained in:
Zed A. Shaw 2025-05-29 12:34:25 -04:00
parent 74a1801069
commit 3dc70c3af6
11 changed files with 48 additions and 17 deletions

View file

@ -1,10 +1,27 @@
#include "lights.hpp"
#include "constants.hpp"
#include "textures.hpp"
#include <vector>
using std::vector;
namespace lighting {
LightRender::LightRender(Matrix& tiles) :
$width(matrix::width(tiles)),
$height(matrix::height(tiles)),
$lightmap(matrix::make($width, $height)),
$ambient(matrix::make($width, $height)),
$paths($width, $height)
{
auto& tile_ambient = textures::get_ambient_light();
for(matrix::each_cell it{tiles}; it.next();) {
size_t tile_id = tiles[it.y][it.x];
$ambient[it.y][it.x] = MIN + tile_ambient[tile_id];
}
}
void LightRender::render_square_light(LightSource source, Point at, PointList &has_light) {
for(matrix::box it{$lightmap, at.x, at.y, (size_t)floor(source.radius)}; it.next();) {
if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) {
@ -44,7 +61,7 @@ namespace lighting {
}
void LightRender::reset_light() {
matrix::assign($lightmap, lighting::MIN);
$lightmap = $ambient;
}
void LightRender::clear_light_target(const Point &at) {