Recast Navigation
Navigation-mesh Toolset for Games
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
22 #include "DetourAlloc.h"
23 #include "DetourStatus.h"
25 static const int DT_TILECACHE_MAGIC = 'D'<<24 | 'T'<<16 | 'L'<<8 | 'R';
26 static const int DT_TILECACHE_VERSION = 1;
28 static const unsigned char DT_TILECACHE_NULL_AREA = 0;
29 static const unsigned char DT_TILECACHE_WALKABLE_AREA = 63;
30 static const unsigned short DT_TILECACHE_NULL_IDX = 0xffff;
33 {
34  int magic;
35  int version;
36  int tx,ty,tlayer;
37  float bmin[3], bmax[3];
38  unsigned short hmin, hmax;
39  unsigned char width, height;
40  unsigned char minx, maxx, miny, maxy;
41 };
44 {
46  unsigned char regCount;
47  unsigned char* heights;
48  unsigned char* areas;
49  unsigned char* cons;
50  unsigned char* regs;
51 };
54 {
55  int nverts;
56  unsigned char* verts;
57  unsigned char reg;
58  unsigned char area;
59 };
62 {
63  int nconts;
65 };
68 {
69  int nvp;
70  int nverts;
71  int npolys;
72  unsigned short* verts;
73  unsigned short* polys;
74  unsigned short* flags;
75  unsigned char* areas;
76 };
80 {
81  virtual ~dtTileCacheAlloc();
83  virtual void reset() {}
85  virtual void* alloc(const size_t size)
86  {
87  return dtAlloc(size, DT_ALLOC_TEMP);
88  }
90  virtual void free(void* ptr)
91  {
92  dtFree(ptr);
93  }
94 };
97 {
98  virtual ~dtTileCacheCompressor();
100  virtual int maxCompressedSize(const int bufferSize) = 0;
101  virtual dtStatus compress(const unsigned char* buffer, const int bufferSize,
102  unsigned char* compressed, const int maxCompressedSize, int* compressedSize) = 0;
103  virtual dtStatus decompress(const unsigned char* compressed, const int compressedSize,
104  unsigned char* buffer, const int maxBufferSize, int* bufferSize) = 0;
105 };
109  dtTileCacheLayerHeader* header,
110  const unsigned char* heights,
111  const unsigned char* areas,
112  const unsigned char* cons,
113  unsigned char** outData, int* outDataSize);
118  unsigned char* compressed, const int compressedSize,
119  dtTileCacheLayer** layerOut);
127 dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
128  const float* pos, const float radius, const float height, const unsigned char areaId);
130 dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
131  const float* bmin, const float* bmax, const unsigned char areaId);
133 dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
134  const float* center, const float* halfExtents, const float* rotAux, const unsigned char areaId);
137  dtTileCacheLayer& layer,
138  const int walkableClimb);
141  dtTileCacheLayer& layer,
142  const int walkableClimb, const float maxError,
143  dtTileCacheContourSet& lcset);
146  dtTileCacheContourSet& lcset,
147  dtTileCachePolyMesh& mesh);
153 bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize);
Memory used temporarily within a function.
Definition: DetourAlloc.h:29
void * dtAlloc(size_t size, dtAllocHint hint)
Allocates a memory block.
Definition: DetourAlloc.cpp:41
void dtFree(void *ptr)
Deallocates a memory block.
Definition: DetourAlloc.cpp:46
unsigned int dtStatus
Definition: DetourStatus.h:22
static const int DT_TILECACHE_MAGIC
Definition: DetourTileCacheBuilder.h:25
dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc *alloc, dtTileCacheContourSet &lcset, dtTileCachePolyMesh &mesh)
Definition: DetourTileCacheBuilder.cpp:1748
dtStatus dtBuildTileCacheContours(dtTileCacheAlloc *alloc, dtTileCacheLayer &layer, const int walkableClimb, const float maxError, dtTileCacheContourSet &lcset)
Definition: DetourTileCacheBuilder.cpp:748
dtStatus dtMarkBoxArea(dtTileCacheLayer &layer, const float *orig, const float cs, const float ch, const float *bmin, const float *bmax, const unsigned char areaId)
Definition: DetourTileCacheBuilder.cpp:2012
void dtFreeTileCacheLayer(dtTileCacheAlloc *alloc, dtTileCacheLayer *layer)
Definition: DetourTileCacheBuilder.cpp:2156
dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc *alloc, dtTileCacheCompressor *comp, unsigned char *compressed, const int compressedSize, dtTileCacheLayer **layerOut)
Definition: DetourTileCacheBuilder.cpp:2163
void dtFreeTileCachePolyMesh(dtTileCacheAlloc *alloc, dtTileCachePolyMesh *lmesh)
Definition: DetourTileCacheBuilder.cpp:95
static const int DT_TILECACHE_VERSION
Definition: DetourTileCacheBuilder.h:26
dtStatus dtMarkCylinderArea(dtTileCacheLayer &layer, const float *orig, const float cs, const float ch, const float *pos, const float radius, const float height, const unsigned char areaId)
Definition: DetourTileCacheBuilder.cpp:1957
dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor *comp, dtTileCacheLayerHeader *header, const unsigned char *heights, const unsigned char *areas, const unsigned char *cons, unsigned char **outData, int *outDataSize)
Definition: DetourTileCacheBuilder.cpp:2105
static const unsigned char DT_TILECACHE_NULL_AREA
Definition: DetourTileCacheBuilder.h:28
void dtFreeTileCacheContourSet(dtTileCacheAlloc *alloc, dtTileCacheContourSet *cset)
Definition: DetourTileCacheBuilder.cpp:75
dtTileCacheContourSet * dtAllocTileCacheContourSet(dtTileCacheAlloc *alloc)
Definition: DetourTileCacheBuilder.cpp:66
static const unsigned char DT_TILECACHE_WALKABLE_AREA
Definition: DetourTileCacheBuilder.h:29
dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc *alloc, dtTileCacheLayer &layer, const int walkableClimb)
Definition: DetourTileCacheBuilder.cpp:186
dtTileCachePolyMesh * dtAllocTileCachePolyMesh(dtTileCacheAlloc *alloc)
Definition: DetourTileCacheBuilder.cpp:86
static const unsigned short DT_TILECACHE_NULL_IDX
Definition: DetourTileCacheBuilder.h:30
bool dtTileCacheHeaderSwapEndian(unsigned char *data, const int dataSize)
Swaps the endianness of the compressed tile data's header (dtTileCacheLayerHeader).
Definition: DetourTileCacheBuilder.cpp:2223
Definition: DetourTileCacheBuilder.h:80
virtual void reset()
Definition: DetourTileCacheBuilder.h:83
virtual void * alloc(const size_t size)
Definition: DetourTileCacheBuilder.h:85
virtual ~dtTileCacheAlloc()
Definition: DetourTileCacheBuilder.cpp:26
virtual void free(void *ptr)
Definition: DetourTileCacheBuilder.h:90
Definition: DetourTileCacheBuilder.h:97
virtual dtStatus decompress(const unsigned char *compressed, const int compressedSize, unsigned char *buffer, const int maxBufferSize, int *bufferSize)=0
virtual ~dtTileCacheCompressor()
Definition: DetourTileCacheBuilder.cpp:31
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:62
dtTileCacheContour * conts
Definition: DetourTileCacheBuilder.h:64
int nconts
Definition: DetourTileCacheBuilder.h:63
Definition: DetourTileCacheBuilder.h:54
int nverts
Definition: DetourTileCacheBuilder.h:55
unsigned char area
Definition: DetourTileCacheBuilder.h:58
unsigned char * verts
Definition: DetourTileCacheBuilder.h:56
unsigned char reg
Definition: DetourTileCacheBuilder.h:57
Definition: DetourTileCacheBuilder.h:33
int ty
Definition: DetourTileCacheBuilder.h:36
unsigned short hmax
Height min/max range.
Definition: DetourTileCacheBuilder.h:38
int tx
Definition: DetourTileCacheBuilder.h:36
unsigned char height
Dimension of the layer.
Definition: DetourTileCacheBuilder.h:39
unsigned char miny
Definition: DetourTileCacheBuilder.h:40
int tlayer
Definition: DetourTileCacheBuilder.h:36
float bmin[3]
Definition: DetourTileCacheBuilder.h:37
int magic
Data magic.
Definition: DetourTileCacheBuilder.h:34
unsigned char width
Definition: DetourTileCacheBuilder.h:39
unsigned char maxx
Definition: DetourTileCacheBuilder.h:40
float bmax[3]
Definition: DetourTileCacheBuilder.h:37
unsigned char minx
Definition: DetourTileCacheBuilder.h:40
int version
Data version.
Definition: DetourTileCacheBuilder.h:35
unsigned short hmin
Definition: DetourTileCacheBuilder.h:38
unsigned char maxy
Usable sub-region.
Definition: DetourTileCacheBuilder.h:40
Definition: DetourTileCacheBuilder.h:44
unsigned char * regs
Definition: DetourTileCacheBuilder.h:50
unsigned char * cons
Definition: DetourTileCacheBuilder.h:49
unsigned char regCount
Region count.
Definition: DetourTileCacheBuilder.h:46
unsigned char * heights
Definition: DetourTileCacheBuilder.h:47
dtTileCacheLayerHeader * header
Definition: DetourTileCacheBuilder.h:45
unsigned char * areas
Definition: DetourTileCacheBuilder.h:48
Definition: DetourTileCacheBuilder.h:68
int npolys
Number of polygons.
Definition: DetourTileCacheBuilder.h:71
unsigned short * polys
Polygons of the mesh, nvp*2 elements per polygon.
Definition: DetourTileCacheBuilder.h:73
int nverts
Number of vertices.
Definition: DetourTileCacheBuilder.h:70
unsigned char * areas
Area ID of polygons.
Definition: DetourTileCacheBuilder.h:75
unsigned short * flags
Per polygon flags.
Definition: DetourTileCacheBuilder.h:74
int nvp
Definition: DetourTileCacheBuilder.h:69
unsigned short * verts
Vertices of the mesh, 3 elements per vertex.
Definition: DetourTileCacheBuilder.h:72