Skip to content

Commit

Permalink
Clean up: DrawDungeon() (#7090)
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Apr 19, 2024
1 parent 5ee75b1 commit 368fa7f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Source/engine/render/scrollrt.cpp
Expand Up @@ -735,7 +735,9 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit
}
Player *player = PlayerAtPosition(tilePosition);
if (player != nullptr) {
auto playerId = static_cast<int8_t>(player->getId() + 1);
uint8_t pid = player->getId();
assert(pid < MAX_PLRS);
int playerId = static_cast<int>(pid) + 1;
// If sprite is moving southwards or east, we want to draw it offset from the tile it's moving to, so we need negative ID
// This respests the order that tiles are drawn. By using the negative id, we ensure that the sprite is drawn with priority
if (player->_pmode == PM_WALK_SOUTHWARDS || (player->_pmode == PM_WALK_SIDEWAYS && player->_pdir == Direction::East))
Expand Down Expand Up @@ -768,7 +770,9 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit

Monster *monster = FindMonsterAtPosition(tilePosition);
if (monster != nullptr) {
auto monsterId = static_cast<int16_t>(monster->getId() + 1);
auto mid = monster->getId();
assert(mid < MaxMonsters);
int monsterId = static_cast<int>(mid) + 1;
// If sprite is moving southwards or east, we want to draw it offset from the tile it's moving to, so we need negative ID
// This respests the order that tiles are drawn. By using the negative id, we ensure that the sprite is drawn with priority
if (monster->mode == MonsterMode::MoveSouthwards || (monster->mode == MonsterMode::MoveSideways && monster->direction == Direction::East))
Expand Down Expand Up @@ -809,28 +813,27 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit
}

if (leveltype != DTYPE_TOWN) {
char bArch = dSpecial[tilePosition.x][tilePosition.y];
if (bArch != 0) {
int8_t bArch = dSpecial[tilePosition.x][tilePosition.y] - 1;
if (bArch >= 0) {
bool transparency = TransList[bMap];
#ifdef _DEBUG
// Turn transparency off here for debugging
transparency = transparency && (SDL_GetModState() & KMOD_ALT) == 0;
#endif
if (transparency) {
ClxDrawLightBlended(out, targetBufferPosition, (*pSpecialCels)[bArch - 1]);
ClxDrawLightBlended(out, targetBufferPosition, (*pSpecialCels)[bArch]);
} else {
ClxDrawLight(out, targetBufferPosition, (*pSpecialCels)[bArch - 1]);
ClxDrawLight(out, targetBufferPosition, (*pSpecialCels)[bArch]);
}
}
} else {
// Tree leaves should always cover player when entering or leaving the tile,
// So delay the rendering until after the next row is being drawn.
// This could probably have been better solved by sprites in screen space.
if (tilePosition.x > 0 && tilePosition.y > 0 && targetBufferPosition.y > TILE_HEIGHT) {
char bArch = dSpecial[tilePosition.x - 1][tilePosition.y - 1];
if (bArch != 0) {
ClxDraw(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, (*pSpecialCels)[bArch - 1]);
}
int8_t bArch = dSpecial[tilePosition.x - 1][tilePosition.y - 1] - 1;
if (bArch >= 0)
ClxDraw(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, (*pSpecialCels)[bArch]);
}
}
}
Expand Down

0 comments on commit 368fa7f

Please sign in to comment.