Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Source/engine/render/light_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,36 @@

std::vector<uint8_t> LightmapBuffer;

void RenderFullTile(Point position, uint8_t lightLevel, uint8_t *lightmap, uint16_t pitch)
{
uint8_t *top = lightmap + (position.y + 1) * pitch + position.x - TILE_WIDTH / 2;

Check warning on line 23 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:23:17 [bugprone-implicit-widening-of-multiplication-result]

result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t'
uint8_t *bottom = top + (TILE_HEIGHT - 2) * pitch;

Check warning on line 24 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:24:20 [bugprone-implicit-widening-of-multiplication-result]

result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t'
for (int y = 0, w = 4; y < TILE_HEIGHT / 2 - 1; y++, w += 4) {
int x = (TILE_WIDTH - w) / 2;

Check warning on line 26 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:26:3 [misc-const-correctness]

variable 'x' of type 'int' can be declared 'const'
memset(top + x, lightLevel, w);
memset(bottom + x, lightLevel, w);
top += pitch;
bottom -= pitch;
}
memset(top, lightLevel, TILE_WIDTH);
}

// Half-space method for drawing triangles
// Points must be provided using counter-clockwise rotation
// https://web.archive.org/web/20050408192410/http://sw-shader.sourceforge.net/rasterizer.html
void RenderTriangle(Point p1, Point p2, Point p3, uint8_t lightLevel, uint8_t *lightmap, uint16_t pitch, uint16_t scanLines)
{
// Deltas (points are already 28.4 fixed-point)
int dx12 = p1.x - p2.x;

Check warning on line 41 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:41:2 [misc-const-correctness]

variable 'dx12' of type 'int' can be declared 'const'
int dx23 = p2.x - p3.x;

Check warning on line 42 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:42:2 [misc-const-correctness]

variable 'dx23' of type 'int' can be declared 'const'
int dx31 = p3.x - p1.x;

Check warning on line 43 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:43:2 [misc-const-correctness]

variable 'dx31' of type 'int' can be declared 'const'

int dy12 = p1.y - p2.y;

Check warning on line 45 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:45:2 [misc-const-correctness]

variable 'dy12' of type 'int' can be declared 'const'
int dy23 = p2.y - p3.y;

Check warning on line 46 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:46:2 [misc-const-correctness]

variable 'dy23' of type 'int' can be declared 'const'
int dy31 = p3.y - p1.y;

Check warning on line 47 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:47:2 [misc-const-correctness]

variable 'dy31' of type 'int' can be declared 'const'

// 24.8 fixed-point deltas
int fdx12 = dx12 << 4;

Check warning on line 50 in Source/engine/render/light_render.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/render/light_render.cpp:50:2 [misc-const-correctness]

variable 'fdx12' of type 'int' can be declared 'const'
int fdx23 = dx23 << 4;
int fdx31 = dx31 << 4;

Expand Down Expand Up @@ -367,8 +381,13 @@
// Fill in the whole cell
// All four tiles in the quad are lit
case 15: {
RenderTriangle(fpCenter0, fpCenter2, fpCenter1, lightLevel, lightmap, pitch, scanLines);
RenderTriangle(fpCenter0, fpCenter3, fpCenter2, lightLevel, lightmap, pitch, scanLines);
if (center3.x < 0 || center1.x >= pitch || center0.y < 0 || center2.y >= scanLines) {
RenderTriangle(fpCenter0, fpCenter2, fpCenter1, lightLevel, lightmap, pitch, scanLines);
RenderTriangle(fpCenter0, fpCenter3, fpCenter2, lightLevel, lightmap, pitch, scanLines);
} else {
// Optimized rendering path if full tile is visible
RenderFullTile(center0, lightLevel, lightmap, pitch);
}
} break;
}
}
Expand Down