Release 0.77

master
Kasi 2018-07-25 03:46:17 +01:00
parent d83c228e10
commit 594aae4221
3 changed files with 77 additions and 60 deletions

View File

@ -6,48 +6,17 @@
/** @addtogroup Types /** @addtogroup Types
* @{ */ * @{ */
/**
* @brief A Counter can be used, well as a Counter. You construct it with MaxIterations, the counter is marked as finished whenever the current Iterations reach, or exceed MaxIterations.
* You can use @ref Increment to increase, and @ref Reset to reset the current Iterations.
* You can also use @ref IsFinished to check the current state of the Counter.
*/
class Counter class Counter
{ {
public: public:
/**
* @brief Default Counter constructor with MaxIterations as 0
*/
Counter(); Counter();
/**
* @brief Constructs a Counter with
* @param std::int32_t MaxIterations Maximum amount of Iterations before the counter is Finished
*/
Counter(std::int32_t MaxIterations); Counter(std::int32_t MaxIterations);
/**
* @brief Resets the Counter's current Iterations to 0
* @par Description
* Resets the Counter's current Iterations to 0
*/
void Reset(); void Reset();
/**
* @brief Increases the Counter's current Iterations by Amount, and returns true if the Counter isn't Finished
* @return True if the Counter isn't Finished, after it increments the Counter's current Iterations
*/
bool Increment(std::int32_t Amount = 1); bool Increment(std::int32_t Amount = 1);
/**
* @brief Returns True if the Counter's current Iterations equals the MaxIterations Paramater passed in the Constructor
* @return True if the Counter's current Iterations equals the MaxIterations Paramater passed in the Constructor
*/
bool IsFinished() const; bool IsFinished() const;
/**
* @brief Returns the Counter's current Iterations
* @return Returns the Counter's current Iterations
*/
std::int32_t GetIterations() const; std::int32_t GetIterations() const;
/**
* @brief Returns the Counter's maximum Iterations
* @return Returns the Counter's maximum Iterations
*/
std::int32_t GetMaxIterations() const; std::int32_t GetMaxIterations() const;
friend std::ostream& operator<<(std::ostream& OS, const Counter& C); friend std::ostream& operator<<(std::ostream& OS, const Counter& C);
~Counter(); ~Counter();

View File

@ -5,6 +5,9 @@
#include <vector> #include <vector>
#include <functional> #include <functional>
/**
* @brief A class allowing easy pathfinding within the local region
*/
class Pathfinding class Pathfinding
{ {
public: public:
@ -26,67 +29,112 @@ class Pathfinding
NORTHEAST = 0x4, NORTHEAST = 0x4,
SOUTHEAST = 0x10, SOUTHEAST = 0x10,
SOUTHWEST = 0x40, SOUTHWEST = 0x40,
NORTHWEST = 0x1, NORTHWEST = 0x1
BLOCKED_NORTH = 0x400,
BLOCKED_EAST = 0x1000,
BLOCKED_SOUTH = 0x4000,
BLOCKED_WEST = 0x10000,
BLOCKED_NORTHEAST = 0x800,
BLOCKED_SOUTHEAST = 0x2000,
BLOCKED_NORTHWEST = 0x200,
BLOCKED_SOUTHWEST = 0x8000,
}; };
typedef enum PATHFINDER typedef enum PATHFINDER
{ {
/** <A HREF="https://en.wikipedia.org/wiki/Breadth-first_search">Breadth-first search algorithim</A> */
BREADTH_FIRST_SEARCH BREADTH_FIRST_SEARCH
} PATHFINDER; } PATHFINDER;
enum PATHFIND_OPTION
{
/** Checks collision */
CHECK_COLLISION = (1 << 1),
/** Checks whitelist */
CHECK_WHITELIST = (1 << 2),
/** Checks blacklist */
CHECK_BLACKLIST = (1 << 3),
/** The passed goal is a local tile, the function won't normalize it */
GOAL_IS_LOCAL = (1 << 4),
/** Returns a path as local tiles */
RETURN_LOCAL = (1 << 5)
};
/**
* @brief A subclass used to store information about tile nodes generated by the Pathfinding class
*/
class TileNode class TileNode
{ {
public: public:
/** @brief The local region X coordinate */
std::int32_t X; std::int32_t X;
/** @brief The local region Y coordinate */
std::int32_t Y; std::int32_t Y;
/** @brief The collision flag associated with the node */
std::int32_t Flag; std::int32_t Flag;
/** @brief <B> For pathfinding use only </B> */
bool Inspected; bool Inspected;
/** @brief True if this node matches the whitelisted tiles set in Pathfinding */
bool MatchesWhitelist;
/** @brief True if this node matches the blacklisted tiles set in Pathfinding */
bool MatchesBlacklist;
/** @brief <B> For pathfinding use only </B> */
std::int32_t Parent[2]; std::int32_t Parent[2];
TileNode(); TileNode();
TileNode(std::int32_t X, std::int32_t Y, std::int32_t Flag); TileNode(std::int32_t X, std::int32_t Y, std::int32_t Flag);
bool IsBlocked(bool AllowOccupied = true) const; /** @brief True if the node is occupied or blocked according to its collision flag*/
bool IsBlocked() const;
/** @brief Adds ClientX/Y to the local X and Y coordinates of the node, returning a world tile */
Tile ToWorldTile() const; Tile ToWorldTile() const;
bool operator==(const TileNode& N) const; bool operator==(const TileNode& N) const;
operator bool() const; operator bool() const;
}; };
static void RegenerateNodes(); /** @brief Clears the internal cached nodes, and generates new ones based on the local region */
static void GenerateNodes();
/**
* @brief Sets the internal Whitelist tiles
* @note This will set the internal Whitelist object to the one passed
* */
static void SetWhitelist(const std::vector<Tile>& W);
/**
* @brief Sets the internal Blacklist tiles
* @note This will set the internal Blacklist object to the one passed
* */
static void SetBlacklist(const std::vector<Tile>& B);
/** @brief Returns the internal TileNode cache generated by GenerateNodes() */
static std::vector<std::vector<TileNode>> GetNodes(); static std::vector<std::vector<TileNode>> GetNodes();
/** @brief Returns the internal Whitelist cache */
static std::vector<Tile> GetWhitelist();
/** @brief Returns the internal Blacklist cache */
static std::vector<Tile> GetBlacklist();
static Tile FindWalkableTile(const Tile& T); static Tile FindWalkableTile(const Tile& T);
static Tile FindWalkableTile(const Tile& T, const Tile& Min, const Tile& Max); static Tile FindWalkableTile(const Tile& T, const Tile& Min, const Tile& Max);
static std::vector<Tile> FindWalkableTiles(const Tile& T); static std::vector<Tile> FindWalkableTiles(const Tile& T);
static std::vector<Tile> FindWalkableTiles(const Tile& T, const Tile& Min, const Tile& Max); static std::vector<Tile> FindWalkableTiles(const Tile& T, const Tile& Min, const Tile& Max);
static std::vector<Tile> FindPathTo(const Tile& Goal, bool AllowOccupied = false, PATHFINDER Finder = BREADTH_FIRST_SEARCH); static std::vector<Tile> FindPathTo( const Tile& Goal,
static std::vector<Tile> FindPathTo(const std::vector<Tile>& Goals, bool AllowOccupied = false, PATHFINDER Finder = BREADTH_FIRST_SEARCH); std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST,
// Ignores collision PATHFINDER Finder = BREADTH_FIRST_SEARCH );
static std::vector<Tile> FindDirectPathTo(const Tile& Goal, PATHFINDER Finder = BREADTH_FIRST_SEARCH);
static std::vector<Tile> FindDirectPathTo(const std::vector<Tile>& Goals, PATHFINDER Finder = BREADTH_FIRST_SEARCH);
static std::vector<Tile> FindPathTo( const std::vector<Tile>& Goals,
std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST,
PATHFINDER Finder = BREADTH_FIRST_SEARCH );
static std::vector<Pathfinding::TileNode> FindNodePathTo( const Tile& Goal,
std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST,
PATHFINDER Finder = BREADTH_FIRST_SEARCH );
static bool IsInside(std::uint32_t X, std::uint32_t Y); static std::vector<Pathfinding::TileNode> FindNodePathTo( const std::vector<Tile>& Goals,
static std::vector<Pathfinding::TileNode*> GetNeighborsTo(std::uint32_t X, std::uint32_t Y, bool AllowOccupied = false, bool CheckCollision = true); std::int32_t Options = CHECK_COLLISION | CHECK_WHITELIST | CHECK_BLACKLIST,
static std::vector<Pathfinding::TileNode> Finder_BFS( std::uint32_t StartX, std::uint32_t StartY, PATHFINDER Finder = BREADTH_FIRST_SEARCH );
std::uint32_t EndX, std::uint32_t EndY,
bool AllowOccupied = false, bool CheckCollision = true );
static std::vector<Pathfinding::TileNode> Finder_BFS( std::uint32_t StartX, std::uint32_t StartY,
const std::vector<std::pair<std::uint32_t, std::uint32_t>>& Ends,
bool AllowOccupied = false, bool CheckCollision = true );
private: private:
static std::vector<std::vector<TileNode>> Nodes; static std::vector<std::vector<TileNode>> Nodes;
static std::vector<Tile> Whitelist;
static std::vector<Tile> Blacklist;
static bool IsInside(std::uint32_t X, std::uint32_t Y);
static std::vector<Pathfinding::TileNode*> GetNeighborsTo(std::uint32_t X, std::uint32_t Y, bool CheckCollision = true);
static std::vector<Pathfinding::TileNode> Finder_BFS( std::uint32_t StartX, std::uint32_t StartY,
std::uint32_t EndX, std::uint32_t EndY,
std::int32_t Options );
static std::vector<Pathfinding::TileNode> Finder_BFS( std::uint32_t StartX, std::uint32_t StartY,
const std::vector<std::pair<std::uint32_t, std::uint32_t>>& Ends,
std::int32_t Options );
}; };
#endif // PATHFINDING_HPP_INCLUDED #endif // PATHFINDING_HPP_INCLUDED

Binary file not shown.