From e019de8dcd2991c00bc161ed9352c79250827403 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:19:19 +0200 Subject: [PATCH] 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. --- src/game/shared/ai_utility_shared.cpp | 2 +- .../recast/DebugUtils/Source/DetourDebugDraw.cpp | 2 +- src/thirdparty/recast/Detour/Include/DetourNavMesh.h | 5 ----- .../recast/Detour/Source/DetourNavMesh.cpp | 12 ++++++------ .../recast/Detour/Source/DetourNavMeshBuilder.cpp | 8 ++++---- .../recast/Recast/Source/RecastMeshDetail.cpp | 9 +++------ src/thirdparty/recast/Shared/Include/SharedConst.h | 7 +++++++ 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/game/shared/ai_utility_shared.cpp b/src/game/shared/ai_utility_shared.cpp index 3a7233e8..cb0f171f 100644 --- a/src/game/shared/ai_utility_shared.cpp +++ b/src/game/shared/ai_utility_shared.cpp @@ -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 && diff --git a/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp b/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp index 6dd2c996..ade01a2e 100644 --- a/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp +++ b/src/thirdparty/recast/DebugUtils/Source/DetourDebugDraw.cpp @@ -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 && diff --git a/src/thirdparty/recast/Detour/Include/DetourNavMesh.h b/src/thirdparty/recast/Detour/Include/DetourNavMesh.h index be86bbc7..0ef1118b 100644 --- a/src/thirdparty/recast/Detour/Include/DetourNavMesh.h +++ b/src/thirdparty/recast/Detour/Include/DetourNavMesh.h @@ -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 diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp index f93f6d86..3332c50d 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp @@ -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 diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp index fd3746d3..e985a395 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp @@ -630,9 +630,9 @@ static bool createPolyMeshCells(const dtNavMeshCreateParams* params, rdTempVecto const unsigned char* tris = ¶ms->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 diff --git a/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp b/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp index bde2034f..dcba543b 100644 --- a/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp +++ b/src/thirdparty/recast/Recast/Source/RecastMeshDetail.cpp @@ -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; } } diff --git a/src/thirdparty/recast/Shared/Include/SharedConst.h b/src/thirdparty/recast/Shared/Include/SharedConst.h index c37e13db..c4c90ee7 100644 --- a/src/thirdparty/recast/Shared/Include/SharedConst.h +++ b/src/thirdparty/recast/Shared/Include/SharedConst.h @@ -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