Fixed freezes on controller calling MarkPath() to invalid locations
This commit is contained in:
@@ -106,3 +106,63 @@ protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
};
|
||||
|
||||
|
||||
// only used for an experimental implementation of A*
|
||||
template <typename InElementType>
|
||||
struct TPriorityQueueNode {
|
||||
InElementType Element;
|
||||
float Priority;
|
||||
|
||||
TPriorityQueueNode()
|
||||
{
|
||||
}
|
||||
|
||||
TPriorityQueueNode(InElementType InElement, float InPriority)
|
||||
{
|
||||
Element = InElement;
|
||||
Priority = InPriority;
|
||||
}
|
||||
|
||||
bool operator<(const TPriorityQueueNode<InElementType> Other) const
|
||||
{
|
||||
return Priority < Other.Priority;
|
||||
}
|
||||
};
|
||||
template <typename InElementType>
|
||||
class TPriorityQueue {
|
||||
public:
|
||||
TPriorityQueue()
|
||||
{
|
||||
Array.Heapify();
|
||||
}
|
||||
|
||||
public:
|
||||
// Always check if IsEmpty() before Pop-ing!
|
||||
InElementType Pop()
|
||||
{
|
||||
TPriorityQueueNode<InElementType> Node;
|
||||
Array.HeapPop(Node);
|
||||
return Node.Element;
|
||||
}
|
||||
|
||||
TPriorityQueueNode<InElementType> PopNode()
|
||||
{
|
||||
TPriorityQueueNode<InElementType> Node;
|
||||
Array.HeapPop(Node);
|
||||
return Node;
|
||||
}
|
||||
|
||||
void Push(InElementType Element, float Priority)
|
||||
{
|
||||
Array.HeapPush(TPriorityQueueNode<InElementType>(Element, Priority));
|
||||
}
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return Array.Num() == 0;
|
||||
}
|
||||
|
||||
public: // make private later on
|
||||
TArray<TPriorityQueueNode<InElementType>> Array;
|
||||
};
|
||||
Reference in New Issue
Block a user