6 #include <unordered_map>
7 #include <unordered_set>
30 using std::unordered_map;
31 using std::unordered_set;
121 inline const tuple<int, int, int>
toId(
float x,
float y,
float z) {
133 inline static const tuple<int, int, int>
toId(
float x,
float y,
float z,
float stepSize) {
134 return tuple<int, int, int> {
135 static_cast<int>(Math::ceil(x /
stepSize)),
136 static_cast<int>(Math::ceil(y / 0.1f)),
137 static_cast<int>(Math::ceil(z /
stepSize))
184 inline static const tuple<int, int, int>
toIdInt(
int x,
int y,
int z) {
185 return tuple<int, int, int> {
251 bool isWalkable(
float x,
float y,
float z,
float& height,
float stepSize,
float scaleActorBoundingVolumes,
bool flowMapRequest, uint16_t
collisionTypeIds = 0,
bool ignoreStepUpMax =
false);
283 tuple<int, int, int>
id;
353 std::size_t
operator()(
const tuple<int, int, int>& k)
const {
354 std::hash<uint64_t> hashVal;
355 return hashVal(get<0>(k) ^ get<1>(k) ^ get<2>(k));
360 std::size_t
operator()(
const tuple<uint8_t, uint8_t, int, int, int, uint16_t, bool>& k)
const {
361 std::hash<uint64_t> hashVal;
362 return hashVal(
static_cast<int>(get<0>(k)) ^
static_cast<int>(get<1>(k)) ^ get<2>(k) ^ get<3>(k) ^ get<4>(k) ^
static_cast<int>(get<5>(k)) ^
static_cast<int>(get<6>(k)));
367 std::size_t
operator()(
const tuple<uint8_t, uint8_t, int, int, int, uint16_t, int16_t>& k)
const {
368 std::hash<uint64_t> hashVal;
369 return hashVal(
static_cast<int>(get<0>(k)) ^
static_cast<int>(get<1>(k)) ^ get<2>(k) ^ get<3>(k) ^ get<4>(k) ^
static_cast<int>(get<5>(k)) ^
static_cast<int>(get<6>(k)));
444 bool isSlopeWalkableInternal(
float x,
float y,
float z,
float successorX,
float successorY,
float successorZ,
float stepSize,
float scaleActorBoundingVolumes,
bool flowMapRequest,
PathFindingCustomTest* customTest =
nullptr, uint16_t
collisionTypeIds = 0);
456 void step(PathFindingNode* node,
float stepSize,
float scaleActorBoundingVolumes,
const unordered_set<tuple<int, int, int>, PathFindingNodeId_Hash>* nodesToTest,
bool flowMapRequest,
PathFindingCustomTest* customTest =
nullptr);
Dynamic physics world class.
Bounding volume interface.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & setY(float y)
Sets y component.
float computeLengthSquared() const
Vector3 clone() const
Clones this vector3.
Vector3 & sub(float scalar)
Subtracts a scalar.
PathFindingNodesPool()
Public constructor.
PathFindingNode * instantiate() override
Instantiate a path finding node.
unordered_map< tuple< uint8_t, uint8_t, int, int, int, uint16_t, bool >, float, WalkableCache_Hash > walkableCache
PathFindingNodesPool pathFindingNodesPool
unordered_map< tuple< int, int, int >, PathFindingNode *, PathFindingNodeId_Hash > closedNodes
const vector< Vector3 > generateDirectPath(const Vector3 &start, const Vector3 &end)
Generate direct path from start to end.
FlowMap * createFlowMap(const vector< Vector3 > &endPositions, const Vector3 ¢er, float depth, float width, const uint16_t collisionTypeIds, const vector< Vector3 > &path=vector< Vector3 >(), bool complete=true, PathFindingCustomTest *customTest=nullptr)
Create flow map.
bool isWalkable(float x, float y, float z, float &height, float stepSize, float scaleActorBoundingVolumes, bool flowMapRequest, uint16_t collisionTypeIds=0, bool ignoreStepUpMax=false)
Checks if a cell is walkable.
bool findFlowMapPath(const Vector3 &startPosition, const Vector3 &endPosition, const uint16_t collisionTypeIds, vector< Vector3 > &path, int alternativeEndSteps=0, int maxTriesOverride=-1, PathFindingCustomTest *customTest=nullptr)
Finds path to given end position for flow maps.
bool equalsLastNode(const PathFindingNode *a, const PathFindingNode *b)
Returns if nodes are equals for (last node test)
uint16_t skipOnCollisionTypeIds
static const tuple< int, int, int > toId(float x, float y, float z, float stepSize)
Return path finding node id of given x, y, z position components.
PathFinding(World *world, bool sloping=false, int stepsMax=1000, float actorHeight=2.0f, float stepSize=0.5f, float stepSizeLast=0.75f, float actorStepUpMax=0.25f, uint16_t skipOnCollisionTypeIds=0, int maxTries=5, float flowMapStepSize=0.5f, float flowMapScaleActorBoundingVolumes=1.0f)
Public constructor.
static const tuple< int, int, int > toIdInt(int x, int y, int z)
Return string representation of given x,z integer flow map position representation for path finding i...
bool isSlopeWalkableInternal(float x, float y, float z, float successorX, float successorY, float successorZ, float stepSize, float scaleActorBoundingVolumes, bool flowMapRequest, PathFindingCustomTest *customTest=nullptr, uint16_t collisionTypeIds=0)
Checks if a cell is slope walkable.
float computeDistance(const PathFindingNode *a, const PathFindingNode *b)
Computes non square rooted distance between a and b.
float computeDistanceToEnd(const PathFindingNode *node)
Computes minimal non square rooted distance between node and end point.
~PathFinding()
Destructor.
void setNavigationMap(Texture *navigationMap)
Set navigation map which allows fast look ups if Terrain::STEP_SIZE dimensioned cells are walkable.
bool equals(const PathFindingNode *a, float bX, float bY, float bZ)
Returns if nodes are equals.
uint16_t collisionTypeIds
static constexpr bool VERBOSE
bool findPath(const Vector3 &startPosition, const Vector3 &endPosition, const uint16_t collisionTypeIds, vector< Vector3 > &path, int alternativeEndSteps=0, int maxTriesOverride=-1, PathFindingCustomTest *customTest=nullptr)
Finds path to given end position.
static int getIntegerPositionComponent(float value, float stepSize)
Returns integer position component.
bool findPathCustom(const Vector3 &startPosition, const Vector3 &endPosition, float stepSize, float scaleActorBoundingVolumes, const uint16_t collisionTypeIds, vector< Vector3 > &path, int alternativeEndSteps=0, int maxTriesOverride=-1, PathFindingCustomTest *customTest=nullptr)
Finds path to given end position.
float flowMapScaleActorBoundingVolumes
const tuple< int, int, int > toId(float x, float y, float z)
Return path finding node id of given x, y, z position components.
void reset()
Clear caches.
float alignPositionComponent(float value)
Align position component.
unordered_map< tuple< uint8_t, uint8_t, int, int, int, uint16_t, int16_t >, float, WalkableSlopeCache_Hash > walkableSlopeCache
bool isWalkableInternal(float x, float y, float z, float &height, float stepSize, float scaleActorBoundingVolumes, bool flowMapRequest, PathFindingCustomTest *customTest=nullptr, uint16_t collisionTypeIds=0, bool ignoreStepUpMax=false)
Checks if a cell is walkable.
int getIntegerPositionComponent(float value)
Returns integer position component.
static float alignPositionComponent(float value, float stepSize)
Align position component.
unordered_map< tuple< int, int, int >, PathFindingNode *, PathFindingNodeId_Hash > openNodes
void step(PathFindingNode *node, float stepSize, float scaleActorBoundingVolumes, const unordered_set< tuple< int, int, int >, PathFindingNodeId_Hash > *nodesToTest, bool flowMapRequest, PathFindingCustomTest *customTest=nullptr)
Processes one step in AStar path finding.
Path finding custom test interface.
std::size_t operator()(const tuple< int, int, int > &k) const
int y
Integer position along y axis.
int z
Integer position along z axis.
bool hasPreviousNode
Has previous node.
tuple< int, int, int > id
Node id.
int x
Integer position along x axis.
tuple< int, int, int > previousNodeId
Previous node.
float costsAll
Estimated costs to the end plus calculated costs from start to this node.
float costsEstimated
Estimated costs to get to the end.
float costsReachPoint
Calculated costs up to this point (from all previous nodes up to this node) to get to this coordinate...
Vector3 position
Position.
std::size_t operator()(const tuple< uint8_t, uint8_t, int, int, int, uint16_t, bool > &k) const
std::size_t operator()(const tuple< uint8_t, uint8_t, int, int, int, uint16_t, int16_t > &k) const
#define FORBID_CLASS_COPY(CLASS)