Browse Source

Level renderer: Remove `level_piece_id` global

`DrawFloor` now passes the piece ID into RenderTile.
Previously, `DrawFloor` did not set `level_piece_id`.
pull/5534/head
Gleb Mazovetskiy 3 years ago committed by Anders Jenbo
parent
commit
1293dfb86d
  1. 10
      Source/engine/render/dun_render.cpp
  2. 3
      Source/engine/render/dun_render.hpp
  3. 28
      Source/engine/render/scrollrt.cpp
  4. 1
      Source/engine/render/scrollrt.h

10
Source/engine/render/dun_render.cpp

@ -1017,7 +1017,7 @@ DVL_ATTRIBUTE_HOT void RenderTileType(TileType tile, std::uint8_t *dst, int dstP
}
/** Returns the mask that defines what parts of the tile are opaque. */
const std::uint32_t *GetMask(TileType tile, ArchType archType)
const std::uint32_t *GetMask(TileType tile, uint16_t levelPieceId, ArchType archType)
{
#ifdef _DEBUG
if ((SDL_GetModState() & KMOD_ALT) != 0) {
@ -1030,12 +1030,12 @@ const std::uint32_t *GetMask(TileType tile, ArchType archType)
return &WallMaskFullyTrasparent[TILE_HEIGHT - 1];
}
if (archType == ArchType::Left && tile != TileType::LeftTriangle) {
if (TileHasAny(level_piece_id, TileProperties::TransparentLeft)) {
if (TileHasAny(levelPieceId, TileProperties::TransparentLeft)) {
return &LeftMaskTransparent[TILE_HEIGHT - 1];
}
}
if (archType == ArchType::Right && tile != TileType::RightTriangle) {
if (TileHasAny(level_piece_id, TileProperties::TransparentRight)) {
if (TileHasAny(levelPieceId, TileProperties::TransparentRight)) {
return &RightMaskTransparent[TILE_HEIGHT - 1];
}
}
@ -1142,10 +1142,10 @@ void RenderBlackTileFull(std::uint8_t *dst, int dstPitch)
} // namespace
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, ArchType archType)
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, uint16_t levelPieceId, ArchType archType)
{
const TileType tile = levelCelBlock.type();
const uint32_t *mask = GetMask(tile, archType);
const uint32_t *mask = GetMask(tile, levelPieceId, archType);
if (mask == nullptr)
return;

3
Source/engine/render/dun_render.hpp

@ -122,9 +122,10 @@ private:
* @param out Target buffer
* @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 archType The type of arch to render.
*/
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, ArchType archType);
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, uint16_t levelPieceId, ArchType archType);
/**
* @brief Render a black 64x31 tile

28
Source/engine/render/scrollrt.cpp

@ -70,10 +70,6 @@ bool cel_transparency_active;
* Specifies whether foliage (tile has extra content that overlaps previous tile) being rendered.
*/
bool cel_foliage_active = false;
/**
* Specifies the current dungeon piece ID of the level, as used during rendering of the level tiles.
*/
int level_piece_id;
// DevilutionX extension.
extern void DrawControllerModifierHints(const Surface &out);
@ -504,22 +500,24 @@ static void DrawDungeon(const Surface & /*out*/, Point /*tilePosition*/, Point /
*/
void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition)
{
level_piece_id = dPiece[tilePosition.x][tilePosition.y];
MICROS *pMap = &DPieceMicros[level_piece_id];
cel_transparency_active = TileHasAny(level_piece_id, TileProperties::Transparent) && TransList[dTransVal[tilePosition.x][tilePosition.y]];
cel_foliage_active = !TileHasAny(level_piece_id, TileProperties::Solid);
const uint16_t levelPieceId = dPiece[tilePosition.x][tilePosition.y];
MICROS *pMap = &DPieceMicros[levelPieceId];
cel_transparency_active = TileHasAny(levelPieceId, TileProperties::Transparent) && TransList[dTransVal[tilePosition.x][tilePosition.y]];
cel_foliage_active = !TileHasAny(levelPieceId, TileProperties::Solid);
for (int i = 0; i < (MicroTileLen / 2); i++) {
{
const LevelCelBlock levelCelBlock { pMap->mt[2 * i] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition, levelCelBlock,
RenderTile(out, targetBufferPosition,
levelCelBlock, levelPieceId,
i == 0 ? ArchType::Left : ArchType::None);
}
}
{
const LevelCelBlock levelCelBlock { pMap->mt[2 * i + 1] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, levelCelBlock,
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 },
levelCelBlock, levelPieceId,
i == 0 ? ArchType::Right : ArchType::None);
}
}
@ -539,17 +537,17 @@ void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPositio
cel_transparency_active = false;
LightTableIndex = dLight[tilePosition.x][tilePosition.y];
const uint16_t pn = dPiece[tilePosition.x][tilePosition.y];
const uint16_t levelPieceId = dPiece[tilePosition.x][tilePosition.y];
{
const LevelCelBlock levelCelBlock { DPieceMicros[pn].mt[0] };
const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[0] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition, levelCelBlock, ArchType::Left);
RenderTile(out, targetBufferPosition, levelCelBlock, levelPieceId, ArchType::Left);
}
}
{
const LevelCelBlock levelCelBlock { DPieceMicros[pn].mt[1] };
const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[1] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, levelCelBlock, ArchType::Right);
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, levelCelBlock, levelPieceId, ArchType::Right);
}
}
}

1
Source/engine/render/scrollrt.h

@ -16,7 +16,6 @@ namespace devilution {
extern int LightTableIndex;
extern bool cel_transparency_active;
extern bool cel_foliage_active;
extern int level_piece_id;
extern bool AutoMapShowItems;
extern bool frameflag;

Loading…
Cancel
Save