Recast: make detail triangle flags enum shared

The same constants are used between Recast and Detour, but Recast had to declare and match the constant locally as it couldn't access the one from the Detour library. This patch avoids duplicate definitions and potential issues during refactors.
This commit is contained in:
Kawe Mazidjatari 2024-09-04 16:19:19 +02:00
parent 6fa5080fe5
commit e019de8dcd
7 changed files with 22 additions and 23 deletions

View File

@ -543,7 +543,7 @@ void CAI_Utility::DrawNavMeshPolyBoundaries(const dtNavMesh* pMesh,
}
for (int m = 0, n = 2; m < 3; n = m++)
{
if ((dtGetDetailTriEdgeFlags(t[3], n) & DT_DETAIL_EDGE_BOUNDARY) == 0)
if ((dtGetDetailTriEdgeFlags(t[3], n) & RD_DETAIL_EDGE_BOUNDARY) == 0)
continue;
if (rdDistancePtLine2D(tv[n], v0, v1) < thr &&

View File

@ -207,7 +207,7 @@ static void drawPolyBoundaries(duDebugDraw* dd, const dtMeshTile* tile,
}
for (int m = 0, n = 2; m < 3; n=m++)
{
if ((dtGetDetailTriEdgeFlags(t[3], n) & DT_DETAIL_EDGE_BOUNDARY) == 0)
if ((dtGetDetailTriEdgeFlags(t[3], n) & RD_DETAIL_EDGE_BOUNDARY) == 0)
continue;
if (rdDistancePtLine2D(tv[n],v0,v1) < thr &&

View File

@ -200,11 +200,6 @@ enum dtRaycastOptions
DT_RAYCAST_USE_COSTS = 0x01, ///< Raycast should calculate movement cost along the ray and fill RaycastHit::cost
};
enum dtDetailTriEdgeFlags
{
DT_DETAIL_EDGE_BOUNDARY = 0x01, ///< Detail triangle edge is part of the poly boundary
};
/// Limit raycasting during any angle pahfinding
/// The limit is given as a multiple of the character radius

View File

@ -794,7 +794,7 @@ dtStatus dtNavMesh::connectTraverseLinks(const dtTileRef tileRef, const dtTraver
}
for (int l = 0, m = 2; l < 3; m = l++)
{
if ((dtGetDetailTriEdgeFlags(baseTri[3], m) & DT_DETAIL_EDGE_BOUNDARY) == 0)
if ((dtGetDetailTriEdgeFlags(baseTri[3], m) & RD_DETAIL_EDGE_BOUNDARY) == 0)
continue;
if (rdDistancePtLine2D(baseTriVerts[m], basePolySpos, basePolyEpos) >= detailEdgeAlignThresh ||
@ -909,7 +909,7 @@ dtStatus dtNavMesh::connectTraverseLinks(const dtTileRef tileRef, const dtTraver
else if (firstBaseTileLinkUsed && !baseTile->linkCountAvailable(2))
return DT_FAILURE | DT_OUT_OF_MEMORY;
if ((dtGetDetailTriEdgeFlags(landTri[3], s) & DT_DETAIL_EDGE_BOUNDARY) == 0)
if ((dtGetDetailTriEdgeFlags(landTri[3], s) & RD_DETAIL_EDGE_BOUNDARY) == 0)
continue;
if (rdDistancePtLine2D(landTriVerts[s], landPolySpos, landPolyEpos) >= detailEdgeAlignThresh ||
@ -1062,9 +1062,9 @@ namespace
{
const unsigned char* tris = &tile->detailTris[(pd->triBase + i) * 4];
const int ANY_BOUNDARY_EDGE =
(DT_DETAIL_EDGE_BOUNDARY << 0) |
(DT_DETAIL_EDGE_BOUNDARY << 2) |
(DT_DETAIL_EDGE_BOUNDARY << 4);
(RD_DETAIL_EDGE_BOUNDARY << 0) |
(RD_DETAIL_EDGE_BOUNDARY << 2) |
(RD_DETAIL_EDGE_BOUNDARY << 4);
if (onlyBoundary && (tris[3] & ANY_BOUNDARY_EDGE) == 0)
continue;
@ -1079,7 +1079,7 @@ namespace
for (int k = 0, j = 2; k < 3; j = k++)
{
if ((dtGetDetailTriEdgeFlags(tris[3], j) & DT_DETAIL_EDGE_BOUNDARY) == 0 &&
if ((dtGetDetailTriEdgeFlags(tris[3], j) & RD_DETAIL_EDGE_BOUNDARY) == 0 &&
(onlyBoundary || tris[j] < tris[k]))
{
// Only looking at boundary edges and this is internal, or

View File

@ -630,9 +630,9 @@ static bool createPolyMeshCells(const dtNavMeshCreateParams* params, rdTempVecto
const unsigned char* tris = &params->detailTris[(tb+l)*4];
const int ANY_BOUNDARY_EDGE =
(DT_DETAIL_EDGE_BOUNDARY << 0) |
(DT_DETAIL_EDGE_BOUNDARY << 2) |
(DT_DETAIL_EDGE_BOUNDARY << 4);
(RD_DETAIL_EDGE_BOUNDARY << 0) |
(RD_DETAIL_EDGE_BOUNDARY << 2) |
(RD_DETAIL_EDGE_BOUNDARY << 4);
if (onlyBoundary && (tris[3] & ANY_BOUNDARY_EDGE) == 0)
continue;
@ -655,7 +655,7 @@ static bool createPolyMeshCells(const dtNavMeshCreateParams* params, rdTempVecto
for (int m = 0, n = 2; m < 3; n = m++)
{
if ((dtGetDetailTriEdgeFlags(tris[3], n) & DT_DETAIL_EDGE_BOUNDARY) == 0 &&
if ((dtGetDetailTriEdgeFlags(tris[3], n) & RD_DETAIL_EDGE_BOUNDARY) == 0 &&
(onlyBoundary || tris[n] < tris[m]))
{
// Only looking at boundary edges and this is internal, or

View File

@ -735,18 +735,15 @@ static bool onHull(int a, int b, int nhull, int* hull)
// Find edges that lie on hull and mark them as such.
static void setTriFlags(rdIntArray& tris, int nhull, int* hull)
{
// Matches DT_DETAIL_EDGE_BOUNDARY
const int DETAIL_EDGE_BOUNDARY = 0x1;
for (int i = 0; i < tris.size(); i += 4)
{
int a = tris[i + 0];
int b = tris[i + 1];
int c = tris[i + 2];
unsigned short flags = 0;
flags |= (onHull(a, c, nhull, hull) ? DETAIL_EDGE_BOUNDARY : 0) << 0;
flags |= (onHull(c, b, nhull, hull) ? DETAIL_EDGE_BOUNDARY : 0) << 2;
flags |= (onHull(b, a, nhull, hull) ? DETAIL_EDGE_BOUNDARY : 0) << 4;
flags |= (onHull(a, c, nhull, hull) ? RD_DETAIL_EDGE_BOUNDARY : 0) << 0;
flags |= (onHull(c, b, nhull, hull) ? RD_DETAIL_EDGE_BOUNDARY : 0) << 2;
flags |= (onHull(b, a, nhull, hull) ? RD_DETAIL_EDGE_BOUNDARY : 0) << 4;
tris[i + 3] = (int)flags;
}
}

View File

@ -27,4 +27,11 @@ static const int RD_BITS_PER_BIT_CELL = 32;
/// @see rcPolyMesh::polys
static const unsigned short RD_MESH_NULL_IDX = 0xffff;
/// Detail triangle edge flags used for various functions and fields.
/// For an example, see dtNavMesh::connectTraverseLinks().
enum rdDetailTriEdgeFlags
{
RD_DETAIL_EDGE_BOUNDARY = 1<<0, ///< Detail triangle edge is part of the poly boundary
};
#endif // RECASTDETOURCONST_H