Skip to content

Commit

Permalink
Added drawing of path context
Browse files Browse the repository at this point in the history
  • Loading branch information
dkargin committed Jul 30, 2023
1 parent 3ba690b commit fecb13e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/drawPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,35 @@ void drawDroidPath(DROID *psDroid, const glm::mat4& viewMatrix, const glm::mat4
drawSquare(perspectiveViewMatrix, 32, psDroid->sMove.target.x, psDroid->sMove.target.y, height, WZCOL_GREEN);
}

/// Draws path tree from the context.
void drawContext(const PathfindContext& context, const glm::mat4 &mvp)
{
const int terrainOffset = 5;
const int contextIteration = context.iteration;
std::vector<Vector3i> pts;
for (int y = 0; y < context.height; y++)
{
for (int x = 0; x < context.width; x++)
{
const PathExploredTile& tile = context.tile(PathCoord(x, y));
if (tile.iteration != contextIteration)
continue;
auto heightStart = map_TileHeight(x, y) + terrainOffset;
Vector3i start(world_coord(x), heightStart, -world_coord(y));
pts.push_back(start);
auto heightEnd = map_TileHeight(x - tile.dx/64, y - tile.dy/64) + terrainOffset;
Vector3i end(world_coord(x) - tile.dx , heightEnd, -world_coord(y) + tile.dy);
pts.push_back(end);
}
}
if (!pts.empty())
drawLines(mvp, pts, WZCOL_LGREEN);
}

static bool _drawImpassableTiles = true;

extern std::list<PathfindContext> fpathContexts;

void drawPathCostLayer(int player, const iView& playerViewPos, const glm::mat4& viewMatrix, const glm::mat4 &perspectiveViewMatrix)
{
if (player >= MAX_PLAYERS)
Expand All @@ -198,6 +225,10 @@ void drawPathCostLayer(int player, const iView& playerViewPos, const glm::mat4&
drawDroidPath(psDroid, viewMatrix, perspectiveViewMatrix);
}
}

if (!fpathContexts.empty()) {
drawContext(fpathContexts.back(), perspectiveViewMatrix);
}
/*
if (isFlowfieldEnabled() && lastSelected) debugDrawFlowfield(lastSelected, mvp);
*/
Expand Down
2 changes: 1 addition & 1 deletion src/fpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static uint32_t waitingForResultId;
static WZ_SEMAPHORE *waitingForResultSemaphore = nullptr;

/// Last recently used list of contexts.
static std::list<PathfindContext> fpathContexts;
std::list<PathfindContext> fpathContexts;

static PATHRESULT fpathExecute(PATHJOB psJob);

Expand Down

0 comments on commit fecb13e

Please sign in to comment.