Pyrogenesis  trunk
Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
HierarchicalPathfinder Class Reference

#include <HierarchicalPathfinder.h>

Collaboration diagram for HierarchicalPathfinder:
Collaboration graph
[legend]

Classes

struct  Chunk
 
struct  InterestingRegion
 
struct  RegionID
 
struct  SortByBestToPoint
 
struct  SortByCenterToPoint
 

Public Types

typedef u32 GlobalRegionID
 

Public Member Functions

 HierarchicalPathfinder ()
 
 ~HierarchicalPathfinder ()
 
void SetDebugOverlay (bool enabled, const CSimContext *simContext)
 
void Recompute (Grid< NavcellData > *passabilityGrid, const std::map< std::string, pass_class_t > &nonPathfindingPassClassMasks, const std::map< std::string, pass_class_t > &pathfindingPassClassMasks)
 
void Update (Grid< NavcellData > *grid, const Grid< u8 > &dirtinessGrid)
 
RegionID Get (u16 i, u16 j, pass_class_t passClass) const
 
GlobalRegionID GetGlobalRegion (u16 i, u16 j, pass_class_t passClass) const
 
GlobalRegionID GetGlobalRegion (RegionID region, pass_class_t passClass) const
 
bool MakeGoalReachable (u16 i0, u16 j0, PathGoal &goal, pass_class_t passClass) const
 Updates goal so that it's guaranteed to be reachable from the navcell i0, j0 (which is assumed to be on a passable navcell). More...
 
bool IsGoalReachable (u16 i0, u16 j0, const PathGoal &goal, pass_class_t passClass) const
 
void FindNearestPassableNavcell (u16 &i, u16 &j, pass_class_t passClass) const
 Updates i, j (which is assumed to be an impassable navcell) to the nearest passable navcell. More...
 
Grid< u16GetConnectivityGrid (pass_class_t passClass) const
 Generates the connectivity grid associated with the given pass_class. More...
 
pass_class_t GetPassabilityClass (const std::string &name) const
 
void RenderSubmit (SceneCollector &collector)
 

Public Attributes

std::vector< SOverlayLinem_DebugOverlayLines
 

Private Types

typedef std::map< RegionID, std::set< RegionID > > EdgesMap
 

Private Member Functions

const ChunkGetChunk (u8 ci, u8 cj, pass_class_t passClass) const
 
void ComputeNeighbors (EdgesMap &edges, Chunk &a, Chunk &b, bool transpose, bool opposite) const
 
void RecomputeAllEdges (pass_class_t passClass, EdgesMap &edges)
 Find edges between regions in all chunks, in an optimised manner (only look at top/left) More...
 
void UpdateEdges (u8 ci, u8 cj, pass_class_t passClass, EdgesMap &edges)
 Connect a chunk's regions to their neighbors. More...
 
void UpdateGlobalRegions (const std::map< pass_class_t, std::vector< RegionID > > &needNewGlobalRegionMap)
 
template<typename Ordering >
void FindReachableRegions (RegionID from, std::set< RegionID, Ordering > &reachable, pass_class_t passClass) const
 Returns all reachable regions, optionally ordered in a specific manner. More...
 
