Recast: variable name cleanup and improve documentation

Renamed variables to accommodate the XZ -> XY change. Also fixed a dead URL to point to an archived version to maintain documentation.
This commit is contained in:
Kawe Mazidjatari 2024-07-02 00:59:17 +02:00
parent a99b9cc850
commit ad44b3f010
5 changed files with 41 additions and 58 deletions

View File

@ -1093,7 +1093,7 @@ int rcGetHeightFieldSpanCount(rcContext* context, const rcHeightfield& heightfie
/// @param[out] compactHeightfield The resulting compact heightfield. (Must be pre-allocated.)
/// @returns True if the operation completed successfully.
bool rcBuildCompactHeightfield(rcContext* context, int walkableHeight, int walkableClimb,
rcHeightfield& heightfield, rcCompactHeightfield& compactHeightfield);
const rcHeightfield& heightfield, rcCompactHeightfield& compactHeightfield);
/// Erodes the walkable area within the heightfield by the specified radius.
/// @ingroup recast
@ -1281,7 +1281,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
/// @param[out] cset The resulting contour set. (Must be pre-allocated.)
/// @param[in] buildFlags The build flags. (See: #rcBuildContoursFlags)
/// @returns True if the operation completed successfully.
bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf,
bool rcBuildContours(rcContext* ctx, const rcCompactHeightfield& chf,
float maxError, int maxEdgeLen,
rcContourSet& cset, int buildFlags = RC_CONTOUR_TESS_WALL_EDGES);

View File

