From 2c0ca0b4c3152765f97e9bb3894b55694e979f32 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 15 Dec 2015 10:46:32 +0000 Subject: Changed cPath to have a reset method. Also reverts "Changed raw cPath to an unique_ptr, fixes memory leak" This reverts commit 1515d37684b469f212bb9858cca6128d74e591b6. --- src/Mobs/Path.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/Mobs/Path.h') diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h index 158853a8c..d133c3669 100644 --- a/src/Mobs/Path.h +++ b/src/Mobs/Path.h @@ -79,7 +79,8 @@ public: /** delete default constructors */ cPath(const cPath & a_other) = delete; cPath(cPath && a_other) = delete; - + + /** delete default assignment operators */ cPath & operator=(const cPath & a_other) = delete; cPath & operator=(cPath && a_other) = delete; @@ -136,6 +137,31 @@ public: return m_PathPoints.size() - m_CurrentPoint; } + /** Recreates a pathfinder instance. A Mob will probably need a single pathfinder instance for its entire life. + + Note that if you have a man-sized mob (1x1x2, zombies, etc), you are advised to call this function without parameters + because the declaration might change in later version of the pathFinder, and a parameter-less call always assumes a man-sized mob. + + If your mob is not man-sized, you are advised to use cPath(width, height), this would be compatible with future versions, + but please be aware that as of now those parameters will be ignored and your mob will be assumed to be man sized. + + @param a_BoundingBoxWidth the character's boundingbox width in blocks. Currently the parameter is ignored and 1 is assumed. + @param a_BoundingBoxHeight the character's boundingbox width in blocks. Currently the parameter is ignored and 2 is assumed. + @param a_MaxUp the character's max jump height in blocks. Currently the parameter is ignored and 1 is assumed. + @param a_MaxDown How far is the character willing to fall? Currently the parameter is ignored and 1 is assumed. */ + /** Attempts to find a path starting from source to destination. + After calling this, you are expected to call Step() once per tick or once per several ticks until it returns true. You should then call getPath() to obtain the path. + Calling this before a path is found resets the current path and starts another search. + @param a_StartingPoint The 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". + @param a_EndingPoint "The block where the Zombie's knees want to be". + @param a_MaxSteps The maximum steps before giving up. */ + void Reset( + cChunk & a_Chunk, + const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps, + double a_BoundingBoxWidth, double a_BoundingBoxHeight, + int a_MaxUp = 1, int a_MaxDown = 1 + ); + @@ -148,6 +174,11 @@ private: void FinishCalculation(ePathFinderStatus a_NewStatus); // Clears the memory used for calculating the path and changes the status. void AttemptToFindAlternative(); void BuildPath(); + /** Handles all logic associated with reseting the path to a clean state */ + void ResetImpl( + const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, + double a_BoundingBoxWidth, double a_BoundingBoxHeight + ); /* Openlist and closedlist management */ void OpenListAdd(cPathCell * a_Cell); -- cgit v1.2.3