From dc2d97c11280b35c29d9a9308ef912501db1af48 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 21 Apr 2023 00:10:04 +0200 Subject: [PATCH] Split lighting shades from trn tables --- Source/engine/load_pcx.cpp | 2 +- Source/engine/render/clx_render.hpp | 4 ++-- Source/engine/render/dun_render.cpp | 2 +- Source/engine/render/dun_render.hpp | 2 +- Source/engine/trn.cpp | 6 +++--- Source/lighting.cpp | 24 +++++++++++------------- Source/lighting.h | 9 ++++++--- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Source/engine/load_pcx.cpp b/Source/engine/load_pcx.cpp index 95ecd4024..741c99616 100644 --- a/Source/engine/load_pcx.cpp +++ b/Source/engine/load_pcx.cpp @@ -45,7 +45,7 @@ OptionalOwnedClxSpriteList LoadPcxSpriteList(const char *filename, int numFrames if (outPalette != nullptr) { std::memcpy(pathEnd - 3, "pal", 3); std::array palette; - LoadFileInMem(path, &palette[0], palette.size()); + LoadFileInMem(path, palette); for (unsigned i = 0; i < 256; i++) { outPalette[i].r = palette[i * 3]; outPalette[i].g = palette[i * 3 + 1]; diff --git a/Source/engine/render/clx_render.hpp b/Source/engine/render/clx_render.hpp index 3f3293a18..4a8f06416 100644 --- a/Source/engine/render/clx_render.hpp +++ b/Source/engine/render/clx_render.hpp @@ -94,7 +94,7 @@ extern int LightTableIndex; inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx) { if (LightTableIndex != 0) - ClxDrawTRN(out, position, clx, &LightTables[LightTableIndex * 256]); + ClxDrawTRN(out, position, clx, LightTables[LightTableIndex].data()); else ClxDraw(out, position, clx); } @@ -107,7 +107,7 @@ inline void ClxDrawLight(const Surface &out, Point position, ClxSprite clx) */ inline void ClxDrawLightBlended(const Surface &out, Point position, ClxSprite clx) { - ClxDrawBlendedTRN(out, position, clx, &LightTables[LightTableIndex * 256]); + ClxDrawBlendedTRN(out, position, clx, LightTables[LightTableIndex].data()); } /** diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index 47121ed08..9845039d1 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -1143,7 +1143,7 @@ void RenderTile(const Surface &out, Point position, if (clip.width <= 0 || clip.height <= 0) return; - const uint8_t *tbl = &LightTables[256 * lightTableIndex]; + const uint8_t *tbl = LightTables[LightTableIndex].data(); const auto *pFrameTable = reinterpret_cast(pDungeonCels.get()); const auto *src = reinterpret_cast(&pDungeonCels[SDL_SwapLE32(pFrameTable[levelCelBlock.frame()])]); uint8_t *dst = out.at(static_cast(position.x + clip.left), static_cast(position.y - clip.bottom)); diff --git a/Source/engine/render/dun_render.hpp b/Source/engine/render/dun_render.hpp index 865476f41..f5859885f 100644 --- a/Source/engine/render/dun_render.hpp +++ b/Source/engine/render/dun_render.hpp @@ -262,7 +262,7 @@ string_view MaskTypeToString(MaskType maskType); * @param position Target buffer coordinates * @param levelCelBlock The MIN block of the level CEL file. * @param maskType The mask to use, - * @param lightTableIndex The light level to use for rendering (index into LightTables / 256). + * @param lightTableIndex The light level to use for rendering (index into LightTables). */ void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, MaskType maskType, uint8_t lightTableIndex); diff --git a/Source/engine/trn.cpp b/Source/engine/trn.cpp index c6f6b0538..5dd38cc24 100644 --- a/Source/engine/trn.cpp +++ b/Source/engine/trn.cpp @@ -12,17 +12,17 @@ namespace devilution { uint8_t *GetInfravisionTRN() { - return &LightTables[16 * 256]; + return InfravisionTable.data(); } uint8_t *GetStoneTRN() { - return &LightTables[17 * 256]; + return StoneTable.data(); } uint8_t *GetPauseTRN() { - return &LightTables[18 * 256]; + return PauseTable.data(); } std::optional> GetClassTRN(Player &player) diff --git a/Source/lighting.cpp b/Source/lighting.cpp index ac68b9145..f11ff0165 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -20,7 +20,10 @@ int VisionId; Light Lights[MAXLIGHTS]; uint8_t ActiveLights[MAXLIGHTS]; int ActiveLightCount; -std::array LightTables; +std::array, NumLightingLevels> LightTables; +std::array InfravisionTable; +std::array StoneTable; +std::array PauseTable; bool DisableLighting; bool UpdateLighting; @@ -336,7 +339,7 @@ void DoVision(Point position, int radius, MapExplorationType doAutomap, bool vis void MakeLightTable() { - uint8_t *tbl = LightTables.data(); + uint8_t *tbl = LightTables[0].data(); int shade = 0; int lights = 15; @@ -396,7 +399,7 @@ void MakeLightTable() if (leveltype == DTYPE_HELL) { uint8_t blood[16]; - tbl = LightTables.data(); + tbl = LightTables[0].data(); for (int i = 0; i < lights; i++) { int l1 = lights - i; int l2 = l1; @@ -436,7 +439,7 @@ void MakeLightTable() tbl += 224; } if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) { - tbl = LightTables.data(); + tbl = LightTables[0].data(); for (int i = 0; i < lights; i++) { *tbl++ = 0; for (int j = 1; j < 16; j++) @@ -449,14 +452,9 @@ void MakeLightTable() tbl += 240; } - LoadFileInMem("plrgfx\\infra.trn", tbl, 256); - tbl += 256; - - LoadFileInMem("plrgfx\\stone.trn", tbl, 256); - tbl += 256; - - LoadFileInMem("gendata\\pause.trn", tbl, 256); - tbl += 256; + LoadFileInMem("plrgfx\\infra.trn", InfravisionTable); + LoadFileInMem("plrgfx\\stone.trn", StoneTable); + LoadFileInMem("gendata\\pause.trn", PauseTable); for (int j = 0; j < 16; j++) { for (int i = 0; i < 128; i++) { @@ -788,7 +786,7 @@ void lighting_color_cycling() return; } - uint8_t *tbl = LightTables.data(); + uint8_t *tbl = LightTables[0].data(); for (int j = 0; j < 16; j++) { tbl++; diff --git a/Source/lighting.h b/Source/lighting.h index 27ae9b39e..b4ff6ac57 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -21,8 +21,8 @@ namespace devilution { #define MAXLIGHTS 32 #define MAXVISION 32 -/** 16 light levels + infravision + stone curse + red for pause/death screen */ -#define LIGHTSIZE (19 * 256) +/** @brief Number of supported light levels */ +constexpr size_t NumLightingLevels = 16; #define NO_LIGHT -1 struct LightPosition { @@ -50,7 +50,10 @@ extern Light Lights[MAXLIGHTS]; extern uint8_t ActiveLights[MAXLIGHTS]; extern int ActiveLightCount; constexpr char LightsMax = 15; -extern std::array LightTables; +extern std::array, NumLightingLevels> LightTables; +extern std::array InfravisionTable; +extern std::array StoneTable; +extern std::array PauseTable; extern bool DisableLighting; extern bool UpdateLighting;