@ -401,19 +401,19 @@ int rcGetHeightFieldSpanCount(rcContext* context, const rcHeightfield& heightfie
}
bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, const int walkableClimb,
rcHeightfield& heightfield, rcCompactHeightfield& compactHeightfield)
const rcHeightfield& heightfield, rcCompactHeightfield& compactHeightfield)
{
rcAssert(context);
rcScopedTimer timer(context, RC_TIMER_BUILD_COMPACTHEIGHTFIELD);
const int xSize = heightfield.width;
const int zSize = heightfield.height;
const int ySize = heightfield.height;
const int spanCount = rcGetHeightFieldSpanCount(context, heightfield);
// Fill in header.
compactHeightfield.width = xSize;
compactHeightfield.height = zSize;
compactHeightfield.height = ySize;
compactHeightfield.spanCount = spanCount;
compactHeightfield.walkableHeight = walkableHeight;
compactHeightfield.walkableClimb = walkableClimb;
@ -423,13 +423,13 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
compactHeightfield.bmax[2] += walkableHeight * heightfield.ch;
compactHeightfield.cs = heightfield.cs;
compactHeightfield.ch = heightfield.ch;
compactHeightfield.cells = (rcCompactCell*)rcAlloc(sizeof(rcCompactCell) * xSize * zSize, RC_ALLOC_PERM);
compactHeightfield.cells = (rcCompactCell*)rcAlloc(sizeof(rcCompactCell) * xSize * ySize, RC_ALLOC_PERM);
if (!compactHeightfield.cells)
{
context->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.cells' (%d)", xSize * zSize);
context->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory 'chf.cells' (%d)", xSize * ySize);
return false;
}
memset(compactHeightfield.cells, 0, sizeof(rcCompactCell) * xSize * zSize);
memset(compactHeightfield.cells, 0, sizeof(rcCompactCell) * xSize * ySize);
compactHeightfield.spans = (rcCompactSpan*)rcAlloc(sizeof(rcCompactSpan) * spanCount, RC_ALLOC_PERM);
if (!compactHeightfield.spans)
{
@ -449,7 +449,7 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
// Fill in cells and spans.
int currentCellIndex = 0;
const int numColumns = xSize * zSize;
const int numColumns = xSize * ySize;
for (int columnIndex = 0; columnIndex < numColumns; ++columnIndex)
{
const rcSpan* span = heightfield.spans[columnIndex];
@ -483,11 +483,11 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
const int MAX_LAYERS = RC_NOT_CONNECTED - 1;
int maxLayerIndex = 0;
const int zStride = xSize; // for readability
for (int z = 0; z < zSize; ++z)
for (int y = 0; y < ySize; ++y)
{
for (int x = 0; x < xSize; ++x)
{
const rcCompactCell& cell = compactHeightfield.cells[x + z * zStride];
const rcCompactCell& cell = compactHeightfield.cells[x + y * zStride];
for (int i = (int)cell.index, ni = (int)(cell.index + cell.count); i < ni; ++i)
{
rcCompactSpan& span = compactHeightfield.spans[i];
@ -496,9 +496,9 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
{
rcSetCon(span, dir, RC_NOT_CONNECTED);
const int neighborX = x + rcGetDirOffsetX(dir);
const int neighborZ = z + rcGetDirOffsetY(dir);
const int neighborZ = y + rcGetDirOffsetY(dir);
// First check that the neighbour cell is in bounds.
if (neighborX < 0 || neighborZ < 0 || neighborX >= xSize || neighborZ >= zSize)
if (neighborX < 0 || neighborZ < 0 || neighborX >= xSize || neighborZ >= ySize)
{
continue;
}

View File

@ -101,7 +101,7 @@ static int getCornerHeight(int x, int y, int i, int dir,
}
static void walkContour(int x, int y, int i,
rcCompactHeightfield& chf,
const rcCompactHeightfield& chf,
unsigned char* flags, rcIntArray& points)
{
// Choose the first non-connected edge
@ -183,16 +183,16 @@ static void walkContour(int x, int y, int i,
}
}
static float distancePtSeg(const int x, const int z,
const int px, const int pz,
static float distancePtSeg(const int x, const int y,
const int px, const int py,
const int qx, const int qz)
{
float pqx = (float)(qx - px);
float pqz = (float)(qz - pz);
float pqz = (float)(qz - py);
float dx = (float)(x - px);
float dz = (float)(z - pz);
float dy = (float)(y - py);
float d = pqx*pqx + pqz*pqz;
float t = pqx*dx + pqz*dz;
float t = pqx*dx + pqz*dy;
if (d > 0)
t /= d;
if (t < 0)
@ -201,9 +201,9 @@ static float distancePtSeg(const int x, const int z,
t = 1;
dx = px + t*pqx - x;
dz = pz + t*pqz - z;
dy = py + t*pqz - y;
return dx*dx + dz*dz;
return dx*dx + dy*dy;
}
static void simplifyContour(rcIntArray& points, rcIntArray& simplified,
@ -512,7 +512,7 @@ static bool intersectProp(const int* a, const int* b, const int* c, const int* d
}
// Returns T iff (a,b,c) are collinear and point c lies
// on the closed segement ab.
// on the closed segment ab.
static bool between(const int* a, const int* b, const int* c)
{
if (!collinear(a, b, c))
@ -541,7 +541,7 @@ static bool vequal(const int* a, const int* b)
return a[0] == b[0] && a[1] == b[1];
}
static bool intersectSegCountour(const int* d0, const int* d1, int i, int n, const int* verts)
static bool intersectSegContour(const int* d0, const int* d1, int i, int n, const int* verts)
{
// For each edge (k,k+1) of P
for (int k = 0; k < n; k++)
@ -749,7 +749,7 @@ static void mergeRegionHoles(rcContext* ctx, rcContourRegion& region)
for (int iter = 0; iter < hole->nverts; iter++)
{
// Find potential diagonals.
// The 'best' vertex must be in the cone described by 3 cosequtive vertices of the outline.
// The 'best' vertex must be in the cone described by 3 consecutive vertices of the outline.
// ..o j-1
// |
// | * best
@ -777,9 +777,9 @@ static void mergeRegionHoles(rcContext* ctx, rcContourRegion& region)
for (int j = 0; j < ndiags; j++)
{
const int* pt = &outline->verts[diags[j].vert*4];
bool intersect = intersectSegCountour(pt, corner, diags[j].vert, outline->nverts, outline->verts);
bool intersect = intersectSegContour(pt, corner, diags[j].vert, outline->nverts, outline->verts);
for (int k = i; k < region.nholes && !intersect; k++)
intersect |= intersectSegCountour(pt, corner, -1, region.holes[k].contour->nverts, region.holes[k].contour->verts);
intersect |= intersectSegContour(pt, corner, -1, region.holes[k].contour->nverts, region.holes[k].contour->verts);
if (!intersect)
{
index = diags[j].vert;
@ -820,7 +820,7 @@ static void mergeRegionHoles(rcContext* ctx, rcContourRegion& region)
/// See the #rcConfig documentation for more information on the configuration parameters.
///
/// @see rcAllocContourSet, rcCompactHeightfield, rcContourSet, rcConfig
bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf,
bool rcBuildContours(rcContext* ctx, const rcCompactHeightfield& chf,
const float maxError, const int maxEdgeLen,
rcContourSet& cset, const int buildFlags)
{

View File

@ -28,9 +28,9 @@ void rcFilterLowHangingWalkableObstacles(rcContext* context, const int walkableC
rcScopedTimer timer(context, RC_TIMER_FILTER_LOW_OBSTACLES);
const int xSize = heightfield.width;
const int zSize = heightfield.height;
const int ySize = heightfield.height;
for (int z = 0; z < zSize; ++z)
for (int y = 0; y < ySize; ++y)
{
for (int x = 0; x < xSize; ++x)
{
@ -38,7 +38,7 @@ void rcFilterLowHangingWalkableObstacles(rcContext* context, const int walkableC
bool previousWasWalkable = false;
unsigned char previousArea = RC_NULL_AREA;
for (rcSpan* span = heightfield.spans[x + z * xSize]; span != NULL; previousSpan = span, span = span->next)
for (rcSpan* span = heightfield.spans[x + y * xSize]; span != NULL; previousSpan = span, span = span->next)
{
const bool walkable = span->area != RC_NULL_AREA;
// If current span is not walkable, but there is walkable
@ -71,11 +71,11 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int
const int MAX_HEIGHT = 0xffff; // TODO (graham): Move this to a more visible constant and update usages.
// Mark border spans.
for (int z = 0; z < zSize; ++z)
for (int y = 0; y < zSize; ++y)
{
for (int x = 0; x < xSize; ++x)
{
for (rcSpan* span = heightfield.spans[x + z * xSize]; span; span = span->next)
for (rcSpan* span = heightfield.spans[x + y * xSize]; span; span = span->next)
{
// Skip non walkable spans.
if (span->area == RC_NULL_AREA)
@ -96,7 +96,7 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int
for (int direction = 0; direction < 4; ++direction)
{
int dx = x + rcGetDirOffsetX(direction);
int dy = z + rcGetDirOffsetY(direction);
int dy = y + rcGetDirOffsetY(direction);
// Skip neighbours which are out of bounds.
if (dx < 0 || dy < 0 || dx >= xSize || dy >= zSize)
{
@ -161,16 +161,16 @@ void rcFilterWalkableLowHeightSpans(rcContext* context, const int walkableHeight
rcScopedTimer timer(context, RC_TIMER_FILTER_WALKABLE);
const int xSize = heightfield.width;
const int zSize = heightfield.height;
const int ySize = heightfield.height;
const int MAX_HEIGHT = 0xffff;
// Remove walkable flag from spans which do not have enough
// space above them for the agent to stand there.
for (int z = 0; z < zSize; ++z)
for (int y = 0; y < ySize; ++y)
{
for (int x = 0; x < xSize; ++x)
{
for (rcSpan* span = heightfield.spans[x + z*xSize]; span; span = span->next)
for (rcSpan* span = heightfield.spans[x + y*xSize]; span; span = span->next)
{
const int bot = (int)(span->smax);
const int top = span->next ? (int)(span->next->smin) : MAX_HEIGHT;

View File

@ -35,7 +35,7 @@ static bool buildMeshAdjacency(unsigned short* polys, const int npolys,
const int nverts, const int vertsPerPoly)
{
// Based on code by Eric Lengyel from:
// http://www.terathon.com/code/edges.php
// https://web.archive.org/web/20080704083314/http://www.terathon.com/code/edges.php
int maxEdgeCount = npolys*vertsPerPoly;
unsigned short* firstEdge = (unsigned short*)rcAlloc(sizeof(unsigned short)*(nverts + maxEdgeCount), RC_ALLOC_TEMP);
@ -217,7 +217,7 @@ static bool intersectProp(const int* a, const int* b, const int* c, const int* d
#if REVERSE_DIRECTION
return xorb(right(a,b,c), right(a,b,d)) && xorb(right(c,d,a), right(c,d,b));
#else
return xorb(left(a, b, c), left(a, b, d)) && xorb(left(c, d, a), left(c, d, b));
return xorb(left(a,b,c), left(a,b,d)) && xorb(left(c,d,a), left(c,d,b));
#endif
}
@ -1044,27 +1044,11 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short
return true;
}
void copy_flip_poly_mesh(unsigned short* input,unsigned short *output,int max_idx)
{
//find actual vertex count
int cidx = 0;
for (int i = 0; i < max_idx; i++)
if (input[i] != 0xffff)
cidx++;
else
break;
//copy it out
for (int i = 0; i < cidx; i++)
{
output[i] = input[cidx - i-1];
}
}
/// @par
///
/// @note If the mesh data is to be used to construct a Detour navigation mesh, then the upper
/// limit must be retricted to <= #DT_VERTS_PER_POLYGON.
/// limit must be restricted to <= #DT_VERTS_PER_POLYGON.
///
/// @see rcAllocPolyMesh, rcContourSet, rcPolyMesh, rcConfig
bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMesh& mesh)
@ -1290,7 +1274,6 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
{
unsigned short* p = &mesh.polys[mesh.npolys*nvp*2];
unsigned short* q = &polys[j*nvp];
//copy_flip_poly_mesh(q, p, nvp);
for (int k = 0; k < nvp; ++k)
p[k] = q[k];
mesh.regs[mesh.npolys] = cont.reg;
@ -1507,7 +1490,7 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r
for (int j = 0; j < pmesh->nverts; ++j)
{
unsigned short* v = &pmesh->verts[j*3];
vremap[j] = addVertex(v[0]+ox, v[1] + oy, v[2],
vremap[j] = addVertex(v[0]+ox, v[1]+oy, v[2],
mesh.verts, firstVert, nextVert, mesh.nverts);
}
@ -1691,7 +1674,7 @@ void flip_neis_direction(unsigned short* arr, int count)
p[nvp+j] = 0x8000 | 3;
*/
}
void rcFlipPolyMesh(rcPolyMesh& mesh)
void rcFlipPolyMesh(rcPolyMesh& /*mesh*/)
{
#if !REVERSE_DIRECTION
for (int i = 0; i < mesh.npolys; i++)