summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Path.h
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2015-05-04 20:31:53 +0200
committerAlexander Harkness <me@bearbin.net>2015-05-04 20:31:53 +0200
commitadba982257c24557c952c07e9b142c32233d055c (patch)
treef9a5fa0402c1376f69a1c9c342221cc39aa7f780 /src/Mobs/Path.h
parentUpgraded ubuntu version. (diff)
parentMerge remote-tracking branch 'origin/master' into fixes (diff)
downloadcuberite-adba982257c24557c952c07e9b142c32233d055c.tar
cuberite-adba982257c24557c952c07e9b142c32233d055c.tar.gz
cuberite-adba982257c24557c952c07e9b142c32233d055c.tar.bz2
cuberite-adba982257c24557c952c07e9b142c32233d055c.tar.lz
cuberite-adba982257c24557c952c07e9b142c32233d055c.tar.xz
cuberite-adba982257c24557c952c07e9b142c32233d055c.tar.zst
cuberite-adba982257c24557c952c07e9b142c32233d055c.zip
Diffstat (limited to 'src/Mobs/Path.h')
-rw-r--r--src/Mobs/Path.h42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h
index 1bce0ace0..9e893f1d7 100644
--- a/src/Mobs/Path.h
+++ b/src/Mobs/Path.h
@@ -53,7 +53,7 @@ public:
@param a_MaxSteps The maximum steps before giving up. */
cPath(
cChunk & a_Chunk,
- const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps,
+ const Vector3i & a_StartingPoint, const Vector3i & a_EndingPoint, int a_MaxSteps,
double a_BoundingBoxWidth = 1, double a_BoundingBoxHeight = 2,
int a_MaxUp = 1, int a_MaxDown = 1
);
@@ -66,35 +66,39 @@ public:
/* Point retrieval functions, inlined for performance. */
/** Returns the next point in the path. */
- inline Vector3d GetNextPoint()
+ inline Vector3i GetNextPoint()
{
ASSERT(m_Status == ePathFinderStatus::PATH_FOUND);
- return m_PathPoints[m_PointCount - 1 - (++m_CurrentPoint)];
+ return m_PathPoints[m_PathPoints.size() - 1 - (++m_CurrentPoint)];
}
/** Checks whether this is the last point or not. Never call getnextPoint when this is true. */
inline bool IsLastPoint()
{
ASSERT(m_Status == ePathFinderStatus::PATH_FOUND);
- ASSERT(m_CurrentPoint != -1); // You must call getFirstPoint at least once before calling this.
- return (m_CurrentPoint == m_PointCount - 1);
+ return (m_CurrentPoint == m_PathPoints.size() - 1);
+ }
+ inline bool IsFirstPoint()
+ {
+ ASSERT(m_Status == ePathFinderStatus::PATH_FOUND);
+ return (m_CurrentPoint == 0);
}
/** Get the point at a_index. Remark: Internally, the indexes are reversed. */
- inline Vector3d GetPoint(int a_index)
+ inline Vector3i GetPoint(size_t a_index)
{
ASSERT(m_Status == ePathFinderStatus::PATH_FOUND);
- ASSERT(a_index < m_PointCount);
- return m_PathPoints[m_PointCount - 1 - a_index];
+ ASSERT(a_index < m_PathPoints.size());
+ return m_PathPoints[m_PathPoints.size() - 1 - a_index];
}
/** Returns the total number of points this path has. */
inline int GetPointCount()
{
ASSERT(m_Status == ePathFinderStatus::PATH_FOUND);
- return m_PointCount;
+ return m_PathPoints.size();
}
struct VectorHasher
{
- std::size_t operator()(const Vector3d & a_Vector) const
+ std::size_t operator()(const Vector3i & a_Vector) const
{
// Guaranteed to have no hash collisions for any 128x128x128 area. Suitable for pathfinding.
int32_t t = 0;
@@ -110,7 +114,7 @@ public:
private:
/* General */
- bool IsSolid(const Vector3d & a_Location); // Query our hosting world and ask it if there's a solid at a_location.
+ bool IsSolid(const Vector3i & a_Location); // Query our hosting world and ask it if there's a solid at a_location.
bool Step_Internal(); // The public version just calls this version * CALCULATIONS_PER_CALL times.
void FinishCalculation(); // Clears the memory used for calculating the path.
void FinishCalculation(ePathFinderStatus a_NewStatus); // Clears the memory used for calculating the path and changes the status.
@@ -118,27 +122,25 @@ private:
/* Openlist and closedlist management */
void OpenListAdd(cPathCell * a_Cell);
cPathCell * OpenListPop();
- void ProcessIfWalkable(const Vector3d &a_Location, cPathCell * a_Parent, int a_Cost);
+ void ProcessIfWalkable(const Vector3i &a_Location, cPathCell * a_Parent, int a_Cost);
/* Map management */
void ProcessCell(cPathCell * a_Cell, cPathCell * a_Caller, int a_GDelta);
- cPathCell * GetCell(const Vector3d & a_location);
+ cPathCell * GetCell(const Vector3i & a_location);
/* Pathfinding fields */
std::priority_queue<cPathCell *, std::vector<cPathCell *>, compareHeuristics> m_OpenList;
- std::unordered_map<Vector3d, cPathCell *, VectorHasher> m_Map;
- Vector3d m_Destination;
- Vector3d m_Source;
+ std::unordered_map<Vector3i, cPathCell *, VectorHasher> m_Map;
+ Vector3i m_Destination;
+ Vector3i m_Source;
int m_StepsLeft;
/* Control fields */
ePathFinderStatus m_Status;
/* Final path fields */
- int m_PointCount;
- int m_CurrentPoint;
- std::vector<Vector3d> m_PathPoints;
- void AddPoint(Vector3d a_Vector);
+ size_t m_CurrentPoint;
+ std::vector<Vector3i> m_PathPoints;
/* Interfacing with the world */
cChunk * m_Chunk; // Only valid inside Step()!