Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/helpers/HierarchicalPathfinder.h
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | #endif | ||||
typedef std::map<RegionID, std::set<RegionID> > EdgesMap; | typedef std::map<RegionID, std::set<RegionID> > EdgesMap; | ||||
void ComputeNeighbors(EdgesMap& edges, Chunk& a, Chunk& b, bool transpose, bool opposite) const; | void ComputeNeighbors(EdgesMap& edges, Chunk& a, Chunk& b, bool transpose, bool opposite) const; | ||||
void RecomputeAllEdges(pass_class_t passClass, EdgesMap& edges); | void RecomputeAllEdges(pass_class_t passClass, EdgesMap& edges); | ||||
void UpdateEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges); | void UpdateEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges); | ||||
void UpdateGlobalRegions(const std::map<pass_class_t, std::vector<RegionID> >& needNewGlobalRegionMap); | void UpdateGlobalRegions(const std::map<pass_class_t, std::vector<RegionID> >& needNewGlobalRegionMap); | ||||
public: | |||||
/** | /** | ||||
* Returns all reachable regions, optionally ordered in a specific manner. | * Returns all reachable regions, optionally ordered in a specific manner. | ||||
*/ | */ | ||||
template<typename Ordering> | template<typename Ordering> | ||||
void FindReachableRegions(RegionID from, std::set<RegionID, Ordering>& reachable, pass_class_t passClass) const | void FindReachableRegions(RegionID from, std::set<RegionID, Ordering>& reachable, pass_class_t passClass) const | ||||
{ | { | ||||
// Flood-fill the region graph, starting at 'from', | // Flood-fill the region graph, starting at 'from', | ||||
// collecting all the regions that are reachable via edges | // collecting all the regions that are reachable via edges | ||||
Show All 14 Lines | while (!open.empty()) | ||||
for (const RegionID& region : edgeMap.at(curr)) | for (const RegionID& region : edgeMap.at(curr)) | ||||
// Add to the reachable set; if this is the first time we added | // Add to the reachable set; if this is the first time we added | ||||
// it then also add it to the open list | // it then also add it to the open list | ||||
if (reachable.insert(region).second) | if (reachable.insert(region).second) | ||||
open.push_back(region); | open.push_back(region); | ||||
} | } | ||||
} | } | ||||
private: | |||||
struct SortByCenterToPoint | struct SortByCenterToPoint | ||||
{ | { | ||||
SortByCenterToPoint(u16 i, u16 j): gi(i), gj(j) {}; | SortByCenterToPoint(u16 i, u16 j): gi(i), gj(j) {}; | ||||
bool operator()(const HierarchicalPathfinder::RegionID& a, const HierarchicalPathfinder::RegionID& b) const | bool operator()(const HierarchicalPathfinder::RegionID& a, const HierarchicalPathfinder::RegionID& b) const | ||||
{ | { | ||||
if (a.DistanceTo(gi, gj) < b.DistanceTo(gi, gj)) | if (a.DistanceTo(gi, gj) < b.DistanceTo(gi, gj)) | ||||
return true; | return true; | ||||
if (a.DistanceTo(gi, gj) > b.DistanceTo(gi, gj)) | if (a.DistanceTo(gi, gj) > b.DistanceTo(gi, gj)) | ||||
Show All 28 Lines | private: | ||||
// Returns the region along with the best cell for optimisation. | // Returns the region along with the best cell for optimisation. | ||||
void FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 gi, u16 gj, const PathGoal& goal, std::set<InterestingRegion, SortByBestToPoint>& regions, pass_class_t passClass) const; | void FindGoalRegionsAndBestNavcells(u16 i0, u16 j0, u16 gi, u16 gj, const PathGoal& goal, std::set<InterestingRegion, SortByBestToPoint>& regions, pass_class_t passClass) const; | ||||
void FillRegionOnGrid(const RegionID& region, pass_class_t passClass, u16 value, Grid<u16>& grid) const; | void FillRegionOnGrid(const RegionID& region, pass_class_t passClass, u16 value, Grid<u16>& grid) const; | ||||
u16 m_W, m_H; | u16 m_W, m_H; | ||||
u8 m_ChunksW, m_ChunksH; | u8 m_ChunksW, m_ChunksH; | ||||
public: | |||||
std::map<pass_class_t, std::vector<Chunk> > m_Chunks; | std::map<pass_class_t, std::vector<Chunk> > m_Chunks; | ||||
std::map<pass_class_t, EdgesMap> m_Edges; | std::map<pass_class_t, EdgesMap> m_Edges; | ||||
private: | |||||
std::map<pass_class_t, std::map<RegionID, GlobalRegionID> > m_GlobalRegions; | std::map<pass_class_t, std::map<RegionID, GlobalRegionID> > m_GlobalRegions; | ||||
GlobalRegionID m_NextGlobalRegionID; | GlobalRegionID m_NextGlobalRegionID; | ||||
// Passability classes for which grids will be updated when calling Update | // Passability classes for which grids will be updated when calling Update | ||||
std::map<std::string, pass_class_t> m_PassClassMasks; | std::map<std::string, pass_class_t> m_PassClassMasks; | ||||
void AddDebugEdges(pass_class_t passClass); | void AddDebugEdges(pass_class_t passClass); | ||||
HierarchicalOverlay* m_DebugOverlay; | HierarchicalOverlay* m_DebugOverlay; | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator