Debian Codegraph @

DetourTileCache/Include/DetourTileCacheBuilder.h

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
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 //
18
19 #ifndef DETOURTILECACHEBUILDER_H
20 #define DETOURTILECACHEBUILDER_H
21
22 #include "DetourAlloc.h"
23 #include "DetourStatus.h"
24
25 static const int DT_TILECACHE_MAGIC = 'D'<<24 | 'T'<<16 | 'L'<<8 | 'R'; ///< 'DTLR';
26 static const int DT_TILECACHE_VERSION = 1;
27
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;
31
32 struct dtTileCacheLayerHeader
33 {
34 int magic; ///< Data magic
35 int version; ///< Data version
36 int tx,ty,tlayer;
37 float bmin[3], bmax[3];
38 unsigned short hmin, hmax; ///< Height min/max range
39 unsigned char width, height; ///< Dimension of the layer.
40 unsigned char minx, maxx, miny, maxy; ///< Usable sub-region.
41 };
42
43 struct dtTileCacheLayer
44 {
45 dtTileCacheLayerHeader* header;
46 unsigned char regCount; ///< Region count.
47 unsigned char* heights;
48 unsigned char* areas;
49 unsigned char* cons;
50 unsigned char* regs;
51 };
52
53 struct dtTileCacheContour
54 {
55 int nverts;
56 unsigned char* verts;
57 unsigned char reg;
58 unsigned char area;
59 };
60
61 struct dtTileCacheContourSet
62 {
63 int nconts;
64 dtTileCacheContour* conts;
65 };
66
67 struct dtTileCachePolyMesh
68 {
69 int nvp;
70 int nverts; ///< Number of vertices.
71 int npolys; ///< Number of polygons.
72 unsigned short* verts; ///< Vertices of the mesh, 3 elements per vertex.
73 unsigned short* polys; ///< Polygons of the mesh, nvp*2 elements per polygon.
74 unsigned short* flags; ///< Per polygon flags.
75 unsigned char* areas; ///< Area ID of polygons.
76 };
77
78
79 struct dtTileCacheAlloc
80 {
81 virtual ~dtTileCacheAlloc();
82
83 virtual void reset() {}
84
85 virtual void* alloc(const size_t size)
86 {
87 return dtAlloc(size, DT_ALLOC_TEMP);
88 }
89
90 virtual void free(void* ptr)
91 {
92 dtFree(ptr);
93 }
94 };
95
96 struct dtTileCacheCompressor
97 {
98 virtual ~dtTileCacheCompressor();
99
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 };
106
107
108 dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
109 dtTileCacheLayerHeader* header,
110 const unsigned char* heights,
111 const unsigned char* areas,
112 const unsigned char* cons,
113 unsigned char** outData, int* outDataSize);
114
115 void dtFreeTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheLayer* layer);
116
117 dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheCompressor* comp,
118 unsigned char* compressed, const int compressedSize,
119 dtTileCacheLayer** layerOut);
120
121 dtTileCacheContourSet* dtAllocTileCacheContourSet(dtTileCacheAlloc* alloc);
122 void dtFreeTileCacheContourSet(dtTileCacheAlloc* alloc, dtTileCacheContourSet* cset);
123
124 dtTileCachePolyMesh* dtAllocTileCachePolyMesh(dtTileCacheAlloc* alloc);
125 void dtFreeTileCachePolyMesh(dtTileCacheAlloc* alloc, dtTileCachePolyMesh* lmesh);
126
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);
129
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);
132
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);
135
136 dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc* alloc,
137 dtTileCacheLayer& layer,
138 const int walkableClimb);
139
140 dtStatus dtBuildTileCacheContours(dtTileCacheAlloc* alloc,
141 dtTileCacheLayer& layer,
142 const int walkableClimb, const float maxError,
143 dtTileCacheContourSet& lcset);
144
145 dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc,
146 dtTileCacheContourSet& lcset,
147 dtTileCachePolyMesh& mesh);
148
•149 /// Swaps the endianness of the compressed tile data's header (#dtTileCacheLayerHeader).
•150 /// Tile layer data does not need endian swapping as it consist only of bytes.
151 /// @param[in,out] data The tile data array.
152 /// @param[in] dataSize The size of the data array.
153 bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize);
154
155
156 #endif // DETOURTILECACHEBUILDER_H