Skip to content

Commit

Permalink
Make IsFullyDark/IsFullyLit respect hell and hellfire levels
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron authored and AJenbo committed Jun 25, 2024
1 parent 56044b7 commit 4b74249
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/engine/render/dun_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <LightType Light, bool Transparent>
Expand Down
9 changes: 9 additions & 0 deletions Source/lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Light Lights[MAXLIGHTS];
std::array<uint8_t, MAXLIGHTS> ActiveLights;
int ActiveLightCount;
std::array<std::array<uint8_t, 256>, NumLightingLevels> LightTables;
uint8_t *FullyLitLightTable = nullptr;
uint8_t *FullyDarkLightTable = nullptr;
std::array<uint8_t, 256> InfravisionTable;
std::array<uint8_t, 256> StoneTable;
std::array<uint8_t, 256> PauseTable;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Source/lighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ extern std::array<uint8_t, MAXLIGHTS> ActiveLights;
extern int ActiveLightCount;
constexpr char LightsMax = 15;
extern std::array<std::array<uint8_t, 256>, 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<uint8_t, 256> InfravisionTable;
extern std::array<uint8_t, 256> StoneTable;
extern std::array<uint8_t, 256> PauseTable;
Expand Down

0 comments on commit 4b74249

Please sign in to comment.