Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/helpers/VertexPathfinder.cpp
Show First 20 Lines • Show All 504 Lines • ▼ Show 20 Lines | struct SquareSort | ||||
bool operator()(const Square& a, const Square& b) const | bool operator()(const Square& a, const Square& b) const | ||||
{ | { | ||||
if ((a.p0 - src).CompareLength(b.p0 - src) < 0) | if ((a.p0 - src).CompareLength(b.p0 - src) < 0) | ||||
return true; | return true; | ||||
return false; | return false; | ||||
} | } | ||||
}; | }; | ||||
WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, CmpPtr<ICmpObstructionManager> cmpObstructionManager) const | WaypointPath VertexPathfinder::ComputeShortPath(const u16 mapSize, Grid<NavcellData>* const& terrainOnlyGrid, const ShortPathRequest& request, CmpPtr<ICmpObstructionManager> cmpObstructionManager) const | ||||
elexis: One could also pass `mapSize * Pathfinding::NAVCELLS_PER_TILE` and should pass a reference to… | |||||
wraitiiUnsubmitted Not Done Inline ActionsNote: wraitii: Note:
A reference to the object itself couldn't be passed when this was kept in the… | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsGrid<NavcellData>* const& terrainOnlyGrid seems strange, why that? Usually it's useless to pass pointers by references. The only case when the pointer can be changed during the function, but it'd even stranger as it's const. vladislavbelov: `Grid<NavcellData>* const& terrainOnlyGrid` seems strange, why that? Usually it's useless to… | |||||
wraitiiUnsubmitted Not Done Inline ActionsIt's merely because I had a const reference to a pointer in the class (which was weird but made sense) and elexis didn't change that wraitii: It's merely because I had a const reference to a pointer in the class (which was weird but made… | |||||
{ | { | ||||
PROFILE2("ComputeShortPath"); | PROFILE2("ComputeShortPath"); | ||||
DebugRenderGoal(cmpObstructionManager->GetSimContext(), request.goal); | DebugRenderGoal(cmpObstructionManager->GetSimContext(), request.goal); | ||||
// Create impassable edges at the max-range boundary, so we can't escape the region | // Create impassable edges at the max-range boundary, so we can't escape the region | ||||
// where we're meant to be searching | // where we're meant to be searching | ||||
fixed rangeXMin = request.x0 - request.range; | fixed rangeXMin = request.x0 - request.range; | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < squares.size(); ++i) | ||||
// TODO: should clip out vertexes and edges that are outside the range, | // TODO: should clip out vertexes and edges that are outside the range, | ||||
// to reduce the search space | // to reduce the search space | ||||
} | } | ||||
// Add terrain obstructions | // Add terrain obstructions | ||||
{ | { | ||||
u16 i0, j0, i1, j1; | u16 i0, j0, i1, j1; | ||||
Pathfinding::NearestNavcell(rangeXMin, rangeZMin, i0, j0, m_MapSize*Pathfinding::NAVCELLS_PER_TILE, m_MapSize*Pathfinding::NAVCELLS_PER_TILE); | Pathfinding::NearestNavcell(rangeXMin, rangeZMin, i0, j0, mapSize * Pathfinding::NAVCELLS_PER_TILE, mapSize * Pathfinding::NAVCELLS_PER_TILE); | ||||
Pathfinding::NearestNavcell(rangeXMax, rangeZMax, i1, j1, m_MapSize*Pathfinding::NAVCELLS_PER_TILE, m_MapSize*Pathfinding::NAVCELLS_PER_TILE); | Pathfinding::NearestNavcell(rangeXMax, rangeZMax, i1, j1, mapSize * Pathfinding::NAVCELLS_PER_TILE, mapSize * Pathfinding::NAVCELLS_PER_TILE); | ||||
AddTerrainEdges(m_Edges, m_Vertexes, i0, j0, i1, j1, request.passClass, *m_TerrainOnlyGrid); | AddTerrainEdges(m_Edges, m_Vertexes, i0, j0, i1, j1, request.passClass, *terrainOnlyGrid); | ||||
} | } | ||||
// Clip out vertices that are inside an edgeSquare (i.e. trivially unreachable) | // Clip out vertices that are inside an edgeSquare (i.e. trivially unreachable) | ||||
for (size_t i = 0; i < m_EdgeSquares.size(); ++i) | for (size_t i = 0; i < m_EdgeSquares.size(); ++i) | ||||
{ | { | ||||
// If the start point is inside the square, ignore it | // If the start point is inside the square, ignore it | ||||
if (start.p.X >= m_EdgeSquares[i].p0.X && | if (start.p.X >= m_EdgeSquares[i].p0.X && | ||||
start.p.Y >= m_EdgeSquares[i].p0.Y && | start.p.Y >= m_EdgeSquares[i].p0.Y && | ||||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
One could also pass mapSize * Pathfinding::NAVCELLS_PER_TILE and should pass a reference to terrainOnlyGrid instead of a pointer. I don't really want to work on it, more communicate that one shouldn't opt in for a pointer when there is no need to.