Plasma Engine  2.0
Loading...
Searching...
No Matches
GraphSearch.h
1#pragma once
2
3#include <Foundation/Math/Math.h>
4#include <Utilities/PathFinding/PathState.h>
5#include <Utilities/UtilitiesDLL.h>
6
14template <typename PathStateType>
16{
17public:
19 using IsSearchedObjectCallback = bool (*)(plInt64 iStartNodeIndex, const PathStateType& StartState);
20
23 {
24 PL_DECLARE_POD_TYPE();
25
27 plInt64 m_iNodeIndex;
28
30 const PathStateType* m_pPathState;
31 };
32
34 void SetPathStateGenerator(plPathStateGenerator<PathStateType>* pStateGenerator) { m_pStateGenerator = pStateGenerator; }
35
43 plResult FindPath(plInt64 iStartNodeIndex, const PathStateType& StartState, plInt64 iTargetNodeIndex, plDeque<PathResultData>& out_Path,
44 float fMaxPathCost = plMath::Infinity<float>());
45
53 plResult FindClosest(plInt64 iStartNodeIndex, const PathStateType& StartState, IsSearchedObjectCallback Callback, plDeque<PathResultData>& out_Path,
54 float fMaxPathCost = plMath::Infinity<float>());
55
57 void AddPathNode(plInt64 iNodeIndex, const PathStateType& NewState);
58
59private:
60 void ClearPathStates();
61 plInt64 FindBestNodeToExpand(PathStateType*& out_pPathState);
62 void FillOutPathResult(plInt64 iEndNodeIndex, plDeque<PathResultData>& out_Path);
63
64 plPathStateGenerator<PathStateType>* m_pStateGenerator;
65
67
68 plDeque<plInt64> m_StateQueue;
69
70 plInt64 m_iCurNodeIndex;
71 PathStateType m_CurState;
72};
73
74
75
76#include <Utilities/PathFinding/Implementation/GraphSearch_inl.h>
Definition Deque.h:270
Definition HashTable.h:333
Implements a directed breadth-first search through a graph (A*).
Definition GraphSearch.h:16
plResult FindPath(plInt64 iStartNodeIndex, const PathStateType &StartState, plInt64 iTargetNodeIndex, plDeque< PathResultData > &out_Path, float fMaxPathCost=plMath::Infinity< float >())
Searches for a path that starts at the graph node iStartNodeIndex with the start state StartState and...
Definition GraphSearch_inl.h:97
void AddPathNode(plInt64 iNodeIndex, const PathStateType &NewState)
Needs to be called by the used plPathStateGenerator to add nodes to evaluate.
Definition GraphSearch_inl.h:62
bool(*)(plInt64 iStartNodeIndex, const PathStateType &StartState) IsSearchedObjectCallback
Used by FindClosest() to query whether the currently visited node fulfills the termination criteria.
Definition GraphSearch.h:19
void SetPathStateGenerator(plPathStateGenerator< PathStateType > *pStateGenerator)
Sets the plPathStateGenerator that should be used by this plPathSearch object.
Definition GraphSearch.h:34
plResult FindClosest(plInt64 iStartNodeIndex, const PathStateType &StartState, IsSearchedObjectCallback Callback, plDeque< PathResultData > &out_Path, float fMaxPathCost=plMath::Infinity< float >())
Searches for a path that starts at the graph node iStartNodeIndex with the start state StartState and...
Definition GraphSearch_inl.h:168
The base class for all path state generates.
Definition PathState.h:51
constexpr TYPE Infinity()
Returns the value for Infinity as the template type. Returns zero, if the type does not support Infin...
Definition Constants_inl.h:110
FindPath() and FindClosest() return an array of these objects as the path result.
Definition GraphSearch.h:23
plInt64 m_iNodeIndex
The index of the node that was visited.
Definition GraphSearch.h:27
const PathStateType * m_pPathState
Pointer to the path state that was active at that step along the path.
Definition GraphSearch.h:30
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54