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 (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 ()
 Creates an invalid path which is not usable. 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 67 of file Path.h.

Constructor & Destructor Documentation

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 30 of file Path.cpp.

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 73 of file Path.cpp.

cPath::cPath ( const cPath a_other)
delete

delete default constructors

cPath::cPath ( cPath &&  a_other)
delete

Member Function Documentation

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 121 of file Path.cpp.

void cPath::AttemptToFindAlternative ( )
private

Definition at line 309 of file Path.cpp.

bool cPath::BlockTypeIsSpecial ( BLOCKTYPE  a_Type)
private

Definition at line 602 of file Path.cpp.

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

Definition at line 568 of file Path.cpp.

void cPath::BuildPath ( )
private

Definition at line 327 of file Path.cpp.

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 82 of file Path.cpp.

void cPath::FillCellAttributes ( cPathCell a_Cell)
private

Definition at line 475 of file Path.cpp.

void cPath::FinishCalculation ( )
private

Definition at line 348 of file Path.cpp.

void cPath::FinishCalculation ( ePathFinderStatus  a_NewStatus)
private

Definition at line 358 of file Path.cpp.

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

Definition at line 534 of file Path.cpp.

Vector3d cPath::GetNextPoint ( )
inline

Returns the next point in the path.

Definition at line 111 of file Path.h.

bool cPath::HasSolidBelow ( const Vector3i a_Location)
private

Definition at line 671 of file Path.cpp.

bool cPath::IsFirstPoint ( ) const
inline

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

Definition at line 129 of file Path.h.

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 138 of file Path.h.

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

Definition at line 559 of file Path.cpp.

bool cPath::NoMoreWayPoints ( ) const
inline

Checks if we have no more waypoints to return.

Never call getnextPoint when this is true.

Definition at line 122 of file Path.h.

void cPath::OpenListAdd ( cPathCell a_Cell)
private

Definition at line 372 of file Path.cpp.

cPathCell * cPath::OpenListPop ( )
private

Definition at line 385 of file Path.cpp.

cPath& cPath::operator= ( const cPath a_other)
delete
cPath& cPath::operator= ( cPath &&  a_other)
delete
void cPath::ProcessCell ( cPathCell a_Cell,
cPathCell a_Caller,
int  a_GDelta 
)
private

Definition at line 419 of file Path.cpp.

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

Definition at line 405 of file Path.cpp.

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

Definition at line 630 of file Path.cpp.

bool cPath::StepOnce ( )
private

Definition at line 132 of file Path.cpp.

size_t cPath::WayPointsLeft ( ) const
inline

The amount of waypoints left to return.

Definition at line 144 of file Path.h.

Member Data Documentation

bool cPath::m_BadChunkFound
private

Definition at line 193 of file Path.h.

int cPath::m_BoundingBoxHeight
private

Definition at line 177 of file Path.h.

int cPath::m_BoundingBoxWidth
private

Definition at line 176 of file Path.h.

cChunk* cPath::m_Chunk
private

Definition at line 192 of file Path.h.

size_t cPath::m_CurrentPoint
private

Definition at line 187 of file Path.h.

Vector3i cPath::m_Destination
private

Definition at line 174 of file Path.h.

double cPath::m_HalfWidth
private

Definition at line 178 of file Path.h.

bool cPath::m_IsValid
private

Definition at line 184 of file Path.h.

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

Definition at line 173 of file Path.h.

cPathCell* cPath::m_NearestPointToTarget
private

Definition at line 180 of file Path.h.

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

Definition at line 172 of file Path.h.

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

Definition at line 188 of file Path.h.

Vector3i cPath::m_Source
private

Definition at line 175 of file Path.h.

ePathFinderStatus cPath::m_Status
private

Definition at line 183 of file Path.h.

int cPath::m_StepsLeft
private

Definition at line 179 of file Path.h.


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