Better lighting and a circle algorithm that works more reliably.
This commit is contained in:
parent
03fe9b3d01
commit
35f2defc11
9 changed files with 97 additions and 87 deletions
40
lights.cpp
40
lights.cpp
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue