Planeshift
DetourTileCacheBuilder.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
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';
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 
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 };
42 
44 {
46  unsigned char regCount;
47  unsigned char* heights;
48  unsigned char* areas;
49  unsigned char* cons;
50  unsigned char* regs;
51 };
52 
54 {
55  int nverts;
56  unsigned char* verts;
57  unsigned char reg;
58  unsigned char area;
59 };
60 
62 {
63  int nconts;
65 };
66 
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 };
77 
78 
80 {
81  virtual void reset()
82  {
83  }
84 
85  virtual void* alloc(const int size)
86  {
87  return dtAlloc(size, DT_ALLOC_TEMP);
88  }
89 
90  virtual void free(void* ptr)
91  {
92  dtFree(ptr);
93  }
94 };
95 
97 {
98  virtual int maxCompressedSize(const int bufferSize) = 0;
99  virtual dtStatus compress(const unsigned char* buffer, const int bufferSize,
100  unsigned char* compressed, const int maxCompressedSize, int* compressedSize) = 0;
101  virtual dtStatus decompress(const unsigned char* compressed, const int compressedSize,
102  unsigned char* buffer, const int maxBufferSize, int* bufferSize) = 0;
103 };
104 
105 
107  dtTileCacheLayerHeader* header,
108  const unsigned char* heights,
109  const unsigned char* areas,
110  const unsigned char* cons,
111  unsigned char** outData, int* outDataSize);
112 
114 
116  unsigned char* compressed, const int compressedSize,
117  dtTileCacheLayer** layerOut);
118 
121 
124 
125 dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
126  const float* pos, const float radius, const float height, const unsigned char areaId);
127 
129  dtTileCacheLayer& layer,
130  const int walkableClimb);
131 
133  dtTileCacheLayer& layer,
134  const int walkableClimb, const float maxError,
135  dtTileCacheContourSet& lcset);
136 
138  dtTileCacheContourSet& lcset,
139  dtTileCachePolyMesh& mesh);
140 
145 bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize);
146 
147 
148 #endif // DETOURTILECACHEBUILDER_H
dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc *alloc, dtTileCacheLayer &layer, const int walkableClimb)
void * dtAlloc(int size, dtAllocHint hint)
Allocates a memory block.
static const unsigned char DT_TILECACHE_NULL_AREA
virtual void * alloc(const int size)
static const unsigned char DT_TILECACHE_WALKABLE_AREA
unsigned char regCount
Region count.
dtTileCacheContourSet * dtAllocTileCacheContourSet(dtTileCacheAlloc *alloc)
static const int DT_TILECACHE_VERSION
bool dtTileCacheHeaderSwapEndian(unsigned char *data, const int dataSize)
Swaps the endianess of the compressed tile data&#39;s header (dtTileCacheLayerHeader). Tile layer data does not need endian swapping as it consits only of bytes.
unsigned int dtStatus
Definition: DetourStatus.h:22
dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc *alloc, dtTileCacheCompressor *comp, unsigned char *compressed, const int compressedSize, dtTileCacheLayer **layerOut)
dtTileCachePolyMesh * dtAllocTileCachePolyMesh(dtTileCacheAlloc *alloc)
unsigned char maxy
Usable sub-region.
unsigned char height
Dimension of the layer.
void dtFreeTileCacheLayer(dtTileCacheAlloc *alloc, dtTileCacheLayer *layer)
unsigned char * heights
dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc *alloc, dtTileCacheContourSet &lcset, dtTileCachePolyMesh &mesh)
unsigned short * polys
Polygons of the mesh, nvp*2 elements per polygon.
unsigned short * verts
Vertices of the mesh, 3 elements per vertex.
void dtFreeTileCachePolyMesh(dtTileCacheAlloc *alloc, dtTileCachePolyMesh *lmesh)
dtTileCacheLayerHeader * header
virtual void free(void *ptr)
int nverts
Number of vertices.
unsigned char * areas
Area ID of polygons.
int npolys
Number of polygons.
Memory used temporarily within a function.
Definition: DetourAlloc.h:27
dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor *comp, dtTileCacheLayerHeader *header, const unsigned char *heights, const unsigned char *areas, const unsigned char *cons, unsigned char **outData, int *outDataSize)
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)
unsigned short hmax
Height min/max range.
static const unsigned short DT_TILECACHE_NULL_IDX
unsigned short * flags
Per polygon flags.
void dtFreeTileCacheContourSet(dtTileCacheAlloc *alloc, dtTileCacheContourSet *cset)
dtStatus dtBuildTileCacheContours(dtTileCacheAlloc *alloc, dtTileCacheLayer &layer, const int walkableClimb, const float maxError, dtTileCacheContourSet &lcset)
dtTileCacheContour * conts
static const int DT_TILECACHE_MAGIC
&#39;DTLR&#39;;
void dtFree(void *ptr)
Deallocates a memory block.