diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index 5a12bc8d3..3bd1856de 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -284,12 +284,12 @@ DVL_ALWAYS_INLINE Clip CalculateClip(int_fast16_t x, int_fast16_t y, int_fast16_ DVL_ALWAYS_INLINE bool IsFullyDark(const uint8_t *DVL_RESTRICT tbl) { - return tbl == LightTables[LightsMax].data(); + return tbl == FullyDarkLightTable; } DVL_ALWAYS_INLINE bool IsFullyLit(const uint8_t *DVL_RESTRICT tbl) { - return tbl == LightTables[0].data(); + return tbl == FullyLitLightTable; } template diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 0c914a6e4..0b06c81e7 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -24,6 +24,8 @@ Light Lights[MAXLIGHTS]; std::array ActiveLights; int ActiveLightCount; std::array, NumLightingLevels> LightTables; +uint8_t *FullyLitLightTable = nullptr; +uint8_t *FullyDarkLightTable = nullptr; std::array InfravisionTable; std::array StoneTable; std::array PauseTable; @@ -345,6 +347,8 @@ void MakeLightTable() } LightTables[15] = {}; // Make last shade pitch black + FullyLitLightTable = LightTables[0].data(); + FullyDarkLightTable = LightTables[LightsMax].data(); if (leveltype == DTYPE_HELL) { // Blood wall lighting @@ -361,14 +365,19 @@ void MakeLightTable() lightTable[idx] = color; } } + FullyLitLightTable = nullptr; // A color map is used for the ceiling animation, so even fully lit tiles have a color map } else if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) { // Make the lava fully bright for (auto &lightTable : LightTables) std::iota(lightTable.begin(), lightTable.begin() + 16, uint8_t { 0 }); LightTables[15][0] = 0; std::fill_n(LightTables[15].begin() + 1, 15, 1); + FullyDarkLightTable = nullptr; // Tiles in Hellfire levels are never completely black } + assert((FullyLitLightTable != nullptr) == (LightTables[0][0] == 0 && std::adjacent_find(LightTables[0].begin(), LightTables[0].end() - 1, [](auto x, auto y) { return (x + 1) != y; }) == LightTables[0].end() - 1)); + assert((FullyDarkLightTable != nullptr) == (std::all_of(LightTables[LightsMax].begin(), LightTables[LightsMax].end(), [](auto x) { return x == 0; }))); + LoadFileInMem("plrgfx\\infra.trn", InfravisionTable); LoadFileInMem("plrgfx\\stone.trn", StoneTable); LoadFileInMem("gendata\\pause.trn", PauseTable); diff --git a/Source/lighting.h b/Source/lighting.h index f4404a067..dd1fc72a4 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -49,6 +49,10 @@ extern std::array ActiveLights; extern int ActiveLightCount; constexpr char LightsMax = 15; extern std::array, NumLightingLevels> LightTables; +/** @brief Contains a pointer to a light table that is fully lit (no color mapping is required). Can be null in hell. */ +extern uint8_t *FullyLitLightTable; +/** @brief Contains a pointer to a light table that is fully dark (every color result to 0/black). Can be null in hellfire levels. */ +extern uint8_t *FullyDarkLightTable; extern std::array InfravisionTable; extern std::array StoneTable; extern std::array PauseTable;