Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/helpers/HierarchicalPathfinder.cpp
Show First 20 Lines • Show All 745 Lines • ▼ Show 20 Lines | if (dist < bestDist) | ||||
bestJ = rj; | bestJ = rj; | ||||
bestDist = dist; | bestDist = dist; | ||||
} | } | ||||
} | } | ||||
iGoal = bestI; | iGoal = bestI; | ||||
jGoal = bestJ; | jGoal = bestJ; | ||||
} | } | ||||
template<typename Ordering> | |||||
void HierarchicalPathfinder::FindReachableRegions(RegionID from, std::set<RegionID, Ordering>& reachable, pass_class_t passClass) const | |||||
{ | |||||
// Flood-fill the region graph, starting at 'from', | |||||
// collecting all the regions that are reachable via edges | |||||
reachable.insert(from); | |||||
const EdgesMap& edgeMap = m_Edges.at(passClass); | |||||
if (edgeMap.find(from) == edgeMap.end()) | |||||
return; | |||||
std::vector<RegionID> open; | |||||
open.reserve(64); | |||||
open.push_back(from); | |||||
while (!open.empty()) | |||||
{ | |||||
RegionID curr = open.back(); | |||||
open.pop_back(); | |||||
for (const RegionID& region : edgeMap.at(curr)) | |||||
// Add to the reachable set; if this is the first time we added | |||||
// it then also add it to the open list | |||||
if (reachable.insert(region).second) | |||||
open.push_back(region); | |||||
} | |||||
} | |||||
void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 gi, u16 gj, const PathGoal& goal, std::set<InterestingRegion, SortByBestToPoint>& regions, pass_class_t passClass) const | void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 gi, u16 gj, const PathGoal& goal, std::set<InterestingRegion, SortByBestToPoint>& regions, pass_class_t passClass) const | ||||
{ | { | ||||
if (goal.type == PathGoal::POINT) | if (goal.type == PathGoal::POINT) | ||||
{ | { | ||||
RegionID region = Get(gi, gj, passClass); | RegionID region = Get(gi, gj, passClass); | ||||
if (region.r > 0) | if (region.r > 0) | ||||
regions.insert({region, gi, gj}); | regions.insert({region, gi, gj}); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator