From aca4aae3c1c34caa29eb7276bdd85b867b3d51ae Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 25 Nov 2022 13:17:44 +0000 Subject: [PATCH] dun_render: Remove the use of `LightTableIndex` Replaces the global with an argument. --- Source/engine/render/dun_render.cpp | 16 +++++++++------- Source/engine/render/dun_render.hpp | 7 +++++-- Source/engine/render/scrollrt.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index db1a06834..a8bf57946 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -1142,8 +1142,10 @@ void RenderBlackTileFull(std::uint8_t *dst, int dstPitch) } // namespace -void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, - uint16_t levelPieceId, ArchType archType, bool transparency, bool foliage) +void RenderTile(const Surface &out, Point position, + LevelCelBlock levelCelBlock, uint16_t levelPieceId, + uint8_t lightTableIndex, ArchType archType, + bool transparency, bool foliage) { const TileType tile = levelCelBlock.type(); const uint32_t *mask = GetMask(tile, levelPieceId, archType, transparency, foliage); @@ -1164,25 +1166,25 @@ void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, if (clip.width <= 0 || clip.height <= 0) return; - const std::uint8_t *tbl = &LightTables[256 * LightTableIndex]; + const std::uint8_t *tbl = &LightTables[256 * lightTableIndex]; const auto *pFrameTable = reinterpret_cast(pDungeonCels.get()); const auto *src = reinterpret_cast(&pDungeonCels[pFrameTable[levelCelBlock.frame()]]); std::uint8_t *dst = out.at(static_cast(position.x + clip.left), static_cast(position.y - clip.bottom)); const auto dstPitch = out.pitch(); if (mask == &SolidMask[TILE_HEIGHT - 1]) { - if (LightTableIndex == LightsMax) { + if (lightTableIndex == LightsMax) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); - } else if (LightTableIndex == 0) { + } else if (lightTableIndex == 0) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } else { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } } else { mask -= clip.bottom; - if (LightTableIndex == LightsMax) { + if (lightTableIndex == LightsMax) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); - } else if (LightTableIndex == 0) { + } else if (lightTableIndex == 0) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } else { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); diff --git a/Source/engine/render/dun_render.hpp b/Source/engine/render/dun_render.hpp index 991a316c6..c4fe3f5ed 100644 --- a/Source/engine/render/dun_render.hpp +++ b/Source/engine/render/dun_render.hpp @@ -123,12 +123,15 @@ private: * @param position Target buffer coordinates * @param levelCelBlock The MIN block of the level CEL file. * @param levelPieceId The piece ID (index into SOLData and DPieceMicros). + * @param lightTableIndex The light level to use for rendering (index into LightTables / 256). * @param archType The type of arch to render. * @param transparency Specifies whether transparency is active for the CEL sprite. * @param foliage Specifies whether the tile has foliage. Foliage is extra content that overlaps the previous tile. */ -void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, - uint16_t levelPieceId, ArchType archType, bool transparency, bool foliage); +void RenderTile(const Surface &out, Point position, + LevelCelBlock levelCelBlock, uint16_t levelPieceId, + uint8_t lightTableIndex, ArchType archType, + bool transparency, bool foliage); /** * @brief Render a black 64x31 tile ◆ diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index a67394a46..39239c8f4 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -506,7 +506,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition const LevelCelBlock levelCelBlock { pMap->mt[2 * i] }; if (levelCelBlock.hasValue()) { RenderTile(out, targetBufferPosition, - levelCelBlock, levelPieceId, + levelCelBlock, levelPieceId, LightTableIndex, i == 0 ? ArchType::Left : ArchType::None, transparency, foliage); } @@ -515,7 +515,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition const LevelCelBlock levelCelBlock { pMap->mt[2 * i + 1] }; if (levelCelBlock.hasValue()) { RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, - levelCelBlock, levelPieceId, + levelCelBlock, levelPieceId, LightTableIndex, i == 0 ? ArchType::Right : ArchType::None, transparency, foliage); } @@ -539,7 +539,7 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[0] }; if (levelCelBlock.hasValue()) { RenderTile(out, targetBufferPosition, - levelCelBlock, levelPieceId, ArchType::Left, + levelCelBlock, levelPieceId, LightTableIndex, ArchType::Left, /*transparency=*/false, /*foliage=*/false); } } @@ -547,7 +547,7 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[1] }; if (levelCelBlock.hasValue()) { RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, - levelCelBlock, levelPieceId, ArchType::Right, + levelCelBlock, levelPieceId, LightTableIndex, ArchType::Right, /*transparency=*/false, /*foliage=*/false); } }