update recast

This commit is contained in:
Johxz 2018-02-28 22:15:31 -06:00
parent e079536122
commit 8aa48ff21b
34 changed files with 1138 additions and 407 deletions

View file

@ -29,9 +29,7 @@ template<class T> class dtFixedArray
dtTileCacheAlloc* m_alloc;
T* m_ptr;
const int m_size;
inline T* operator=(T* p);
inline void operator=(dtFixedArray<T>& p);
inline dtFixedArray();
public:
inline dtFixedArray(dtTileCacheAlloc* a, const int s) : m_alloc(a), m_ptr((T*)a->alloc(sizeof(T)*s)), m_size(s) {}
inline ~dtFixedArray() { if (m_alloc) m_alloc->free(m_ptr); }
@ -2004,6 +2002,98 @@ dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const fl
return DT_SUCCESS;
}
dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
const float* bmin, const float* bmax, const unsigned char areaId)
{
const int w = (int)layer.header->width;
const int h = (int)layer.header->height;
const float ics = 1.0f/cs;
const float ich = 1.0f/ch;
int minx = (int)floorf((bmin[0]-orig[0])*ics);
int miny = (int)floorf((bmin[1]-orig[1])*ich);
int minz = (int)floorf((bmin[2]-orig[2])*ics);
int maxx = (int)floorf((bmax[0]-orig[0])*ics);
int maxy = (int)floorf((bmax[1]-orig[1])*ich);
int maxz = (int)floorf((bmax[2]-orig[2])*ics);
if (maxx < 0) return DT_SUCCESS;
if (minx >= w) return DT_SUCCESS;
if (maxz < 0) return DT_SUCCESS;
if (minz >= h) return DT_SUCCESS;
if (minx < 0) minx = 0;
if (maxx >= w) maxx = w-1;
if (minz < 0) minz = 0;
if (maxz >= h) maxz = h-1;
for (int z = minz; z <= maxz; ++z)
{
for (int x = minx; x <= maxx; ++x)
{
const int y = layer.heights[x+z*w];
if (y < miny || y > maxy)
continue;
layer.areas[x+z*w] = areaId;
}
}
return DT_SUCCESS;
}
dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float cs, const float ch,
const float* center, const float* halfExtents, const float* rotAux, const unsigned char areaId)
{
const int w = (int)layer.header->width;
const int h = (int)layer.header->height;
const float ics = 1.0f/cs;
const float ich = 1.0f/ch;
float cx = (center[0] - orig[0])*ics;
float cz = (center[2] - orig[2])*ics;
float maxr = 1.41f*dtMax(halfExtents[0], halfExtents[2]);
int minx = (int)floorf(cx - maxr*ics);
int maxx = (int)floorf(cx + maxr*ics);
int minz = (int)floorf(cz - maxr*ics);
int maxz = (int)floorf(cz + maxr*ics);
int miny = (int)floorf((center[1]-halfExtents[1]-orig[1])*ich);
int maxy = (int)floorf((center[1]+halfExtents[1]-orig[1])*ich);
if (maxx < 0) return DT_SUCCESS;
if (minx >= w) return DT_SUCCESS;
if (maxz < 0) return DT_SUCCESS;
if (minz >= h) return DT_SUCCESS;
if (minx < 0) minx = 0;
if (maxx >= w) maxx = w-1;
if (minz < 0) minz = 0;
if (maxz >= h) maxz = h-1;
float xhalf = halfExtents[0]*ics + 0.5f;
float zhalf = halfExtents[2]*ics + 0.5f;
for (int z = minz; z <= maxz; ++z)
{
for (int x = minx; x <= maxx; ++x)
{
float x2 = 2.0f*(float(x) - cx);
float z2 = 2.0f*(float(z) - cz);
float xrot = rotAux[1]*x2 + rotAux[0]*z2;
if (xrot > xhalf || xrot < -xhalf)
continue;
float zrot = rotAux[1]*z2 - rotAux[0]*x2;
if (zrot > zhalf || zrot < -zhalf)
continue;
const int y = layer.heights[x+z*w];
if (y < miny || y > maxy)
continue;
layer.areas[x+z*w] = areaId;
}
}
return DT_SUCCESS;
}
dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
dtTileCacheLayerHeader* header,
@ -2027,7 +2117,11 @@ dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
const int bufferSize = gridSize*3;
unsigned char* buffer = (unsigned char*)dtAlloc(bufferSize, DT_ALLOC_TEMP);
if (!buffer)
{
dtFree(data);
return DT_FAILURE | DT_OUT_OF_MEMORY;
}
memcpy(buffer, heights, gridSize);
memcpy(buffer+gridSize, areas, gridSize);
memcpy(buffer+gridSize*2, cons, gridSize);
@ -2038,7 +2132,11 @@ dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
int compressedSize = 0;
dtStatus status = comp->compress(buffer, bufferSize, compressed, maxCompressedSize, &compressedSize);
if (dtStatusFailed(status))
{
dtFree(buffer);
dtFree(data);
return status;
}
*outData = data;
*outDataSize = headerSize + compressedSize;