UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DetourNode.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Modified version of Recast/Detour's source file
3
4//
5// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10// Permission is granted to anyone to use this software for any purpose,
11// including commercial applications, and to alter it and redistribute it
12// freely, subject to the following restrictions:
13// 1. The origin of this software must not be misrepresented; you must not
14// claim that you wrote the original software. If you use this software
15// in a product, an acknowledgment in the product documentation would be
16// appreciated but is not required.
17// 2. Altered source versions must be plainly marked as such, and must not be
18// misrepresented as being the original software.
19// 3. This notice may not be removed or altered from any source distribution.
20//
21
22#ifndef DETOURNODE_H
23#define DETOURNODE_H
24
25#include "CoreMinimal.h"
28
30{
33};
34
35typedef unsigned short dtNodeIndex;
36static const dtNodeIndex DT_NULL_IDX = (dtNodeIndex)~0;
37
38struct dtNode
39{
43 unsigned int pidx : 30;
44 unsigned int flags : 2;
46};
47
48
50{
51public:
54 inline void operator=(const dtNodePool&) {}
55 void clear();
58
59 inline unsigned int getNodeIdx(const dtNode* node) const
60 {
61 if (!node) return 0;
62 return (unsigned int)(node - m_nodes)+1;
63 }
64
65 inline dtNode* getNodeAtIdx(unsigned int idx)
66 {
67 if (!idx) return 0;
68 return &m_nodes[idx-1];
69 }
70
71 inline const dtNode* getNodeAtIdx(unsigned int idx) const
72 {
73 if (!idx) return 0;
74 return &m_nodes[idx-1];
75 }
76
77 inline int getMemUsed() const
78 {
79 return sizeof(*this) +
80 sizeof(dtNode)*m_maxNodes +
81 sizeof(dtNodeIndex)*m_maxNodes +
82 sizeof(dtNodeIndex)*m_hashSize;
83 }
84
85 inline int getMaxNodes() const { return m_maxNodes; }
86 //@UE BEGIN
87 // If using a shared query instance it's possible that m_maxNodes is greater
88 // than pool size requested by callee. There's no point in reallocating the
89 // pool so we artificially limit the number of available nodes
90 inline int getMaxRuntimeNodes() const { return m_maxRuntimeNodes; }
91 //@UE END
92 inline int getNodeCount() const { return m_nodeCount; }
93
94 inline int getHashSize() const { return m_hashSize; }
95 inline dtNodeIndex getFirst(int bucket) const { return m_first[bucket]; }
96 inline dtNodeIndex getNext(int i) const { return m_next[i]; }
97
98 //@UE BEGIN
99 // overrides m_maxNodes for runtime purposes
100 inline void setMaxRuntimeNodes(const int newMaxRuntimeNodes) { m_maxRuntimeNodes = newMaxRuntimeNodes; }
101 //@UE END
102
103private:
104
105 dtNode* m_nodes;
106 dtNodeIndex* m_first;
107 dtNodeIndex* m_next;
108 const int m_maxNodes;
109 const int m_hashSize;
110 //@UE BEGIN
111 int m_maxRuntimeNodes;
112 //@UE END
113 int m_nodeCount;
114};
115
117{
118public:
119 dtNodeQueue(int n);
120 ~dtNodeQueue();
121 inline void operator=(dtNodeQueue&) {}
122
123 inline void clear()
124 {
125 m_size = 0;
126 }
127
128 inline dtNode* top()
129 {
130 return m_heap[0];
131 }
132
133 inline dtNode* pop()
134 {
135 dtNode* result = m_heap[0];
136 m_size--;
137 trickleDown(0, m_heap[m_size]);
138 return result;
139 }
140
141 inline void push(dtNode* node)
142 {
143 m_size++;
144 bubbleUp(m_size-1, node);
145 }
146
147 inline void modify(dtNode* node)
148 {
149 for (int i = 0; i < m_size; ++i)
150 {
151 if (m_heap[i] == node)
152 {
153 bubbleUp(i, node);
154 return;
155 }
156 }
157 }
158
159 inline bool empty() const { return m_size == 0; }
160
161 inline int getMemUsed() const
162 {
163 return sizeof(*this) +
164 sizeof(dtNode*)*(m_capacity+1);
165 }
166
167 inline int getCapacity() const { return m_capacity; }
168
169private:
170 void bubbleUp(int i, dtNode* node);
171 void trickleDown(int i, dtNode* node);
172
173 dtNode** m_heap;
174 const int m_capacity;
175 int m_size;
176};
177
178
179#endif // DETOURNODE_H
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
double dtReal
Definition DetourLargeWorldCoordinates.h:15
dtNodeFlags
Definition DetourNode.h:30
@ DT_NODE_OPEN
Definition DetourNode.h:31
@ DT_NODE_CLOSED
Definition DetourNode.h:32
unsigned short dtNodeIndex
Definition DetourNode.h:35
uint64 dtPolyRef
Definition RecastGraphAStar.h:28
Definition DetourNode.h:50
int getMemUsed() const
Definition DetourNode.h:77
void clear()
Definition DetourNode.cpp:88
dtNode * getNodeAtIdx(unsigned int idx)
Definition DetourNode.h:65
const dtNode * getNodeAtIdx(unsigned int idx) const
Definition DetourNode.h:71
unsigned int getNodeIdx(const dtNode *node) const
Definition DetourNode.h:59
int getNodeCount() const
Definition DetourNode.h:92
dtNode * findNode(dtPolyRef id)
Definition DetourNode.cpp:94
void operator=(const dtNodePool &)
Definition DetourNode.h:54
dtNodeIndex getFirst(int bucket) const
Definition DetourNode.h:95
int getHashSize() const
Definition DetourNode.h:94
dtNode * getNode(dtPolyRef id)
Definition DetourNode.cpp:107
~dtNodePool()
Definition DetourNode.cpp:81
int getMaxNodes() const
Definition DetourNode.h:85
void setMaxRuntimeNodes(const int newMaxRuntimeNodes)
Definition DetourNode.h:100
int getMaxRuntimeNodes() const
Definition DetourNode.h:90
dtNodeIndex getNext(int i) const
Definition DetourNode.h:96
Definition DetourNode.h:117
int getMemUsed() const
Definition DetourNode.h:161
void operator=(dtNodeQueue &)
Definition DetourNode.h:121
bool empty() const
Definition DetourNode.h:159
int getCapacity() const
Definition DetourNode.h:167
void push(dtNode *node)
Definition DetourNode.h:141
~dtNodeQueue()
Definition DetourNode.cpp:154
void modify(dtNode *node)
Definition DetourNode.h:147
void clear()
Definition DetourNode.h:123
dtNode * pop()
Definition DetourNode.h:133
dtNode * top()
Definition DetourNode.h:128
Definition DetourNode.h:39
dtPolyRef id
Polygon ref the node corresponds to.
Definition DetourNode.h:45
dtReal cost
Cost from previous node to current node.
Definition DetourNode.h:41
unsigned int flags
Node flags 0/open/closed.
Definition DetourNode.h:44
dtReal pos[3]
Position of the node.
Definition DetourNode.h:40
dtReal total
Cost up to the node.
Definition DetourNode.h:42
unsigned int pidx
Index to parent node.
Definition DetourNode.h:43