Fixed the lightmap bug where some tiles would stay too dark
Introduced a lightmap debug mode when doing this. It's super laggy. Use with care.
This commit is contained in:
parent
b2b0103b4f
commit
9a887ab964
|
@ -153,8 +153,8 @@ set_light_for_tile(RoomMatrix *matrix, int x, int y)
|
||||||
for (j = y_min; j <= y_max; ++j) {
|
for (j = y_min; j <= y_max; ++j) {
|
||||||
lightval = matrix->spaces[i][j].light;
|
lightval = matrix->spaces[i][j].light;
|
||||||
distance_modifier = abs(x-i) == abs(y-j) ?
|
distance_modifier = abs(x-i) == abs(y-j) ?
|
||||||
abs(x-i) + 1 : max(abs(x-i), abs(y-j));
|
min(abs(x-i) + 1, 5) : max(abs(x-i), abs(y-j));
|
||||||
lightval += 255 - (distance_modifier * 50);
|
lightval += (255 - (distance_modifier * 50));
|
||||||
lightval = min(255, lightval);
|
lightval = min(255, lightval);
|
||||||
lightval = max(0, lightval);
|
lightval = max(0, lightval);
|
||||||
matrix->spaces[i][j].light = lightval;
|
matrix->spaces[i][j].light = lightval;
|
||||||
|
@ -189,6 +189,21 @@ roommatrix_render_mouse_square(RoomMatrix *matrix, Camera *cam)
|
||||||
SDL_RenderFillRect(cam->renderer, &box);
|
SDL_RenderFillRect(cam->renderer, &box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LIGHTMAPDEBUG
|
||||||
|
static Texture *
|
||||||
|
create_light_texture(int light, Camera *cam)
|
||||||
|
{
|
||||||
|
static SDL_Color color = { 255, 255, 0, 0 };
|
||||||
|
|
||||||
|
char buffer[4];
|
||||||
|
Texture *t = texture_create();
|
||||||
|
texture_load_font(t, "assets/GUI/SDS_8x8.ttf", 8);
|
||||||
|
m_sprintf(buffer, 4, "%d", light);
|
||||||
|
texture_load_from_text(t, buffer, color, cam->renderer);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
#endif // LIGHTMAPDEBUG
|
||||||
|
|
||||||
void
|
void
|
||||||
roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
|
roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
|
||||||
{
|
{
|
||||||
|
@ -196,11 +211,7 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
|
||||||
|
|
||||||
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
|
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
|
||||||
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
|
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
|
||||||
light = 245 - matrix->spaces[i][j].light;
|
light = max(245 - matrix->spaces[i][j].light, 0);
|
||||||
if (light < 0)
|
|
||||||
light = 0;
|
|
||||||
else if (light > 245)
|
|
||||||
light = 245;
|
|
||||||
|
|
||||||
SDL_Rect box = (SDL_Rect) {
|
SDL_Rect box = (SDL_Rect) {
|
||||||
i*TILE_DIMENSION,
|
i*TILE_DIMENSION,
|
||||||
|
@ -212,6 +223,13 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
|
||||||
SDL_SetRenderDrawColor(cam->renderer,
|
SDL_SetRenderDrawColor(cam->renderer,
|
||||||
0, 0, 0, light);
|
0, 0, 0, light);
|
||||||
SDL_RenderFillRect(cam->renderer, &box);
|
SDL_RenderFillRect(cam->renderer, &box);
|
||||||
|
|
||||||
|
#ifdef LIGHTMAPDEBUG
|
||||||
|
Texture *t = create_light_texture(light, cam);
|
||||||
|
Position p = { box.x+3, box.y+3 };
|
||||||
|
texture_render(t, &p, cam);
|
||||||
|
texture_destroy(t);
|
||||||
|
#endif // LIGHTMAPDEBUG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue