From 1bab0251e22be81efbe706548ba2cceb05591487 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 26 Aug 2024 11:07:19 +0100 Subject: [PATCH] Minor rendering cleanups Extracted from various open PRs, for ease of reviewing. --- Source/engine/render/dun_render.cpp | 6 +++--- Source/engine/render/scrollrt.cpp | 33 ++++++++++++++++------------- Source/utils/attributes.h | 8 +++++++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index fc9c5af4212..fd28b414f70 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -443,7 +443,7 @@ struct DiamondClipY { }; template -DVL_ALWAYS_INLINE DiamondClipY CalculateDiamondClipY(const Clip &clip) +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT DiamondClipY CalculateDiamondClipY(const Clip &clip) { DiamondClipY result; if (clip.bottom > LowerHeight) { @@ -462,12 +462,12 @@ DVL_ALWAYS_INLINE DiamondClipY CalculateDiamondClipY(const Clip &clip) return result; } -DVL_ALWAYS_INLINE std::size_t CalculateTriangleSourceSkipLowerBottom(int_fast16_t numLines) +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT std::size_t CalculateTriangleSourceSkipLowerBottom(int_fast16_t numLines) { return XStep * numLines * (numLines + 1) / 2; } -DVL_ALWAYS_INLINE std::size_t CalculateTriangleSourceSkipUpperBottom(int_fast16_t numLines) +DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT std::size_t CalculateTriangleSourceSkipUpperBottom(int_fast16_t numLines) { return 2 * TriangleUpperHeight * numLines - numLines * (numLines - 1); } diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index cd4e719676f..ef009fd31dd 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -18,7 +18,9 @@ #include "diablo_msg.hpp" #include "doom.h" #include "engine/backbuffer_state.hpp" +#include "engine/displacement.hpp" #include "engine/dx.h" +#include "engine/point.hpp" #include "engine/render/clx_render.hpp" #include "engine/render/dun_render.hpp" #include "engine/render/text_render.hpp" @@ -29,6 +31,7 @@ #include "hwcursor.hpp" #include "init.h" #include "inv.h" +#include "levels/dun_tile.hpp" #include "levels/gendung.h" #include "lighting.h" #include "lua/lua.hpp" @@ -76,6 +79,8 @@ bool frameflag; namespace { +constexpr auto RightFrameDisplacement = Displacement { DunFrameWidth, 0 }; + [[nodiscard]] DVL_ALWAYS_INLINE bool IsFloor(Point tilePosition) { return !TileHasAny(tilePosition, TileProperties::Solid); @@ -542,7 +547,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition if (levelCelBlock.hasValue()) { if (transparency || !foliage || levelCelBlock.type() == TileType::TransparentSquare) { if (maskType != MaskType::RightFoliage || tileType == TileType::TransparentSquare) { - RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, + RenderTile(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, maskType, tbl); } } @@ -563,7 +568,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition { const LevelCelBlock levelCelBlock { pMap->mt[i + 1] }; if (levelCelBlock.hasValue()) { - RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, + RenderTile(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, transparency ? MaskType::Transparent : MaskType::Solid, tbl); } @@ -599,7 +604,7 @@ void DrawFloorTile(const Surface &out, Point tilePosition, Point targetBufferPos { const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[1] }; if (levelCelBlock.hasValue()) { - RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, + RenderTile(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, MaskType::Solid, tbl); } } @@ -844,16 +849,14 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPosition, int rows, int columns) { for (int i = 0; i < rows; i++) { - for (int j = 0; j < columns; j++) { - if (InDungeonBounds(tilePosition)) { - if (IsFloor(tilePosition)) { - DrawFloorTile(out, tilePosition, targetBufferPosition); - } - } else { + for (int j = 0; j < columns; j++, tilePosition += Direction::East, targetBufferPosition.x += TILE_WIDTH) { + if (!InDungeonBounds(tilePosition)) { world_draw_black_tile(out, targetBufferPosition.x, targetBufferPosition.y); + continue; + } + if (IsFloor(tilePosition)) { + DrawFloorTile(out, tilePosition, targetBufferPosition); } - tilePosition += Direction::East; - targetBufferPosition.x += TILE_WIDTH; } // Return to start of row tilePosition += Displacement(Direction::West) * columns; @@ -874,7 +877,7 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio } /** - * @brief Render a row of tile + * @brief Renders the floor tiles * @param out Output buffer * @param tilePosition dPiece coordinates * @param targetBufferPosition Buffer coordinates @@ -993,7 +996,7 @@ void Zoom(const Surface &out) Displacement tileOffset; Displacement tileShift; -int tileColums; +int tileColumns; int tileRows; void CalcFirstTilePosition(Point &position, Displacement &offset) @@ -1054,7 +1057,7 @@ void DrawGame(const Surface &fullOut, Point position, Displacement offset) ? fullOut.subregionY(0, gnViewportHeight) : fullOut.subregionY(0, (gnViewportHeight + 1) / 2); - int columns = tileColums; + int columns = tileColumns; int rows = tileRows; // Skip rendering parts covered by the panels @@ -1517,7 +1520,7 @@ void CalcViewportGeometry() const int viewportHeight = GetViewportHeight() / zoomFactor; const Point renderStart = startPosition - Displacement { TILE_WIDTH / 2, TILE_HEIGHT / 2 }; tileRows = (viewportHeight - renderStart.y + TILE_HEIGHT / 2 - 1) / (TILE_HEIGHT / 2); - tileColums = (screenWidth - renderStart.x + TILE_WIDTH - 1) / TILE_WIDTH; + tileColumns = (screenWidth - renderStart.x + TILE_WIDTH - 1) / TILE_WIDTH; } Point GetScreenPosition(Point tile) diff --git a/Source/utils/attributes.h b/Source/utils/attributes.h index 2f40a9bcb6e..b14787c019a 100644 --- a/Source/utils/attributes.h +++ b/Source/utils/attributes.h @@ -32,6 +32,14 @@ #define DVL_ALWAYS_INLINE inline #endif +#if DVL_HAVE_ATTRIBUTE(noinline) +#define DVL_NO_INLINE __attribute__((noinline)) +#elif defined(_MSC_VER) +#define DVL_NO_INLINE __declspec(noinline) +#else +#define DVL_NO_INLINE +#endif + #if DVL_HAVE_ATTRIBUTE(hot) #define DVL_ATTRIBUTE_HOT __attribute__((hot)) #else