From a509cf00ef5d76d24549557192b7b43573837475 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 3 May 2015 18:56:37 +0100 Subject: Entity improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit •Pathfinder improvements •Fixes #1217 •Fixes #1933 Merge remote-tracking branch 'SafwatHalaby/water2' into fixes --- src/Mobs/Path.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/Mobs/Path.h') 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, compareHeuristics> m_OpenList; - std::unordered_map m_Map; - Vector3d m_Destination; - Vector3d m_Source; + std::unordered_map 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 m_PathPoints; - void AddPoint(Vector3d a_Vector); + size_t m_CurrentPoint; + std::vector m_PathPoints; /* Interfacing with the world */ cChunk * m_Chunk; // Only valid inside Step()! -- cgit v1.2.3