Skip to content

Commit

Permalink
Minor rendering cleanups
Browse files Browse the repository at this point in the history
Extracted from various open PRs, for ease of reviewing.
  • Loading branch information
glebm committed Aug 26, 2024
1 parent a374985 commit 1bab025
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Source/engine/render/dun_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ struct DiamondClipY {
};

template <int_fast16_t UpperHeight = TriangleUpperHeight>
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) {
Expand All @@ -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);
}
Expand Down
33 changes: 18 additions & 15 deletions Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions Source/utils/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1bab025

Please sign in to comment.