Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dev.display.path() #7520

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading