Planeshift

DetourTileCacheBuilder.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
00003 //
00004 // This software is provided 'as-is', without any express or implied
00005 // warranty.  In no event will the authors be held liable for any damages
00006 // arising from the use of this software.
00007 // Permission is granted to anyone to use this software for any purpose,
00008 // including commercial applications, and to alter it and redistribute it
00009 // freely, subject to the following restrictions:
00010 // 1. The origin of this software must not be misrepresented; you must not
00011 //    claim that you wrote the original software. If you use this software
00012 //    in a product, an acknowledgment in the product documentation would be
00013 //    appreciated but is not required.
00014 // 2. Altered source versions must be plainly marked as such, and must not be
00015 //    misrepresented as being the original software.
00016 // 3. This notice may not be removed or altered from any source distribution.
00017 //
00018 
00019 #ifndef DETOURTILECACHEBUILDER_H
00020 #define DETOURTILECACHEBUILDER_H
00021 
00022 #include "DetourAlloc.h"
00023 #include "DetourStatus.h"
00024 
00025 static const int DT_TILECACHE_MAGIC = 'D'<<24 | 'T'<<16 | 'L'<<8 | 'R'; 
00026 static const int DT_TILECACHE_VERSION = 1;
00027 
00028 static const unsigned char DT_TILECACHE_NULL_AREA = 0;
00029 static const unsigned char DT_TILECACHE_WALKABLE_AREA = 63;
00030 static const unsigned short DT_TILECACHE_NULL_IDX = 0xffff;
00031 
00032 struct dtTileCacheLayerHeader
00033 {
00034         int magic;                                                              
00035         int version;                                                    
00036         int tx,ty,tlayer;
00037         float bmin[3], bmax[3];
00038         unsigned short hmin, hmax;                              
00039         unsigned char width, height;                    
00040         unsigned char minx, maxx, miny, maxy;   
00041 };
00042 
00043 struct dtTileCacheLayer
00044 {
00045         dtTileCacheLayerHeader* header;
00046         unsigned char regCount;                                 
00047         unsigned char* heights;
00048         unsigned char* areas;
00049         unsigned char* cons;
00050         unsigned char* regs;
00051 };
00052 
00053 struct dtTileCacheContour
00054 {
00055         int nverts;
00056         unsigned char* verts;
00057         unsigned char reg;
00058         unsigned char area;
00059 };
00060 
00061 struct dtTileCacheContourSet
00062 {
00063         int nconts;
00064         dtTileCacheContour* conts;
00065 };
00066 
00067 struct dtTileCachePolyMesh
00068 {
00069         int nvp;
00070         int nverts;                             
00071         int npolys;                             
00072         unsigned short* verts;  
00073         unsigned short* polys;  
00074         unsigned short* flags;  
00075         unsigned char* areas;   
00076 };
00077 
00078 
00079 struct dtTileCacheAlloc
00080 {
00081         virtual void reset()
00082         {
00083         }
00084         
00085         virtual void* alloc(const int size)
00086         {
00087                 return dtAlloc(size, DT_ALLOC_TEMP);
00088         }
00089         
00090         virtual void free(void* ptr)
00091         {
00092                 dtFree(ptr);
00093         }
00094 };
00095 
00096 struct dtTileCacheCompressor
00097 {
00098         virtual int maxCompressedSize(const int bufferSize) = 0;
00099         virtual dtStatus compress(const unsigned char* buffer, const int bufferSize,
00100                                                           unsigned char* compressed, const int maxCompressedSize, int* compressedSize) = 0;
00101         virtual dtStatus decompress(const unsigned char* compressed, const int compressedSize,
00102                                                                 unsigned char* buffer, const int maxBufferSize, int* bufferSize) = 0;
00103 };
00104 
00105 
00106 dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
00107                                                            dtTileCacheLayerHeader* header,
00108                                                            const unsigned char* heights,
00109                                                            const unsigned char* areas,
00110                                                            const unsigned char* cons,
00111                                                            unsigned char** outData, int* outDataSize);
00112 
00113 void dtFreeTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheLayer* layer);
00114 
00115 dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheCompressor* comp,
00116                                                                         unsigned char* compressed, const int compressedSize,
00117                                                                         dtTileCacheLayer** layerOut);
00118 
00119 dtTileCacheContourSet* dtAllocTileCacheContourSet(dtTileCacheAlloc* alloc);
00120 void dtFreeTileCacheContourSet(dtTileCacheAlloc* alloc, dtTileCacheContourSet* cset);
00121 
00122 dtTileCachePolyMesh* dtAllocTileCachePolyMesh(dtTileCacheAlloc* alloc);
00123 void dtFreeTileCachePolyMesh(dtTileCacheAlloc* alloc, dtTileCachePolyMesh* lmesh);
00124 
00125 dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
00126                                                         const float* pos, const float radius, const float height, const unsigned char areaId);
00127 
00128 dtStatus dtBuildTileCacheRegions(dtTileCacheAlloc* alloc,
00129                                                                  dtTileCacheLayer& layer,
00130                                                                  const int walkableClimb);
00131 
00132 dtStatus dtBuildTileCacheContours(dtTileCacheAlloc* alloc,
00133                                                                   dtTileCacheLayer& layer,
00134                                                                   const int walkableClimb,      const float maxError,
00135                                                                   dtTileCacheContourSet& lcset);
00136 
00137 dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc,
00138                                                                   dtTileCacheContourSet& lcset,
00139                                                                   dtTileCachePolyMesh& mesh);
00140 
00145 bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize);
00146 
00147 
00148 #endif // DETOURTILECACHEBUILDER_H