text
stringlengths 0
2.2M
|
---|
}
|
// Compact ids.
|
unsigned char remap[256];
|
memset(remap, 0, 256);
|
// Find number of unique regions.
|
regId = 0;
|
for (int i = 0; i < nregs; ++i)
|
remap[regs[i].regId] = 1;
|
for (int i = 0; i < 256; ++i)
|
if (remap[i])
|
remap[i] = regId++;
|
// Remap ids.
|
for (int i = 0; i < nregs; ++i)
|
regs[i].regId = remap[regs[i].regId];
|
layer.regCount = regId;
|
for (int i = 0; i < w*h; ++i)
|
{
|
if (layer.regs[i] != 0xff)
|
layer.regs[i] = regs[layer.regs[i]].regId;
|
}
|
return DT_SUCCESS;
|
}
|
static bool appendVertex(dtTempContour& cont, const int x, const int y, const int z, const int r)
|
{
|
// Try to merge with existing segments.
|
if (cont.nverts > 1)
|
{
|
unsigned char* pa = &cont.verts[(cont.nverts-2)*4];
|
unsigned char* pb = &cont.verts[(cont.nverts-1)*4];
|
if ((int)pb[3] == r)
|
{
|
if (pa[0] == pb[0] && (int)pb[0] == x)
|
{
|
// The verts are aligned aling x-axis, update z.
|
pb[1] = (unsigned char)y;
|
pb[2] = (unsigned char)z;
|
return true;
|
}
|
else if (pa[2] == pb[2] && (int)pb[2] == z)
|
{
|
// The verts are aligned aling z-axis, update x.
|
pb[0] = (unsigned char)x;
|
pb[1] = (unsigned char)y;
|
return true;
|
}
|
}
|
}
|
// Add new point.
|
if (cont.nverts+1 > cont.cverts)
|
return false;
|
unsigned char* v = &cont.verts[cont.nverts*4];
|
v[0] = (unsigned char)x;
|
v[1] = (unsigned char)y;
|
v[2] = (unsigned char)z;
|
v[3] = (unsigned char)r;
|
cont.nverts++;
|
return true;
|
}
|
static unsigned char getNeighbourReg(dtTileCacheLayer& layer,
|
const int ax, const int ay, const int dir)
|
{
|
const int w = (int)layer.header->width;
|
const int ia = ax + ay*w;
|
const unsigned char con = layer.cons[ia] & 0xf;
|
const unsigned char portal = layer.cons[ia] >> 4;
|
const unsigned char mask = (unsigned char)(1<<dir);
|
if ((con & mask) == 0)
|
{
|
// No connection, return portal or hard edge.
|
if (portal & mask)
|
return 0xf8 + (unsigned char)dir;
|
return 0xff;
|
}
|
const int bx = ax + getDirOffsetX(dir);
|
const int by = ay + getDirOffsetY(dir);
|
const int ib = bx + by*w;
|
return layer.regs[ib];
|
}
|
static bool walkContour(dtTileCacheLayer& layer, int x, int y, dtTempContour& cont)
|
{
|
const int w = (int)layer.header->width;
|
const int h = (int)layer.header->height;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.