Skip to content

Commit

Permalink
Improve dev.display.path()
Browse files Browse the repository at this point in the history
1. Do not draw foliage with the pause trn.
2. Display the number of steps.
3. If the tile is not walkable (allowed for destination tile), display
   the number of steps in yellow.
  • Loading branch information
glebm committed Nov 10, 2024
1 parent e692acb commit f7a93f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
32 changes: 25 additions & 7 deletions Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,17 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition
const MICROS *pMap = &DPieceMicros[levelPieceId];

const uint8_t *tbl = LightTables[lightTableIndex].data();
const uint8_t *foliageTbl = tbl;
#ifdef _DEBUG
if (DebugPath && MyPlayer->IsPositionInPath(tilePosition))
tbl = GetPauseTRN();
int walkpathIdx = -1;
Point originalTargetBufferPosition;
if (DebugPath) {
walkpathIdx = MyPlayer->GetPositionPathIndex(tilePosition);
if (walkpathIdx != -1) {
originalTargetBufferPosition = targetBufferPosition;
tbl = GetPauseTRN();
}
}
#endif

bool transparency = TileHasAny(tilePosition, TileProperties::Transparent) && TransList[dTransVal[tilePosition.x][tilePosition.y]];
Expand Down Expand Up @@ -529,7 +537,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition
const TileType tileType = levelCelBlock.type();
if (!isFloor || tileType == TileType::TransparentSquare) {
if (isFloor && tileType == TileType::TransparentSquare) {
RenderTileFoliage(out, targetBufferPosition, levelCelBlock, tbl);
RenderTileFoliage(out, targetBufferPosition, levelCelBlock, foliageTbl);
} else {
RenderTile(out, targetBufferPosition, levelCelBlock, getFirstTileMaskLeft(tileType), tbl);
}
Expand All @@ -539,7 +547,7 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition
const TileType tileType = levelCelBlock.type();
if (!isFloor || tileType == TileType::TransparentSquare) {
if (isFloor && tileType == TileType::TransparentSquare) {
RenderTileFoliage(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, tbl);
RenderTileFoliage(out, targetBufferPosition + RightFrameDisplacement, levelCelBlock, foliageTbl);
} else {
RenderTile(out, targetBufferPosition + RightFrameDisplacement,
levelCelBlock, getFirstTileMaskRight(tileType), tbl);
Expand All @@ -554,19 +562,29 @@ void DrawCell(const Surface &out, Point tilePosition, Point targetBufferPosition
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition,
levelCelBlock,
transparency ? MaskType::Transparent : MaskType::Solid, tbl);
transparency ? MaskType::Transparent : MaskType::Solid, foliageTbl);
}
}
{
const LevelCelBlock levelCelBlock { pMap->mt[i + 1] };
if (levelCelBlock.hasValue()) {
RenderTile(out, targetBufferPosition + RightFrameDisplacement,
levelCelBlock,
transparency ? MaskType::Transparent : MaskType::Solid, tbl);
transparency ? MaskType::Transparent : MaskType::Solid, foliageTbl);
}
}
targetBufferPosition.y -= TILE_HEIGHT;
}

#ifdef _DEBUG
if (DebugPath && walkpathIdx != -1) {
DrawString(out, StrCat(walkpathIdx),
Rectangle(originalTargetBufferPosition + Displacement { 0, -TILE_HEIGHT }, Size { TILE_WIDTH, TILE_HEIGHT }),
TextRenderOptions {
.flags = UiFlags::AlignCenter | UiFlags::VerticalCenter
| (IsTileSolid(tilePosition) ? UiFlags::ColorYellow : UiFlags::ColorWhite) });
}
#endif
}

/**
Expand All @@ -581,7 +599,7 @@ void DrawFloorTile(const Surface &out, Point tilePosition, Point targetBufferPos

const uint8_t *tbl = LightTables[lightTableIndex].data();
#ifdef _DEBUG
if (DebugPath && MyPlayer->IsPositionInPath(tilePosition))
if (DebugPath && MyPlayer->GetPositionPathIndex(tilePosition) != -1)
tbl = GetPauseTRN();
#endif

Expand Down
10 changes: 5 additions & 5 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,21 +1653,21 @@ Point Player::GetTargetPosition() const
return target;
}

bool Player::IsPositionInPath(Point pos)
int Player::GetPositionPathIndex(Point pos)
{
constexpr Displacement DirectionOffset[8] = { { 0, -1 }, { -1, 0 }, { 1, 0 }, { 0, 1 }, { -1, -1 }, { 1, -1 }, { 1, 1 }, { -1, 1 } };
Point target = position.future;
int i = 0;
for (auto step : walkpath) {
if (target == pos) {
return true;
}
if (target == pos) return i;
if (step == WALK_NONE)
break;
if (step > 0) {
target += DirectionOffset[step - 1];
}
++i;
}
return false;
return -1;
}

void Player::Say(HeroSpeech speechId) const
Expand Down
4 changes: 2 additions & 2 deletions Source/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,9 @@ struct Player {
Point GetTargetPosition() const;

/**
* @brief Check if position is in player's path.
* @brief Returns the index of the given position in `walkpath`, or -1 if not found.
*/
bool IsPositionInPath(Point position);
int GetPositionPathIndex(Point position);

/**
* @brief Says a speech line.
Expand Down

0 comments on commit f7a93f4

Please sign in to comment.