26#define ENABLE_GRAPH_ASTAR_LOGGING 0
27#if ENABLE_GRAPH_ASTAR_LOGGING
28 #define UE_GRAPH_ASTAR_LOG(Verbosity, Format, ...) UE_LOG(LogAStar, Verbosity, Format, __VA_ARGS__)
30 #define UE_GRAPH_ASTAR_LOG(...)
37template<
typename TGraph>
70#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_IMPL( TemplateClass, TemplateClassParameter, ConditionalReturnType, ConditionalFunctionName, DefaultImpl ) \
71struct CQuery##ConditionalFunctionName \
73 template<typename TemplateClass> auto Requires(TemplateClassParameter& Obj) -> decltype(Obj.ConditionalFunctionName()); \
75template <typename TemplateClass> \
76static inline decltype(auto) ConditionalFunctionName(TemplateClassParameter & Obj) \
78 if constexpr (TModels_V<CQuery##ConditionalFunctionName, TemplateClass>) \
80 return Obj.ConditionalFunctionName(); \
84 return (ConditionalReturnType)(DefaultImpl); \
87#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION( ConditionalReturnType, ConditionalFunctionName, DefaultImpl ) DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_IMPL( TemplateClass, TemplateClass, ConditionalReturnType, ConditionalFunctionName, DefaultImpl )
88#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_CONST( ConditionalReturnType, ConditionalFunctionName, DefaultImpl ) DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_IMPL( TemplateClass, const TemplateClass, ConditionalReturnType, ConditionalFunctionName, DefaultImpl )
90#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM_IMPL( TemplateClass, TemplateClassParameter, ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, DefaultImpl) \
91struct CQuery##ConditionalFunctionName \
93 template<typename TemplateClass> auto Requires(TemplateClassParameter& Obj, ConditionalParamType1 Param1) -> decltype(Obj.ConditionalFunctionName(Param1)); \
95template <typename TemplateClass> \
96static inline decltype(auto) ConditionalFunctionName(TemplateClassParameter & Obj, ConditionalParamType1 Param1) \
98 if constexpr (TModels_V<CQuery##ConditionalFunctionName, TemplateClass>) \
100 return Obj.ConditionalFunctionName(Param1); \
104 return (ConditionalReturnType)(DefaultImpl); \
107#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM( ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, DefaultImpl) DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM_IMPL( TemplateClass, TemplateClass, ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, DefaultImpl)
108#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM_CONST( ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, DefaultImpl) DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM_IMPL( TemplateClass, const TemplateClass, ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, DefaultImpl)
110#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS_IMPL( TemplateClass, TemplateClassParameter, ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl) \
111struct CQuery##ConditionalFunctionName \
113 template<typename TemplateClass> auto Requires(TemplateClassParameter& Obj, ConditionalParamType1 Param1, ConditionalParamType2 Param2) -> decltype(Obj.ConditionalFunctionName(Param1,Param2)); \
115template <typename TemplateClass> \
116static inline decltype(auto) ConditionalFunctionName(TemplateClassParameter & Obj, ConditionalParamType1 Param1, ConditionalParamType2 Param2) \
118 if constexpr (TModels_V<CQuery##ConditionalFunctionName, TemplateClass>) \
120 return Obj.ConditionalFunctionName(Param1, Param2); \
124 return (ConditionalReturnType)(DefaultImpl); \
127#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS( ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl) DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS_IMPL( TemplateClass, TemplateClass, ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl)
128#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS_CONST( ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl) DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS_IMPL(TemplateClass, const TemplateClass, ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl)
130#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_CUSTOM( ConditionalFunctionName, QueryReturnType, QueryFunctionName, QueryParam, QueryDefaultImpl, QueryImpl) \
131struct CQuery##QueryFunctionName \
133 template<typename TemplateClass> auto Requires(const TemplateClass& Obj) -> decltype(Obj.ConditionalFunctionName()); \
135template <typename TemplateClass> \
136static inline QueryReturnType QueryFunctionName(const TemplateClass& Obj, QueryParam) \
138 if constexpr (TModels_V<CQuery##QueryFunctionName, TemplateClass>) \
144 return QueryDefaultImpl; \
148template<
bool DoRangeCheck>
189template<
typename TGraph,
typename Policy = FGraphAStarDefaultPolicy,
typename TSearchNode = FGraphAStarDefaultNode<TGraph>,
bool DoRangeCheck = false >
222 NodeMap.Reserve(FMath::RoundUpToPowerOfTwo(Policy::NodePoolSize / 4));
240 return (*
this)[
Index];
246 Index = NewNode.SearchNodeIndex;
292 for (
int32& NodeIndex : *
this)
309 NodePool[SearchNodeIndex].MarkNotOpened();
310 return SearchNodeIndex;
313 UE_DEPRECATED(5.4,
"PopIndex with a boolean bAllowShrinking has been deprecated - please use the version without parameter")
355 template<
typename TQueryFilter>
356 UE_DEPRECATED(5.1,
"Please use ProcessSingleNode() taking FVector::FReal& OutBestNodeCost instead!")
370 template<
typename TQueryFilter>
503 template<
typename TQueryFilter,
typename TResultPathInfo = TArray<FGraphNodeRef> >
514 if (StartNode.NodeRef == EndNode.NodeRef)
529 if (Policy::bReuseNodePoolInSubsequentSearches)
558 const bool bIsBound =
true;
581 SearchNodeIndex =
NodePool[SearchNodeIndex].ParentNodeIndex;
584 if (PathLength >= Policy::FatalPathLength)
600 SearchNodeIndex =
NodePool[SearchNodeIndex].ParentNodeIndex;
608 template<
typename TQueryFilter>
611 if (!(
Graph.IsValidRef(StartNode.NodeRef)))
635 const bool bIsBound =
false;
646 template<
typename TQueryFilter>
#define check(expr)
Definition AssertionMacros.h:314
#define ensure( InExpression)
Definition AssertionMacros.h:464
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_PTRDIFF_TO_INT32(argument)
Definition CoreMiscDefines.h:442
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
DIRECTLINK_API Display
Definition DirectLinkLog.h:8
return true
Definition ExternalRpcRegistry.cpp:601
EGraphAStarResult
Definition GraphAStar.h:16
@ SearchSuccess
Definition GraphAStar.h:18
@ InfiniteLoop
Definition GraphAStar.h:20
@ SearchFail
Definition GraphAStar.h:17
@ GoalUnreachable
Definition GraphAStar.h:19
#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_CUSTOM(ConditionalFunctionName, QueryReturnType, QueryFunctionName, QueryParam, QueryDefaultImpl, QueryImpl)
Definition GraphAStar.h:130
const int32 NO_COUNT
Definition GraphAStar.h:23
#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS(ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl)
Definition GraphAStar.h:127
#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS_CONST(ConditionalReturnType, ConditionalFunctionName, ConditionalParamType1, ConditionalParamType2, DefaultImpl)
Definition GraphAStar.h:128
#define UE_GRAPH_ASTAR_LOG(...)
Definition GraphAStar.h:30
#define DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_CONST(ConditionalReturnType, ConditionalFunctionName, DefaultImpl)
Definition GraphAStar.h:88
#define UE_REAL_TO_FLOAT_CLAMPED_MAX(argument)
Definition LargeWorldCoordinates.h:33
Definition GraphAStar.h:150
@ RequireRangeCheck
Definition GraphAStar.h:154
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
SizeType HeapPush(ElementType &&InItem, const PREDICATE_CLASS &Predicate)
Definition Array.h:3671
UE_FORCEINLINE_HINT ElementType & Emplace_GetRef(ArgsType &&... Args) UE_LIFETIMEBOUND
Definition Array.h:2613
void HeapPop(ElementType &OutItem, const PREDICATE_CLASS &Predicate, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:3748
UE_NODEBUG UE_FORCEINLINE_HINT bool IsValidIndex(SizeType Index) const
Definition Array.h:1122
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition ContainerAllocationPolicies.h:1662
Definition ContainerAllocationPolicies.h:830
Definition ContainerAllocationPolicies.h:894
CORE_API void Reset(int32 NewReservedSize=0)
Definition String.cpp.inl:326
IndexType HeapSiftUp(RangeValueType *Heap, IndexType RootIndex, IndexType NodeIndex, const ProjectionType &InProj, const PredicateType &Predicate)
Definition BinaryHeap.h:109
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition GraphAStar.h:39
TGraph::FNodeRef FGraphNodeRef
Definition GraphAStar.h:40
bool IsClosed() const
Definition GraphAStar.h:67
bool IsOpened() const
Definition GraphAStar.h:66
uint8 bIsClosed
Definition GraphAStar.h:49
int32 ParentNodeIndex
Definition GraphAStar.h:47
FGraphNodeRef ParentRef
Definition GraphAStar.h:43
FVector::FReal TotalCost
Definition GraphAStar.h:45
FGraphAStarDefaultNode(const FGraphNodeRef &InNodeRef)
Definition GraphAStar.h:51
void MarkNotClosed()
Definition GraphAStar.h:65
const FGraphNodeRef NodeRef
Definition GraphAStar.h:42
uint8 bIsOpened
Definition GraphAStar.h:48
int32 SearchNodeIndex
Definition GraphAStar.h:46
FVector::FReal TraversalCost
Definition GraphAStar.h:44
void MarkClosed()
Definition GraphAStar.h:64
void MarkNotOpened()
Definition GraphAStar.h:63
void MarkOpened()
Definition GraphAStar.h:62
Definition GraphAStar.h:8
static const int32 FatalPathLength
Definition GraphAStar.h:11
static const int32 OpenSetSize
Definition GraphAStar.h:10
static const int32 NodePoolSize
Definition GraphAStar.h:9
static const bool bReuseNodePoolInSubsequentSearches
Definition GraphAStar.h:12
Definition GraphAStar.h:215
void ReinitNodes()
Definition GraphAStar.h:263
FSearchNode & FindOrAdd(const FGraphNodeRef NodeRef)
Definition GraphAStar.h:233
FSearchNode * Find(const FGraphNodeRef NodeRef)
Definition GraphAStar.h:251
FNodeMap NodeMap
Definition GraphAStar.h:217
FNodePool()
Definition GraphAStar.h:219
void Reset()
Definition GraphAStar.h:257
FSearchNode & Add(const FSearchNode &SearchNode)
Definition GraphAStar.h:225
FNodeArray Super
Definition GraphAStar.h:216
Definition GraphAStar.h:201
const FNodeArray & NodePool
Definition GraphAStar.h:202
bool operator()(const int32 A, const int32 B) const
Definition GraphAStar.h:208
FNodeSorter(const FNodeArray &InNodePool)
Definition GraphAStar.h:204
Definition GraphAStar.h:273
FOpenList(FNodeArray &InNodePool, const FNodeSorter &InNodeSorter)
Definition GraphAStar.h:278
const FNodeSorter & NodeSorter
Definition GraphAStar.h:276
FIndexArray Super
Definition GraphAStar.h:274
void Modify(FSearchNode &SearchNode)
Definition GraphAStar.h:290
void Push(FSearchNode &SearchNode)
Definition GraphAStar.h:284
int32 PopIndex()
Definition GraphAStar.h:303
FNodeArray & NodePool
Definition GraphAStar.h:275
Definition GraphAStar.h:191
bool HasReachMaxSearchNodes(const TQueryFilter &Filter) const
Definition GraphAStar.h:647
FNodeSorter NodeSorter
Definition GraphAStar.h:322
EGraphAStarResult FindPath(const FSearchNode &StartNode, const FSearchNode &EndNode, const TQueryFilter &Filter, TResultPathInfo &OutPath)
Definition GraphAStar.h:504
TSearchNode FSearchNode
Definition GraphAStar.h:193
bool ProcessSingleNode(const FSearchNode &EndNode, const bool bIsBound, const TQueryFilter &Filter, int32 &OutBestNodeIndex, FVector::FReal &OutBestNodeCost)
Definition GraphAStar.h:371
TGraph::FNodeRef FGraphNodeRef
Definition GraphAStar.h:192
DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_2PARAMS_CONST(FGraphNodeRef, GetNeighbour, const FSearchNode &, const int32, Obj.GetNeighbour(Param1.NodeRef, Param2))
DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM_CONST(int32, GetNeighbourCountV2, const FSearchNode &, Obj.GetNeighbourCount(Param1.NodeRef))
const TGraph & Graph
Definition GraphAStar.h:320
FNodePool NodePool
Definition GraphAStar.h:321
bool ProcessSingleNode(const FSearchNode &EndNode, const bool bIsBound, const TQueryFilter &Filter, int32 &OutBestNodeIndex, float &OutBestNodeCost)
Definition GraphAStar.h:357
DECLARE_OPTIONALLY_IMPLEMENTED_TEMPLATE_CLASS_FUNCTION_1PARAM_CONST(int32, GetNeighbourCount, const FGraphNodeRef, NO_COUNT)
EGraphAStarResult FloodFrom(const FSearchNode &StartNode, const TQueryFilter &Filter)
Definition GraphAStar.h:609
FOpenList OpenList
Definition GraphAStar.h:323
Definition IdentityFunctor.h:11
Definition ContainerAllocationPolicies.h:256
Definition IsPointer.h:12
Definition NumericLimits.h:41
T FReal
Definition Vector.h:55