Browse Source

Clean up: MakeLightTable() (#7089)

pull/7100/head
Eric Robinson 2 years ago committed by GitHub
parent
commit
692365fe8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 27
      Source/lighting.cpp

27
Source/lighting.cpp

@ -322,8 +322,8 @@ void MakeLightTable()
{
// Generate 16 gradually darker translation tables for doing lighting
uint8_t shade = 0;
constexpr uint8_t black = 0;
constexpr uint8_t white = 255;
constexpr uint8_t Black = 0;
constexpr uint8_t White = 255;
for (auto &lightTable : LightTables) {
uint8_t colorIndex = 0;
for (uint8_t steps : { 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16 }) {
@ -331,13 +331,13 @@ void MakeLightTable()
const uint8_t shadeStart = colorIndex;
const uint8_t shadeEnd = shadeStart + steps - 1;
for (uint8_t step = 0; step < steps; step++) {
if (colorIndex == black) {
lightTable[colorIndex++] = black;
if (colorIndex == Black) {
lightTable[colorIndex++] = Black;
continue;
}
int color = shadeStart + step + shading;
if (color > shadeEnd || color == white)
color = black;
if (color > shadeEnd || color == White)
color = Black;
lightTable[colorIndex++] = color;
}
}
@ -351,12 +351,14 @@ void MakeLightTable()
const auto shades = static_cast<int>(LightTables.size() - 1);
for (int i = 0; i < shades; i++) {
auto &lightTable = LightTables[i];
constexpr int range = 16;
for (int j = 0; j < range; j++) {
uint8_t color = ((range - 1) << 4) / shades * (shades - i) / range * (j + 1);
constexpr int Range = 16;
for (int j = 0; j < Range; j++) {
uint8_t color = ((Range - 1) << 4) / shades * (shades - i) / Range * (j + 1);
color = 1 + (color >> 4);
lightTable[j + 1] = color;
lightTable[31 - j] = color;
int idx = j + 1;
lightTable[idx] = color;
idx = 31 - j;
lightTable[idx] = color;
}
}
} else if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) {
@ -391,7 +393,8 @@ void MakeLightTable()
// Leaner falloff
scaled = factor * maxDarkness;
}
LightFalloffs[radius][distance] = static_cast<uint8_t>(scaled + 0.5F); // round up
scaled += 0.5F; // Round up
LightFalloffs[radius][distance] = static_cast<uint8_t>(scaled);
}
}
}

Loading…
Cancel
Save