Skip to content

Commit

Permalink
Optimize floor drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Aug 26, 2024
1 parent f60659b commit 3377406
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 87 deletions.
8 changes: 2 additions & 6 deletions Source/engine/render/blit_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
#include "engine/palette.h"
#include "utils/attributes.h"

namespace devilution {
#define DEVILUTIONX_BLIT_EXECUTION_POLICY DVL_EXECUTION_UNSEQ

#if __cpp_lib_execution >= 201902L
#define DEVILUTIONX_BLIT_EXECUTION_POLICY std::execution::unseq,
#else
#define DEVILUTIONX_BLIT_EXECUTION_POLICY
#endif
namespace devilution {

DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void BlitFillDirect(uint8_t *dst, unsigned length, uint8_t color)
{
Expand Down
24 changes: 9 additions & 15 deletions Source/engine/render/dun_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstring>

#include "engine/render/blit_impl.hpp"
#include "levels/dun_tile.hpp"
#include "lighting.h"
#include "options.h"
#include "utils/attributes.h"
#ifdef DEBUG_STR
#include "engine/render/text_render.hpp"
Expand Down Expand Up @@ -275,16 +274,6 @@ DVL_ALWAYS_INLINE Clip CalculateClip(int_fast16_t x, int_fast16_t y, int_fast16_
return clip;
}

DVL_ALWAYS_INLINE bool IsFullyDark(const uint8_t *DVL_RESTRICT tbl)
{
return tbl == FullyDarkLightTable;
}

DVL_ALWAYS_INLINE bool IsFullyLit(const uint8_t *DVL_RESTRICT tbl)
{
return tbl == FullyLitLightTable;
}

template <LightType Light, bool Transparent>
DVL_ALWAYS_INLINE DVL_ATTRIBUTE_HOT void RenderSquareFull(uint8_t *DVL_RESTRICT dst, uint16_t dstPitch, const uint8_t *DVL_RESTRICT src, const uint8_t *DVL_RESTRICT tbl)
{
Expand Down Expand Up @@ -438,7 +427,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 @@ -457,12 +446,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 Expand Up @@ -1138,4 +1127,9 @@ void world_draw_black_tile(const Surface &out, int sx, int sy)
}
}

void DunTriangleTileApplyTrans(uint8_t *DVL_RESTRICT dst, const uint8_t *DVL_RESTRICT src, const uint8_t *tbl)
{
BlitPixelsWithMap(dst, src, ReencodedTriangleFrameSize, tbl);
}

} // namespace devilution
8 changes: 7 additions & 1 deletion Source/engine/render/dun_render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "engine/surface.hpp"
#include "levels/dun_tile.hpp"
#include "levels/gendung.h"
#include "lighting.h"
#include "utils/attributes.h"

// #define DUN_RENDER_STATS
Expand Down Expand Up @@ -145,11 +146,16 @@ DVL_ALWAYS_INLINE void RenderTileFoliage(const Surface &out, const Point &positi
}

/**
* @brief Render a black 64x31 tile ◆
* @brief Renders a black 64x31 tile ◆
* @param out Target buffer
* @param sx Target buffer coordinate (left corner of the tile)
* @param sy Target buffer coordinate (bottom corner of the tile)
*/
void world_draw_black_tile(const Surface &out, int sx, int sy);

/**
* @brief Writes a tile with the color swaps from `tbl` to `dst`.
*/
void DunTriangleTileApplyTrans(uint8_t *DVL_RESTRICT dst, const uint8_t *DVL_RESTRICT src, const uint8_t *tbl);

} // namespace devilution
Loading

0 comments on commit 3377406

Please sign in to comment.