Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Private Member Functions | Private Attributes | List of all members
cPath Class Reference

#include <Path.h>

Collaboration diagram for cPath:
Collaboration graph
[legend]

Public Member Functions

Vector3i AcceptNearbyPath ()
 Called after the PathFinder's step returns NEARBY_FOUND. More...
 
ePathFinderStatus CalculationStep (cChunk &a_Chunk)
 Performs part of the path calculation and returns the appropriate status. More...
 
 cPath ()
 Creates an invalid path which is not usable. More...
 
 cPath (cChunk &a_Chunk, const Vector3d &a_StartingPoint, const Vector3d &a_EndingPoint, int a_MaxSteps, double a_BoundingBoxWidth, double a_BoundingBoxHeight)
 Creates a pathfinder instance. More...
 
 cPath (const cPath &a_other)=delete
 delete default constructors More...
 
 cPath (cPath &&a_other)=delete
 
Vector3d GetNextPoint ()
 Returns the next point in the path. More...
 
bool IsFirstPoint () const
 Returns true if GetNextPoint() was never called for this Path. More...
 
bool IsValid () const
 Returns true if this path is properly initialized. More...
 
bool NoMoreWayPoints () const
 Checks if we have no more waypoints to return. More...
 
cPathoperator= (const cPath &a_other)=delete
 
cPathoperator= (cPath &&a_other)=delete
 
size_t WayPointsLeft () const
 The amount of waypoints left to return. More...
 

Private Member Functions

void AttemptToFindAlternative ()
 
bool BlockTypeIsSpecial (BLOCKTYPE a_Type)
 
bool BodyFitsIn (const Vector3i &a_Location, const Vector3i &a_Source)
 
void BuildPath ()
 
void FillCellAttributes (cPathCell &a_Cell)
 
void FinishCalculation ()
 
void FinishCalculation (ePathFinderStatus a_NewStatus)
 
cPathCellGetCell (const Vector3i &a_location)
 
bool HasSolidBelow (const Vector3i &a_Location)
 
bool IsWalkable (const Vector3i &a_Location, const Vector3i &a_Source)
 
void OpenListAdd (cPathCell *a_Cell)
 
cPathCellOpenListPop ()
 
void ProcessCell (cPathCell *a_Cell, cPathCell *a_Caller, int a_GDelta)
 
bool ProcessIfWalkable (const Vector3i &a_Location, cPathCell *a_Source, int a_Cost)
 
bool SpecialIsSolidFromThisDirection (BLOCKTYPE a_Type, NIBBLETYPE a_Meta, const Vector3i &a_Direction)
 
bool StepOnce ()
 

Private Attributes

bool m_BadChunkFound
 
int m_BoundingBoxHeight
 
int m_BoundingBoxWidth
 
cChunkm_Chunk
 
size_t m_CurrentPoint
 
Vector3i m_Destination
 
double m_HalfWidth
 
bool m_IsValid
 
std::unordered_map< Vector3i, cPathCell, VectorHasher< int > > m_Map
 
cPathCellm_NearestPointToTarget
 
std::priority_queue< cPathCell *, std::vector< cPathCell * >, compareHeuristicsm_OpenList
 
std::vector< Vector3im_PathPoints
 
Vector3i m_Source
 
ePathFinderStatus m_Status
 
int m_StepsLeft
 

Detailed Description

Definition at line 68 of file Path.h.

Constructor & Destructor Documentation

◆ cPath() [1/4]

cPath::cPath ( cChunk a_Chunk,
const Vector3d a_StartingPoint,
const Vector3d a_EndingPoint,
int  a_MaxSteps,
double  a_BoundingBoxWidth,
double  a_BoundingBoxHeight 
)

Creates a pathfinder instance.

After calling this, you are expected to call CalculationStep() once per tick or once per several ticks until it returns something other than CALCULATING.

Parameters
a_StartingPointThe function expects this position to be the lowest block the mob is in, a rule of thumb: "The block where the Zombie's knees are at".
a_EndingPoint"The block where the Zombie's knees want to be".
a_MaxStepsThe maximum steps before giving up.
a_BoundingBoxWidththe character's boundingbox width in blocks. Currently the parameter is ignored and 1 is assumed.
a_BoundingBoxHeightthe character's boundingbox width in blocks. Currently the parameter is ignored and 2 is assumed.

Definition at line 32 of file Path.cpp.

◆ cPath() [2/4]

cPath::cPath ( )

Creates an invalid path which is not usable.

You shouldn't call any method other than isValid on such a path.

Definition at line 75 of file Path.cpp.

◆ cPath() [3/4]

cPath::cPath ( const cPath a_other)
delete

delete default constructors

◆ cPath() [4/4]

cPath::cPath ( cPath &&  a_other)
delete

Member Function Documentation

◆ AcceptNearbyPath()

Vector3i cPath::AcceptNearbyPath ( )

Called after the PathFinder's step returns NEARBY_FOUND.

Changes the PathFinder status from NEARBY_FOUND to PATH_FOUND, returns the nearby destination that the PathFinder found a path to.

Definition at line 123 of file Path.cpp.

◆ AttemptToFindAlternative()

void cPath::AttemptToFindAlternative ( )
private

Definition at line 311 of file Path.cpp.

◆ BlockTypeIsSpecial()

bool cPath::BlockTypeIsSpecial ( BLOCKTYPE  a_Type)
private

Definition at line 604 of file Path.cpp.

◆ BodyFitsIn()

bool cPath::BodyFitsIn ( const Vector3i a_Location,
const Vector3i a_Source 
)
private

Definition at line 570 of file Path.cpp.

◆ BuildPath()

void cPath::BuildPath ( )
private

