Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/helpers/HierarchicalPathfinder.h
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | public: | ||||
void Recompute(Grid<NavcellData>* passabilityGrid, | void Recompute(Grid<NavcellData>* passabilityGrid, | ||||
const std::map<std::string, pass_class_t>& nonPathfindingPassClassMasks, | const std::map<std::string, pass_class_t>& nonPathfindingPassClassMasks, | ||||
const std::map<std::string, pass_class_t>& pathfindingPassClassMasks); | const std::map<std::string, pass_class_t>& pathfindingPassClassMasks); | ||||
void Update(Grid<NavcellData>* grid, const Grid<u8>& dirtinessGrid); | void Update(Grid<NavcellData>* grid, const Grid<u8>& dirtinessGrid); | ||||
bool IsChunkDirty(int ci, int cj, const Grid<u8>& dirtinessGrid) const; | bool IsChunkDirty(int ci, int cj, const Grid<u8>& dirtinessGrid) const; | ||||
RegionID Get(u16 i, u16 j, pass_class_t passClass); | RegionID Get(u16 i, u16 j, pass_class_t passClass) const; | ||||
/** | /** | ||||
* Updates @p goal so that it's guaranteed to be reachable from the navcell | * Updates @p goal so that it's guaranteed to be reachable from the navcell | ||||
* @p i0, @p j0 (which is assumed to be on a passable navcell). | * @p i0, @p j0 (which is assumed to be on a passable navcell). | ||||
* | * | ||||
* If the goal is not reachable, it is replaced with a point goal nearest to | * If the goal is not reachable, it is replaced with a point goal nearest to | ||||
* the goal center. | * the goal center. | ||||
* | * | ||||
* In the case of a non-point reachable goal, it is replaced with a point goal | * In the case of a non-point reachable goal, it is replaced with a point goal | ||||
* at the reachable navcell of the goal which is nearest to the starting navcell. | * at the reachable navcell of the goal which is nearest to the starting navcell. | ||||
*/ | */ | ||||
void MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass); | void MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass) const; | ||||
/** | /** | ||||
* Updates @p i, @p j (which is assumed to be an impassable navcell) | * Updates @p i, @p j (which is assumed to be an impassable navcell) | ||||
* to the nearest passable navcell. | * to the nearest passable navcell. | ||||
*/ | */ | ||||
void FindNearestPassableNavcell(u16& i, u16& j, pass_class_t passClass); | void FindNearestPassableNavcell(u16& i, u16& j, pass_class_t passClass) const; | ||||
/** | /** | ||||
* Generates the connectivity grid associated with the given pass_class | * Generates the connectivity grid associated with the given pass_class | ||||
*/ | */ | ||||
Grid<u16> GetConnectivityGrid(pass_class_t passClass); | Grid<u16> GetConnectivityGrid(pass_class_t passClass) const; | ||||
pass_class_t GetPassabilityClass(const std::string& name) const | pass_class_t GetPassabilityClass(const std::string& name) const | ||||
{ | { | ||||
auto it = m_PassClassMasks.find(name); | auto it = m_PassClassMasks.find(name); | ||||
if (it != m_PassClassMasks.end()) | if (it != m_PassClassMasks.end()) | ||||
return it->second; | return it->second; | ||||
LOGERROR("Invalid passability class name '%s'", name.c_str()); | LOGERROR("Invalid passability class name '%s'", name.c_str()); | ||||
Show All 20 Lines | struct Chunk | ||||
void RegionNavcellNearest(u16 r, int iGoal, int jGoal, int& iBest, int& jBest, u32& dist2Best) const; | void RegionNavcellNearest(u16 r, int iGoal, int jGoal, int& iBest, int& jBest, u32& dist2Best) const; | ||||
bool RegionNearestNavcellInGoal(u16 r, u16 i0, u16 j0, const PathGoal& goal, u16& iOut, u16& jOut, u32& dist2Best) const; | bool RegionNearestNavcellInGoal(u16 r, u16 i0, u16 j0, const PathGoal& goal, u16& iOut, u16& jOut, u32& dist2Best) const; | ||||
}; | }; | ||||
typedef std::map<RegionID, std::set<RegionID> > EdgesMap; | typedef std::map<RegionID, std::set<RegionID> > EdgesMap; | ||||
void FindEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges); | void FindEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges) const; | ||||
void FindReachableRegions(RegionID from, std::set<RegionID>& reachable, pass_class_t passClass); | void FindReachableRegions(RegionID from, std::set<RegionID>& reachable, pass_class_t passClass) const; | ||||
void FindPassableRegions(std::set<RegionID>& regions, pass_class_t passClass); | void FindPassableRegions(std::set<RegionID>& regions, pass_class_t passClass) const; | ||||
/** | /** | ||||
* Updates @p iGoal and @p jGoal to the navcell that is the nearest to the | * Updates @p iGoal and @p jGoal to the navcell that is the nearest to the | ||||
* initial goal coordinates, in one of the given @p regions. | * initial goal coordinates, in one of the given @p regions. | ||||
* (Assumes @p regions is non-empty.) | * (Assumes @p regions is non-empty.) | ||||
*/ | */ | ||||
void FindNearestNavcellInRegions(const std::set<RegionID>& regions, u16& iGoal, u16& jGoal, pass_class_t passClass); | void FindNearestNavcellInRegions(const std::set<RegionID>& regions, u16& iGoal, u16& jGoal, pass_class_t passClass) const; | ||||
Chunk& GetChunk(u8 ci, u8 cj, pass_class_t passClass) | const Chunk& GetChunk(u8 ci, u8 cj, pass_class_t passClass) const | ||||
{ | { | ||||
return m_Chunks[passClass].at(cj * m_ChunksW + ci); | return m_Chunks.at(passClass).at(cj * m_ChunksW + ci); | ||||
} | } | ||||
void FillRegionOnGrid(const RegionID& region, pass_class_t passClass, u16 value, Grid<u16>& grid); | 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; | ||||
u16 m_ChunksW, m_ChunksH; | u16 m_ChunksW, m_ChunksH; | ||||
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; | ||||
// Passability classes for which grids will be updated when calling Update | // Passability classes for which grids will be updated when calling Update | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator