Browse Source

Level renderer: Remove `cel_transparency/foliage_active` globals

pull/5535/head
Gleb Mazovetskiy 3 years ago committed by Anders Jenbo
parent
commit
3afef6299f
  1. 11
      Source/engine/render/dun_render.cpp
  2. 5
      Source/engine/render/dun_render.hpp
  3. 49
      Source/engine/render/scrollrt.cpp
  4. 2
      Source/engine/render/scrollrt.h
  5. 3
      Source/inv.cpp

11
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, uint16_t levelPieceId, ArchType archType)
const std::uint32_t *GetMask(TileType tile, uint16_t levelPieceId, ArchType archType, bool transparency, bool foliage)
{
#ifdef _DEBUG
if ((SDL_GetModState() & KMOD_ALT) != 0) {
@ -1025,7 +1025,7 @@ const std::uint32_t *GetMask(TileType tile, uint16_t levelPieceId, ArchType arch
}
#endif
if (cel_transparency_active) {
if (transparency) {
if (archType == ArchType::None) {
return &WallMaskFullyTrasparent[TILE_HEIGHT - 1];
}
@ -1039,7 +1039,7 @@ const std::uint32_t *GetMask(TileType tile, uint16_t levelPieceId, ArchType arch
return &RightMaskTransparent[TILE_HEIGHT - 1];
}
}
} else if (archType != ArchType::None && cel_foliage_active) {
} else if (archType != ArchType::None && foliage) {
if (tile != TileType::TransparentSquare)
return nullptr;
if (archType == ArchType::Left)
@ -1142,10 +1142,11 @@ void RenderBlackTileFull(std::uint8_t *dst, int dstPitch)
} // namespace
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock, uint16_t levelPieceId, ArchType archType)
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock,
uint16_t levelPieceId, ArchType archType, bool transparency, bool foliage)
{
const TileType tile = levelCelBlock.type();
const uint32_t *mask = GetMask(tile, levelPieceId, archType);
const uint32_t *mask = GetMask(tile, levelPieceId, archType, transparency, foliage);
if (mask == nullptr)
return;

5
Source/engine/render/dun_render.hpp

@ -124,8 +124,11 @@ private:
* @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.
* @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);
void RenderTile(const Surface &out, Point position, LevelCelBlock levelCelBlock,
uint16_t levelPieceId, ArchType archType, bool transparency, bool foliage);
/**
* @brief Render a black 64x31 tile

49
Source/engine/render/scrollrt.cpp

@ -62,14 +62,6 @@ namespace devilution {
int LightTableIndex;
bool AutoMapShowItems;
/**
* Specifies whether transparency is active for the current CEL file being decoded.
*/
bool cel_transparency_active;
/**
* Specifies whether foliage (tile has extra content that overlaps previous tile) being rendered.
*/
bool cel_foliage_active = false;
// DevilutionX extension.
extern void DrawControllerModifierHints(const Surface &out);
@ -502,15 +494,21 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition
{
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);
bool transparency = TileHasAny(levelPieceId, TileProperties::Transparent) && TransList[dTransVal[tilePosition.x][tilePosition.y]];
#ifdef _DEBUG
// Turn transparency off here for debugging
transparency = transparency && (SDL_GetModState() & KMOD_ALT) == 0;
#endif
const bool foliage = !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, levelPieceId,
i == 0 ? ArchType::Left : ArchType::None);
i == 0 ? ArchType::Left : ArchType::None,
transparency, foliage);
}
}
{
@ -518,36 +516,39 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 },
levelCelBlock, levelPieceId,
i == 0 ? ArchType::Right : ArchType::None);
i == 0 ? ArchType::Right : ArchType::None,
transparency, foliage);
}
}
targetBufferPosition.y -= TILE_HEIGHT;
}
cel_foliage_active = false;
}
/**
* @brief Render a floor tiles
* @brief Render a floor tile.
* @param out Target buffer
* @param tilePosition dPiece coordinates
* @param targetBufferPosition Target buffer coordinate
*/
void DrawFloor(const Surface &out, Point tilePosition, Point targetBufferPosition)
{
cel_transparency_active = false;
LightTableIndex = dLight[tilePosition.x][tilePosition.y];
const uint16_t levelPieceId = dPiece[tilePosition.x][tilePosition.y];
{
const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[0] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition, levelCelBlock, levelPieceId, ArchType::Left);
RenderTile(out, targetBufferPosition,
levelCelBlock, levelPieceId, ArchType::Left,
/*transparency=*/false, /*foliage=*/false);
}
}
{
const LevelCelBlock levelCelBlock { DPieceMicros[levelPieceId].mt[1] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 }, levelCelBlock, levelPieceId, ArchType::Right);
RenderTile(out, targetBufferPosition + Displacement { TILE_WIDTH / 2, 0 },
levelCelBlock, levelPieceId, ArchType::Right,
/*transparency=*/false, /*foliage=*/false);
}
}
}
@ -726,22 +727,16 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit
if (leveltype != DTYPE_TOWN) {
char bArch = dSpecial[tilePosition.x][tilePosition.y];
if (bArch != 0) {
cel_transparency_active = TransList[bMap];
bool transparency = TransList[bMap];
#ifdef _DEBUG
if ((SDL_GetModState() & KMOD_ALT) != 0) {
cel_transparency_active = false; // Turn transparency off here for debugging
}
// Turn transparency off here for debugging
transparency = transparency && (SDL_GetModState() & KMOD_ALT) == 0;
#endif
if (cel_transparency_active) {
if (transparency) {
ClxDrawLightBlended(out, targetBufferPosition, (*pSpecialCels)[bArch - 1]);
} else {
ClxDrawLight(out, targetBufferPosition, (*pSpecialCels)[bArch - 1]);
}
#ifdef _DEBUG
if ((SDL_GetModState() & KMOD_ALT) != 0) {
cel_transparency_active = TransList[bMap]; // Turn transparency back to its normal state
}
#endif
}
} else {
// Tree leaves should always cover player when entering or leaving the tile,

2
Source/engine/render/scrollrt.h

@ -14,8 +14,6 @@
namespace devilution {
extern int LightTableIndex;
extern bool cel_transparency_active;
extern bool cel_foliage_active;
extern bool AutoMapShowItems;
extern bool frameflag;

3
Source/inv.cpp

@ -1140,13 +1140,10 @@ void DrawInv(const Surface &out)
if (myPlayer.GetItemLocation(myPlayer.InvBody[slot]) == ILOC_TWOHAND) {
InvDrawSlotBack(out, GetPanelPosition(UiPanels::Inventory, slotPos[INVLOC_HAND_RIGHT]), { slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height }, myPlayer.InvBody[slot]._iMagical);
LightTableIndex = 0;
cel_transparency_active = true;
const int dstX = GetRightPanel().position.x + slotPos[INVLOC_HAND_RIGHT].x + (frameSize.width == InventorySlotSizeInPixels.width ? INV_SLOT_HALF_SIZE_PX : 0) - 1;
const int dstY = GetRightPanel().position.y + slotPos[INVLOC_HAND_RIGHT].y;
ClxDrawLightBlended(out, { dstX, dstY }, sprite);
cel_transparency_active = false;
}
}
}

Loading…
Cancel
Save