Definition at line 329 of file Path.cpp.

◆ CalculationStep()

ePathFinderStatus cPath::CalculationStep ( cChunk a_Chunk)

Performs part of the path calculation and returns the appropriate status.

If PATH_FOUND is returned, the path was found, and you can call query the instance for waypoints via GetNextWayPoint, etc. If NEARBY_FOUND is returned, it means that the destination is not reachable, but a nearby destination is reachable. If the user likes the alternative destination, they can call AcceptNearbyPath to treat the path as found, and to make consequent calls to step return PATH_FOUND If PATH_NOT_FOUND is returned, then no path was found.

Definition at line 84 of file Path.cpp.

◆ FillCellAttributes()

void cPath::FillCellAttributes ( cPathCell a_Cell)
private

Definition at line 477 of file Path.cpp.

◆ FinishCalculation() [1/2]

void cPath::FinishCalculation ( )
private

Definition at line 350 of file Path.cpp.

◆ FinishCalculation() [2/2]

void cPath::FinishCalculation ( ePathFinderStatus  a_NewStatus)
private

Definition at line 360 of file Path.cpp.

◆ GetCell()

cPathCell * cPath::GetCell ( const Vector3i a_location)
private

Definition at line 536 of file Path.cpp.

◆ GetNextPoint()

Vector3d cPath::GetNextPoint ( )
inline

Returns the next point in the path.

Definition at line 112 of file Path.h.

◆ HasSolidBelow()

bool cPath::HasSolidBelow ( const Vector3i a_Location)
private

Definition at line 666 of file Path.cpp.

◆ IsFirstPoint()

bool cPath::IsFirstPoint ( ) const
inline

Returns true if GetNextPoint() was never called for this Path.

Definition at line 130 of file Path.h.

◆ IsValid()

bool cPath::IsValid ( void  ) const
inline

Returns true if this path is properly initialized.

Returns false if this path was initialized with an empty constructor. If false, the path is unusable and you should not call any methods.

Definition at line 139 of file Path.h.

◆ IsWalkable()

bool cPath::IsWalkable ( const Vector3i a_Location,
const Vector3i a_Source 
)
private

Definition at line 561 of file Path.cpp.

◆ NoMoreWayPoints()

bool cPath::NoMoreWayPoints ( ) const
inline

Checks if we have no more waypoints to return.

Never call getnextPoint when this is true.

Definition at line 123 of file Path.h.

◆ OpenListAdd()

void cPath::OpenListAdd ( cPathCell a_Cell)
private

Definition at line 374 of file Path.cpp.

◆ OpenListPop()

cPathCell * cPath::OpenListPop ( )
private

Definition at line 387 of file Path.cpp.

◆ operator=() [1/2]

cPath& cPath::operator= ( const cPath a_other)
delete

◆ operator=() [2/2]

cPath& cPath::operator= ( cPath &&  a_other)
delete

◆ ProcessCell()

void cPath::ProcessCell ( cPathCell a_Cell,
cPathCell a_Caller,
int  a_GDelta 
)
private

Definition at line 421 of file Path.cpp.

◆ ProcessIfWalkable()

bool cPath::ProcessIfWalkable ( const Vector3i a_Location,
cPathCell a_Source,
int  a_Cost 
)
private

Definition at line 407 of file Path.cpp.

◆ SpecialIsSolidFromThisDirection()

bool cPath::SpecialIsSolidFromThisDirection ( BLOCKTYPE  a_Type,
NIBBLETYPE  a_Meta,
const Vector3i a_Direction 
)
private

Definition at line 632 of file Path.cpp.

◆ StepOnce()

bool cPath::StepOnce ( )
private

Definition at line 134 of file Path.cpp.

◆ WayPointsLeft()

size_t cPath::WayPointsLeft ( ) const
inline

The amount of waypoints left to return.

Definition at line 145 of file Path.h.

Member Data Documentation

◆ m_BadChunkFound

bool cPath::m_BadChunkFound
private

Definition at line 194 of file Path.h.

◆ m_BoundingBoxHeight

int cPath::m_BoundingBoxHeight
private

Definition at line 178 of file Path.h.

◆ m_BoundingBoxWidth

int cPath::m_BoundingBoxWidth
private

Definition at line 177 of file Path.h.

◆ m_Chunk

cChunk* cPath::m_Chunk
private

Definition at line 193 of file Path.h.

◆ m_CurrentPoint

size_t cPath::m_CurrentPoint
private

Definition at line 188 of file Path.h.

◆ m_Destination

Vector3i cPath::m_Destination
private

Definition at line 175 of file Path.h.

◆ m_HalfWidth

double cPath::m_HalfWidth
private

Definition at line 179 of file Path.h.

◆ m_IsValid

bool cPath::m_IsValid
private

Definition at line 185 of file Path.h.

◆ m_Map

std::unordered_map<Vector3i, cPathCell, VectorHasher<int> > cPath::m_Map
private

Definition at line 174 of file Path.h.

◆ m_NearestPointToTarget

cPathCell* cPath::m_NearestPointToTarget
private

Definition at line 181 of file Path.h.

◆ m_OpenList

std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics> cPath::m_OpenList
private

Definition at line 173 of file Path.h.

◆ m_PathPoints

std::vector<Vector3i> cPath::m_PathPoints
private

Definition at line 189 of file Path.h.

◆ m_Source

Vector3i cPath::m_Source
private

Definition at line 176 of file Path.h.

◆ m_Status

ePathFinderStatus cPath::m_Status
private

Definition at line 184 of file Path.h.

◆ m_StepsLeft

int cPath::m_StepsLeft
private

Definition at line 180 of file Path.h.


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