text
stringlengths
0
2.2M
cont.poly[j] = cont.poly[j-1];
cont.poly[i+1] = (unsigned short)maxi;
}
else
{
++i;
}
}
// Remap vertices
int start = 0;
for (int i = 1; i < cont.npoly; ++i)
if (cont.poly[i] < cont.poly[start])
start = i;
cont.nverts = 0;
for (int i = 0; i < cont.npoly; ++i)
{
const int j = (start+i) % cont.npoly;
unsigned char* src = &cont.verts[cont.poly[j]*4];
unsigned char* dst = &cont.verts[cont.nverts*4];
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
cont.nverts++;
}
}
static unsigned char getCornerHeight(dtTileCacheLayer& layer,
const int x, const int y, const int z,
const int walkableClimb,
bool& shouldRemove)
{
const int w = (int)layer.header->width;
const int h = (int)layer.header->height;
int n = 0;
unsigned char portal = 0xf;
unsigned char height = 0;
unsigned char preg = 0xff;
bool allSameReg = true;
for (int dz = -1; dz <= 0; ++dz)
{
for (int dx = -1; dx <= 0; ++dx)
{
const int px = x+dx;
const int pz = z+dz;
if (px >= 0 && pz >= 0 && px < w && pz < h)
{
const int idx = px + pz*w;
const int lh = (int)layer.heights[idx];
if (dtAbs(lh-y) <= walkableClimb && layer.areas[idx] != DT_TILECACHE_NULL_AREA)
{
height = dtMax(height, (unsigned char)lh);
portal &= (layer.cons[idx] >> 4);
if (preg != 0xff && preg != layer.regs[idx])
allSameReg = false;
preg = layer.regs[idx];
n++;
}
}
}
}
int portalCount = 0;
for (int dir = 0; dir < 4; ++dir)
if (portal & (1<<dir))
portalCount++;
shouldRemove = false;
if (n > 1 && portalCount == 1 && allSameReg)
{
shouldRemove = true;
}
return height;
}
// TODO: move this somewhere else, once the layer meshing is done.
dtStatus dtBuildTileCacheContours(dtTileCacheAlloc* alloc,
dtTileCacheLayer& layer,
const int walkableClimb, const float maxError,
dtTileCacheContourSet& lcset)
{
dtAssert(alloc);
const int w = (int)layer.header->width;
const int h = (int)layer.header->height;
lcset.nconts = layer.regCount;
lcset.conts = (dtTileCacheContour*)alloc->alloc(sizeof(dtTileCacheContour)*lcset.nconts);
if (!lcset.conts)
return DT_FAILURE | DT_OUT_OF_MEMORY;
memset(lcset.conts, 0, sizeof(dtTileCacheContour)*lcset.nconts);
// Allocate temp buffer for contour tracing.