void FindNearestNavcellInRegions (const std::set< RegionID, SortByCenterToPoint > &regions, u16 &iGoal, u16 &jGoal, 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 AddDebugEdges (pass_class_t passClass)
 Debug visualisation of graph edges between regions. More...
 

Private Attributes

u16 m_W
 
u16 m_H
 
u8 m_ChunksW
 
u8 m_ChunksH
 
std::map< pass_class_t, std::vector< Chunk > > m_Chunks
 
std::map< pass_class_t, EdgesMapm_Edges
 
std::map< pass_class_t, std::map< RegionID, GlobalRegionID > > m_GlobalRegions
 
GlobalRegionID m_NextGlobalRegionID
 
std::map< std::string, pass_class_tm_PassClassMasks
 
HierarchicalOverlaym_DebugOverlay
 
const CSimContextm_SimContext
 

Static Private Attributes

static const u8 CHUNK_SIZE = 96
 

Member Typedef Documentation

◆ EdgesMap

typedef std::map<RegionID, std::set<RegionID> > HierarchicalPathfinder::EdgesMap
private

◆ GlobalRegionID

Constructor & Destructor Documentation

◆ HierarchicalPathfinder()

HierarchicalPathfinder::HierarchicalPathfinder ( )

◆ ~HierarchicalPathfinder()

HierarchicalPathfinder::~HierarchicalPathfinder ( )

Member Function Documentation

◆ AddDebugEdges()

void HierarchicalPathfinder::AddDebugEdges ( pass_class_t  passClass)
private

Debug visualisation of graph edges between regions.

◆ ComputeNeighbors()

void HierarchicalPathfinder::ComputeNeighbors ( EdgesMap edges,
Chunk a,
Chunk b,
bool  transpose,
bool  opposite 
) const
private

◆ FillRegionOnGrid()

void HierarchicalPathfinder::FillRegionOnGrid ( const RegionID region,
pass_class_t  passClass,
u16  value,
Grid< u16 > &  grid 
) const
private

◆ FindGoalRegionsAndBestNavcells()

void HierarchicalPathfinder::FindGoalRegionsAndBestNavcells ( u16  i0,
u16  j0,
u16  gi,
u16  gj,
const PathGoal goal,
std::set< InterestingRegion, SortByBestToPoint > &  regions,
pass_class_t  passClass 
) const
private

◆ FindNearestNavcellInRegions()

void HierarchicalPathfinder::FindNearestNavcellInRegions ( const std::set< RegionID, SortByCenterToPoint > &  regions,
u16 iGoal,
u16 jGoal,
pass_class_t  passClass 
) const
private

◆ FindNearestPassableNavcell()

void HierarchicalPathfinder::FindNearestPassableNavcell ( u16 i,
u16 j,
pass_class_t  passClass 
) const

Updates i, j (which is assumed to be an impassable navcell) to the nearest passable navcell.

◆ FindReachableRegions()

template<typename Ordering >
void HierarchicalPathfinder::FindReachableRegions ( RegionID  from,
std::set< RegionID, Ordering > &  reachable,
pass_class_t  passClass 
) const
inlineprivate

Returns all reachable regions, optionally ordered in a specific manner.

◆ Get()

HierarchicalPathfinder::RegionID HierarchicalPathfinder::Get ( u16  i,
u16  j,
pass_class_t  passClass 
) const

◆ GetChunk()

const Chunk& HierarchicalPathfinder::GetChunk ( u8  ci,
u8  cj,
pass_class_t  passClass 
) const
inlineprivate

◆ GetConnectivityGrid()

Grid< u16 > HierarchicalPathfinder::GetConnectivityGrid ( pass_class_t  passClass) const

Generates the connectivity grid associated with the given pass_class.

◆ GetGlobalRegion() [1/2]

HierarchicalPathfinder::GlobalRegionID HierarchicalPathfinder::GetGlobalRegion ( u16  i,
u16  j,
pass_class_t  passClass 
) const

◆ GetGlobalRegion() [2/2]

HierarchicalPathfinder::GlobalRegionID HierarchicalPathfinder::GetGlobalRegion ( RegionID  region,
pass_class_t  passClass 
) const

◆ GetPassabilityClass()

pass_class_t HierarchicalPathfinder::GetPassabilityClass ( const std::string &  name) const
inline

◆ IsGoalReachable()

bool HierarchicalPathfinder::IsGoalReachable ( u16  i0,
u16  j0,
const PathGoal goal,
pass_class_t  passClass 
) const
Returns
true if the goal is reachable from navcell i0, j0. (similar to MakeGoalReachable but only checking for reachability).

◆ MakeGoalReachable()

bool HierarchicalPathfinder::MakeGoalReachable ( u16  i0,
u16  j0,
PathGoal goal,
pass_class_t  passClass 
) const

Updates goal so that it's guaranteed to be reachable from the navcell i0, 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 the goal center.

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.

Returns
true if the goal was reachable, false otherwise.

◆ Recompute()

void HierarchicalPathfinder::Recompute ( Grid< NavcellData > *  passabilityGrid,
const std::map< std::string, pass_class_t > &  nonPathfindingPassClassMasks,
const std::map< std::string, pass_class_t > &  pathfindingPassClassMasks 
)

◆ RecomputeAllEdges()

void HierarchicalPathfinder::RecomputeAllEdges ( pass_class_t  passClass,
EdgesMap edges 
)
private

Find edges between regions in all chunks, in an optimised manner (only look at top/left)

◆ RenderSubmit()

void HierarchicalPathfinder::RenderSubmit ( SceneCollector collector)

◆ SetDebugOverlay()

void HierarchicalPathfinder::SetDebugOverlay ( bool  enabled,
const CSimContext simContext 
)

◆ Update()

void HierarchicalPathfinder::Update ( Grid< NavcellData > *  grid,
const Grid< u8 > &  dirtinessGrid 
)

◆ UpdateEdges()

void HierarchicalPathfinder::UpdateEdges ( u8  ci,
u8  cj,
pass_class_t  passClass,
EdgesMap edges 
)
private

Connect a chunk's regions to their neighbors.

Not optimised for global recomputing.

◆ UpdateGlobalRegions()

void HierarchicalPathfinder::UpdateGlobalRegions ( const std::map< pass_class_t, std::vector< RegionID > > &  needNewGlobalRegionMap)
private

Member Data Documentation

◆ CHUNK_SIZE

const u8 HierarchicalPathfinder::CHUNK_SIZE = 96
staticprivate

◆ m_Chunks

std::map<pass_class_t, std::vector<Chunk> > HierarchicalPathfinder::m_Chunks
private

◆ m_ChunksH

u8 HierarchicalPathfinder::m_ChunksH
private

◆ m_ChunksW

u8 HierarchicalPathfinder::m_ChunksW
private

◆ m_DebugOverlay

HierarchicalOverlay* HierarchicalPathfinder::m_DebugOverlay
private

◆ m_DebugOverlayLines

std::vector<SOverlayLine> HierarchicalPathfinder::m_DebugOverlayLines

◆ m_Edges

std::map<pass_class_t, EdgesMap> HierarchicalPathfinder::m_Edges
private

◆ m_GlobalRegions

std::map<pass_class_t, std::map<RegionID, GlobalRegionID> > HierarchicalPathfinder::m_GlobalRegions
private

◆ m_H

u16 HierarchicalPathfinder::m_H
private

◆ m_NextGlobalRegionID

GlobalRegionID HierarchicalPathfinder::m_NextGlobalRegionID
private

◆ m_PassClassMasks

std::map<std::string, pass_class_t> HierarchicalPathfinder::m_PassClassMasks
private

◆ m_SimContext

const CSimContext* HierarchicalPathfinder::m_SimContext
private

◆ m_W

u16 HierarchicalPathfinder::m_W
private

The documentation for this class was generated from the following files: