Partial checkin or tile cache endian swap.

This commit is contained in:
Mikko Mononen 2011-12-19 19:31:39 +00:00
parent 0e4a53fb0d
commit 1a66ddf71a
2 changed files with 42 additions and 0 deletions

View File

@ -136,5 +136,11 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc,
dtTileCacheContourSet& lcset, dtTileCacheContourSet& lcset,
dtTileCachePolyMesh& mesh); dtTileCachePolyMesh& mesh);
/// Swaps the endianess of the compressed tile data's header (#dtTileCacheLayerHeader).
/// Tile layer data does not need endian swapping as it consits only of bytes.
/// @param[in,out] data The tile data array.
/// @param[in] dataSize The size of the data array.
bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize);
#endif // DETOURTILECACHEBUILDER_H #endif // DETOURTILECACHEBUILDER_H

View File

@ -2103,3 +2103,39 @@ dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheCompress
return DT_SUCCESS; return DT_SUCCESS;
} }
bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize)
{
dtTileCacheLayerHeader* header = (dtTileCacheLayerHeader*)data;
int swappedMagic = DT_TILECACHE_MAGIC;
int swappedVersion = DT_TILECACHE_VERSION;
dtSwapEndian(&swappedMagic);
dtSwapEndian(&swappedVersion);
if ((header->magic != DT_TILECACHE_MAGIC || header->version != DT_TILECACHE_VERSION) &&
(header->magic != swappedMagic || header->version != swappedVersion))
{
return false;
}
dtSwapEndian(&header->magic);
dtSwapEndian(&header->version);
dtSwapEndian(&header->tx);
dtSwapEndian(&header->ty);
dtSwapEndian(&header->tlayer);
dtSwapEndian(&header->bmin[0]);
dtSwapEndian(&header->bmin[1]);
dtSwapEndian(&header->bmin[2]);
dtSwapEndian(&header->bmax[0]);
dtSwapEndian(&header->bmax[1]);
dtSwapEndian(&header->bmax[2]);
dtSwapEndian(&header->hmin);
dtSwapEndian(&header->hmax);
// width, height, minx, maxx, miny, maxy are unsigned char, no need to swap.
return true;
}