UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DetourTileCacheBuilder.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 DETOURTILECACHEBUILDER_H
23#define DETOURTILECACHEBUILDER_H
24
25#include "CoreMinimal.h"
26#include "Detour/DetourAlloc.h"
28#include "Detour/DetourStatus.h"
29#include "HAL/PlatformString.h"
30
31static const int DT_TILECACHE_MAGIC = 'D'<<24 | 'T'<<16 | 'L'<<8 | 'R';
32static const int DT_TILECACHE_VERSION = 1;
33
34static const unsigned char DT_TILECACHE_NULL_AREA = 0;
35static const unsigned char DT_TILECACHE_WALKABLE_AREA = 63;
36static const unsigned short DT_TILECACHE_NULL_IDX = 0xffff;
37
39{
40 short version;
42 unsigned short hmin, hmax;
43 unsigned short width, height;
44 unsigned short minx, maxx, miny, maxy;
45 // These should be at the bottom, as they are less often used than the rest of the data.
47};
48
50{
52 unsigned short regCount;
53 unsigned short* heights;
54 unsigned char* areas;
55 unsigned char* cons;
56 unsigned short* regs;
57};
58
60{
61 unsigned short* verts;
62 int nverts;
63 unsigned short reg;
64 unsigned char area;
65};
66
72
74{
75 int nvp;
76 int nverts;
77 int npolys;
78 unsigned short* verts;
79 unsigned short* polys;
80 unsigned short* flags;
81 unsigned char* areas;
82 unsigned short* regs;
83};
84
85//@UE BEGIN
86#if WITH_NAVMESH_CLUSTER_LINKS
88{
89 int nclusters;
90 int nregs;
91 int npolys;
92 unsigned short* regMap;
93 unsigned short* polyMap;
94};
95#endif //WITH_NAVMESH_CLUSTER_LINKS
96
98{
99 int nmeshes;
100 int nverts;
101 int ntris;
102 unsigned int* meshes;
104 unsigned char* tris;
105};
106
108{
109 unsigned short maxDist;
110 unsigned short* data;
111};
112
114{
115public:
119 NAVMESH_API void dtLog(const char* format, ...);
120
121protected:
122
127 virtual void doDtLog(const char* /*msg*/, const int /*len*/) {}
128};
129
130//@UE END
131
133{
134 virtual ~dtTileCacheAlloc() = default;
135
136 virtual void reset()
137 {
138 }
139
140 virtual void* alloc(const int size)
141 {
142 return dtAlloc(size, DT_ALLOC_TEMP);
143 }
144
145 virtual void free(void* ptr)
146 {
147 dtFree(ptr, DT_ALLOC_TEMP);
148 }
149};
150
152{
153 virtual int maxCompressedSize(const int bufferSize) = 0;
154 virtual dtStatus compress(const unsigned char* buffer, const int bufferSize,
155 unsigned char* compressed, const int maxCompressedSize, int* compressedSize) = 0;
156 virtual dtStatus decompress(const unsigned char* compressed, const int compressedSize,
157 unsigned char* buffer, const int maxBufferSize, int* bufferSize) = 0;
158};
159
160//@UE BEGIN: moved from DetourTileCacheBuilder.cpp
161template<class T> class dtFixedArray
162{
163 dtTileCacheAlloc* m_alloc;
164 T* m_ptr;
165 const int m_size;
166 inline T* operator=(T* p);
167 inline void operator=(dtFixedArray<T>& p);
168 inline dtFixedArray();
169public:
170 inline dtFixedArray(dtTileCacheAlloc* a, const int s) : m_alloc(a), m_ptr((T*)a->alloc(sizeof(T)*s)), m_size(s) {}
171 inline ~dtFixedArray() { if (m_alloc) m_alloc->free(m_ptr); }
172 inline operator T*() { return m_ptr; }
173 inline int size() const { return m_size; }
174 inline void set(unsigned char v) { memset((void*)m_ptr, v, sizeof(T)*m_size); }
175};
176
177inline int getDirOffsetX(int dir)
178{
179 const int offset[4] = { -1, 0, 1, 0, };
180 return offset[dir&0x03];
181}
182
183inline int getDirOffsetY(int dir)
184{
185 const int offset[4] = { 0, 1, 0, -1 };
186 return offset[dir&0x03];
187}
188//@UE END
189
192 const unsigned short* heights,
193 const unsigned char* areas,
194 const unsigned char* cons,
195 unsigned char** outData, int* outDataSize);
196
198
200 const unsigned char* compressed, const int compressedSize,
202
205
208
209//@UE BEGIN
210#if WITH_NAVMESH_CLUSTER_LINKS
213#endif // WITH_NAVMESH_CLUSTER_LINKS
214
217
220//@UE END
221
222NAVMESH_API dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const dtReal* orig, const dtReal cs, const dtReal ch,
223 const dtReal* pos, const dtReal radius, const dtReal height, const unsigned char areaId);
224
225//@UE BEGIN: more shapes
226NAVMESH_API dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const dtReal* orig, const dtReal cs, const dtReal ch,
227 const dtReal* pos, const dtReal* extent, const unsigned char areaId);
228
229NAVMESH_API dtStatus dtMarkConvexArea(dtTileCacheLayer& layer, const dtReal* orig, const dtReal cs, const dtReal ch,
230 const dtReal* verts, const int nverts, const dtReal hmin, const dtReal hmax, const unsigned char areaId);
231
232NAVMESH_API dtStatus dtReplaceCylinderArea(dtTileCacheLayer& layer, const dtReal* orig, const dtReal cs, const dtReal ch,
233 const dtReal* pos, const dtReal radius, const dtReal height, const unsigned char areaId,
234 const unsigned char filterAreaId);
235
236NAVMESH_API dtStatus dtReplaceBoxArea(dtTileCacheLayer& layer, const dtReal* orig, const dtReal cs, const dtReal ch,
237 const dtReal* pos, const dtReal* extent, const unsigned char areaId, const unsigned char filterAreaId);
238
239NAVMESH_API dtStatus dtReplaceConvexArea(dtTileCacheLayer& layer, const dtReal* orig, const dtReal cs, const dtReal ch,
240 const dtReal* verts, const int nverts, const dtReal hmin, const dtReal hmax, const unsigned char areaId,
241 const unsigned char filterAreaId);
242
243NAVMESH_API dtStatus dtReplaceArea(dtTileCacheLayer& layer, const unsigned char areaId, const unsigned char filterAreaId);
244
245//@UE END
246
247
248//@UE BEGIN: renamed building regions to dtBuildTileCacheRegionsMonotone, added new region generation
250
252 const int minRegionArea, const int mergeRegionArea,
254
256 const int minRegionArea, const int mergeRegionArea,
257 dtTileCacheLayer& layer);
258
260 const int minRegionArea, const int mergeRegionArea,
261 dtTileCacheLayer& layer, int regionChunkSize);
262//@UE END
263
265 dtTileCacheLayer& layer,
266 const int walkableClimb, const dtReal maxError, const dtReal simplificationElevationRatio, // UE
267 const dtReal cs, const dtReal ch,
269 //@UE BEGIN
272#endif // WITH_NAVMESH_CLUSTER_LINKS
273 , const bool skipContourSimplification = false
274 //@UE END
275 );
276
281 const int walkableClimb);
282
283//@UE BEGIN
285 const dtReal cs, const dtReal ch,
287 dtTileCacheLayer& layer,
288 dtTileCachePolyMesh& lmesh,
290
291#if WITH_NAVMESH_CLUSTER_LINKS
294 dtTileCachePolyMesh& lmesh);
295#endif // WITH_NAVMESH_CLUSTER_LINKS
296//@UE END
297
303NAVMESH_API bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize);
304
305
306#endif // DETOURTILECACHEBUILDER_H
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void dtFree(void *ptr, dtAllocHint hint)
Definition DetourAlloc.cpp:49
void * dtAlloc(int size, dtAllocHint hint)
Definition DetourAlloc.cpp:43
@ DT_ALLOC_TEMP
Memory used temporarily within a function.
Definition DetourAlloc.h:32
double dtReal
Definition DetourLargeWorldCoordinates.h:15
NAVMESH_API dtStatus dtReplaceArea(dtTileCacheLayer &layer, const unsigned char areaId, const unsigned char filterAreaId)
Definition DetourTileCacheBuilder.cpp:2796
NAVMESH_API bool dtTileCacheHeaderSwapEndian(unsigned char *data, const int dataSize)
Definition DetourTileCacheBuilder.cpp:2957
NAVMESH_API void dtFreeTileCachePolyMesh(dtTileCacheAlloc *alloc, dtTileCachePolyMesh *lmesh)
Definition DetourTileCacheBuilder.cpp:89
NAVMESH_API dtStatus dtReplaceBoxArea(dtTileCacheLayer &layer, const dtReal *orig, const dtReal cs, const dtReal ch, const dtReal *pos, const dtReal *extent, const unsigned char areaId, const unsigned char filterAreaId)
Definition DetourTileCacheBuilder.cpp:2685
NAVMESH_API void dtFreeTileCacheDistanceField(dtTileCacheAlloc *alloc, dtTileCacheDistanceField *dfield)
Definition DetourTileCacheBuilder.cpp:135
NAVMESH_API dtTileCachePolyMeshDetail * dtAllocTileCachePolyMeshDetail(dtTileCacheAlloc *alloc)
Definition DetourTileCacheBuilder.cpp:104
NAVMESH_API dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc *alloc, dtTileCacheLogContext *ctx, dtTileCacheContourSet &lcset, dtTileCachePolyMesh &mesh, const int walkableClimb)
Definition DetourTileCacheBuilder.cpp:2201
NAVMESH_API dtStatus dtMarkBoxArea(dtTileCacheLayer &layer, const dtReal *orig, const dtReal cs, const dtReal ch, const dtReal *pos, const dtReal *extent, const unsigned char areaId)
Definition DetourTileCacheBuilder.cpp:2499
int getDirOffsetX(int dir)
Definition DetourTileCacheBuilder.h:177
NAVMESH_API dtTileCachePolyMesh * dtAllocTileCachePolyMesh(dtTileCacheAlloc *alloc)
Definition DetourTileCacheBuilder.cpp:80
NAVMESH_API dtStatus dtMarkConvexArea(dtTileCacheLayer &layer, const dtReal *orig, const dtReal cs, const dtReal ch, const dtReal *verts, const int nverts, const dtReal hmin, const dtReal hmax, const unsigned char areaId)
Definition DetourTileCacheBuilder.cpp:2562
NAVMESH_API dtStatus dtReplaceCylinderArea(dtTileCacheLayer &layer, const dtReal *orig, const dtReal cs, const dtReal ch, const dtReal *pos, const dtReal radius, const dtReal height, const unsigned char areaId, const unsigned char filterAreaId)
Definition DetourTileCacheBuilder.cpp:2626
NAVMESH_API dtStatus dtReplaceConvexArea(dtTileCacheLayer &layer, const dtReal *orig, const dtReal cs, const dtReal ch, const dtReal *verts, const int nverts, const dtReal hmin, const dtReal hmax, const unsigned char areaId, const unsigned char filterAreaId)
Definition DetourTileCacheBuilder.cpp:2732
NAVMESH_API dtStatus dtBuildTileCacheContours(dtTileCacheAlloc *alloc, dtTileCacheLayer &layer, const int walkableClimb, const dtReal maxError, const dtReal simplificationElevationRatio, const dtReal cs, const dtReal ch, dtTileCacheContourSet &lcset, const bool skipContourSimplification=false)
Definition DetourTileCacheBuilder.cpp:863
NAVMESH_API void dtFreeTileCacheLayer(dtTileCacheAlloc *alloc, dtTileCacheLayer *layer)
Definition DetourTileCacheBuilder.cpp:2890
NAVMESH_API void dtFreeTileCacheContourSet(dtTileCacheAlloc *alloc, dtTileCacheContourSet *cset)
Definition DetourTileCacheBuilder.cpp:42
NAVMESH_API dtStatus dtBuildTileCacheDistanceField(dtTileCacheAlloc *alloc, dtTileCacheLayer &layer, dtTileCacheDistanceField &dfield)
Definition DetourTileCacheRegion.cpp:244
NAVMESH_API dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor *comp, dtTileCacheLayerHeader *header, const unsigned short *heights, const unsigned char *areas, const unsigned char *cons, unsigned char **outData, int *outDataSize)
Definition DetourTileCacheBuilder.cpp:2847
NAVMESH_API dtTileCacheDistanceField * dtAllocTileCacheDistanceField(dtTileCacheAlloc *alloc)
Definition DetourTileCacheBuilder.cpp:126
NAVMESH_API dtStatus dtBuildTileCachePolyMeshDetail(dtTileCacheAlloc *alloc, const dtReal cs, const dtReal ch, const dtReal sampleDist, const dtReal sampleMaxError, dtTileCacheLayer &layer, dtTileCachePolyMesh &lmesh, dtTileCachePolyMeshDetail &dmesh)
Definition DetourTileCacheDetail.cpp:925
NAVMESH_API dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc *alloc, const int minRegionArea, const int mergeRegionArea, dtTileCacheLayer &layer, dtTileCacheDistanceField dfield)
Definition DetourTileCacheRegion.cpp:925
NAVMESH_API dtStatus dtBuildTileCacheRegionsChunky(dtTileCacheAlloc *alloc, const int minRegionArea, const int mergeRegionArea, dtTileCacheLayer &layer, int regionChunkSize)
Definition DetourTileCacheRegion.cpp:1579
NAVMESH_API dtTileCacheContourSet * dtAllocTileCacheContourSet(dtTileCacheAlloc *alloc)
Definition DetourTileCacheBuilder.cpp:33
int getDirOffsetY(int dir)
Definition DetourTileCacheBuilder.h:183
NAVMESH_API dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc *alloc, dtTileCacheCompressor *comp, const unsigned char *compressed, const int compressedSize, dtTileCacheLayer **layerOut)
Definition DetourTileCacheBuilder.cpp:2899
NAVMESH_API dtStatus dtMarkCylinderArea(dtTileCacheLayer &layer, const dtReal *orig, const dtReal cs, const dtReal ch, const dtReal *pos, const dtReal radius, const dtReal height, const unsigned char areaId)
Definition DetourTileCacheBuilder.cpp:2441
NAVMESH_API dtStatus dtBuildTileCacheRegionsMonotone(dtTileCacheAlloc *alloc, const int minRegionArea, const int mergeRegionArea, dtTileCacheLayer &layer)
Definition DetourTileCacheRegion.cpp:1562
NAVMESH_API void dtFreeTileCachePolyMeshDetail(dtTileCacheAlloc *alloc, dtTileCachePolyMeshDetail *dmesh)
Definition DetourTileCacheBuilder.cpp:113
unsigned int dtStatus
Definition RecastGraphAStar.h:29
char int compressedSize
Definition lz4.h:735
Definition DetourTileCacheBuilder.h:162
dtFixedArray(dtTileCacheAlloc *a, const int s)
Definition DetourTileCacheBuilder.h:170
~dtFixedArray()
Definition DetourTileCacheBuilder.h:171
void set(unsigned char v)
Definition DetourTileCacheBuilder.h:174
int size() const
Definition DetourTileCacheBuilder.h:173
Definition DetourTileCacheBuilder.h:114
virtual void doDtLog(const char *, const int)
Definition DetourTileCacheBuilder.h:127
NAVMESH_API void dtLog(const char *format,...)
Definition DetourTileCacheBuilder.cpp:2995
float v
Definition radaudio_mdct.cpp:62
Definition DetourTileCacheBuilder.h:133
virtual void reset()
Definition DetourTileCacheBuilder.h:136
virtual void * alloc(const int size)
Definition DetourTileCacheBuilder.h:140
virtual ~dtTileCacheAlloc()=default
virtual void free(void *ptr)
Definition DetourTileCacheBuilder.h:145
Definition DetourTileCacheBuilder.h:152
virtual dtStatus decompress(const unsigned char *compressed, const int compressedSize, unsigned char *buffer, const int maxBufferSize, int *bufferSize)=0
virtual int maxCompressedSize(const int bufferSize)=0
virtual dtStatus compress(const unsigned char *buffer, const int bufferSize, unsigned char *compressed, const int maxCompressedSize, int *compressedSize)=0
Definition DetourTileCacheBuilder.h:68
dtTileCacheContour * conts
Definition DetourTileCacheBuilder.h:70
int nconts
Definition DetourTileCacheBuilder.h:69
Definition DetourTileCacheBuilder.h:60
int nverts
Definition DetourTileCacheBuilder.h:62
unsigned char area
Definition DetourTileCacheBuilder.h:64
unsigned short reg
Definition DetourTileCacheBuilder.h:63
unsigned short * verts
x, y, z, portal direction.
Definition DetourTileCacheBuilder.h:61
Definition DetourTileCacheBuilder.h:108
unsigned short maxDist
Max distance.
Definition DetourTileCacheBuilder.h:109
unsigned short * data
distance for every cell in layer
Definition DetourTileCacheBuilder.h:110
Definition DetourTileCacheBuilder.h:39
int ty
Definition DetourTileCacheBuilder.h:41
unsigned short miny
Definition DetourTileCacheBuilder.h:44
unsigned short height
Dimension of the layer.
Definition DetourTileCacheBuilder.h:43
unsigned short hmax
Height min/max range (.
Definition DetourTileCacheBuilder.h:42
int tx
Definition DetourTileCacheBuilder.h:41
unsigned short width
Definition DetourTileCacheBuilder.h:43
dtReal bmax[3]
Definition DetourTileCacheBuilder.h:46
unsigned short maxx
Definition DetourTileCacheBuilder.h:44
unsigned short maxy
Usable sub-region.
Definition DetourTileCacheBuilder.h:44
int tlayer
Definition DetourTileCacheBuilder.h:41
dtReal bmin[3]
Definition DetourTileCacheBuilder.h:46
unsigned short minx
Definition DetourTileCacheBuilder.h:44
short version
Data version.
Definition DetourTileCacheBuilder.h:40
unsigned short hmin
Definition DetourTileCacheBuilder.h:42
Definition DetourTileCacheBuilder.h:50
unsigned short * heights
Definition DetourTileCacheBuilder.h:53
unsigned short * regs
Definition DetourTileCacheBuilder.h:56
unsigned char * cons
Definition DetourTileCacheBuilder.h:55
dtTileCacheLayerHeader * header
Definition DetourTileCacheBuilder.h:51
unsigned short regCount
Region count.
Definition DetourTileCacheBuilder.h:52
unsigned char * areas
Definition DetourTileCacheBuilder.h:54
Definition DetourTileCacheBuilder.h:98
unsigned char * tris
The mesh triangles. [Size: 4*ntris].
Definition DetourTileCacheBuilder.h:104
int nverts
The number of vertices in verts.
Definition DetourTileCacheBuilder.h:100
dtReal * verts
The mesh vertices. [Size: 3*nverts].
Definition DetourTileCacheBuilder.h:103
unsigned int * meshes
The sub-mesh data. [Size: 4*nmeshes].
Definition DetourTileCacheBuilder.h:102
int nmeshes
The number of sub-meshes defined by meshes.
Definition DetourTileCacheBuilder.h:99
int ntris
The number of triangles in tris.
Definition DetourTileCacheBuilder.h:101
Definition DetourTileCacheBuilder.h:74
unsigned short * regs
Region ID of polygon.
Definition DetourTileCacheBuilder.h:82
int npolys
Number of polygons.
Definition DetourTileCacheBuilder.h:77
unsigned short * polys
Polygons of the mesh, nvp*2 elements per polygon.
Definition DetourTileCacheBuilder.h:79
int nverts
Number of vertices.
Definition DetourTileCacheBuilder.h:76
unsigned char * areas
Area ID of polygons.
Definition DetourTileCacheBuilder.h:81
unsigned short * flags
Per polygon flags.
Definition DetourTileCacheBuilder.h:80
int nvp
Definition DetourTileCacheBuilder.h:75
unsigned short * verts
Vertices of the mesh, 3 elements per vertex.
Definition DetourTileCacheBuilder.h:78