From da37f898cf8c4612917652ba690fbeffac4935b7 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:25:25 +0200 Subject: [PATCH] Recast: deduplicate XX_VERTS_PER_POLYGON constant Must be synced between Recast & Detour. --- src/naveditor/Editor_SoloMesh.cpp | 6 +- src/naveditor/Editor_TempObstacles.cpp | 4 +- src/naveditor/Editor_TileMesh.cpp | 6 +- src/naveditor/NavMeshTesterTool.cpp | 2 +- .../recast/Detour/Include/DetourNavMesh.h | 9 +- .../recast/Detour/Source/DetourNavMesh.cpp | 2 +- .../Detour/Source/DetourNavMeshBuilder.cpp | 8 +- .../Detour/Source/DetourNavMeshQuery.cpp | 22 ++-- .../Source/DetourLocalBoundary.cpp | 2 +- .../Source/DetourTileCache.cpp | 2 +- .../Source/DetourTileCacheBuilder.cpp | 119 +++++++++--------- .../recast/Shared/Include/SharedConst.h | 3 + 12 files changed, 92 insertions(+), 93 deletions(-) diff --git a/src/naveditor/Editor_SoloMesh.cpp b/src/naveditor/Editor_SoloMesh.cpp index 40df6048..426653f8 100644 --- a/src/naveditor/Editor_SoloMesh.cpp +++ b/src/naveditor/Editor_SoloMesh.cpp @@ -299,8 +299,8 @@ bool Editor_SoloMesh::handleBuild() } // (Optional) Mark areas. - const ShapeVolume* vols = m_geom->getConvexVolumes(); - for (int i = 0; i < m_geom->getConvexVolumeCount(); ++i) + const ShapeVolume* vols = m_geom->getShapeVolumes(); + for (int i = 0; i < m_geom->getShapeVolumeCount(); ++i) rcMarkConvexPolyArea(m_ctx, vols[i].verts, vols[i].nverts, vols[i].hmin, vols[i].hmax, (unsigned short)vols[i].flags, (unsigned char)vols[i].area, *m_chf); @@ -437,7 +437,7 @@ bool Editor_SoloMesh::handleBuild() const int traverseTableCount = NavMesh_GetTraverseTableCountForNavMeshType(m_selectedNavMeshType); - if (m_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON) + if (m_cfg.maxVertsPerPoly <= RD_VERTS_PER_POLYGON) { unsigned char* navData = 0; int navDataSize = 0; diff --git a/src/naveditor/Editor_TempObstacles.cpp b/src/naveditor/Editor_TempObstacles.cpp index 4a03b0ab..e2dbd75f 100644 --- a/src/naveditor/Editor_TempObstacles.cpp +++ b/src/naveditor/Editor_TempObstacles.cpp @@ -360,8 +360,8 @@ int Editor_TempObstacles::rasterizeTileLayers( } // (Optional) Mark areas. - const ShapeVolume* vols = m_geom->getConvexVolumes(); - for (int i = 0; i < m_geom->getConvexVolumeCount(); ++i) + const ShapeVolume* vols = m_geom->getShapeVolumes(); + for (int i = 0; i < m_geom->getShapeVolumeCount(); ++i) { rcMarkConvexPolyArea(m_ctx, vols[i].verts, vols[i].nverts, vols[i].hmin, vols[i].hmax, diff --git a/src/naveditor/Editor_TileMesh.cpp b/src/naveditor/Editor_TileMesh.cpp index af38f0a6..aff90077 100644 --- a/src/naveditor/Editor_TileMesh.cpp +++ b/src/naveditor/Editor_TileMesh.cpp @@ -1103,8 +1103,8 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const } // (Optional) Mark areas. - const ShapeVolume* vols = m_geom->getConvexVolumes(); - for (int i = 0; i < m_geom->getConvexVolumeCount(); ++i) + const ShapeVolume* vols = m_geom->getShapeVolumes(); + for (int i = 0; i < m_geom->getShapeVolumeCount(); ++i) { const ShapeVolume& vol = vols[i]; @@ -1244,7 +1244,7 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const unsigned char* navData = 0; int navDataSize = 0; - if (m_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON) + if (m_cfg.maxVertsPerPoly <= RD_VERTS_PER_POLYGON) { if (m_pmesh->nverts >= 0xffff) { diff --git a/src/naveditor/NavMeshTesterTool.cpp b/src/naveditor/NavMeshTesterTool.cpp index 6115fe73..7ec5d567 100644 --- a/src/naveditor/NavMeshTesterTool.cpp +++ b/src/naveditor/NavMeshTesterTool.cpp @@ -1316,7 +1316,7 @@ void NavMeshTesterTool::handleRender() dd.depthMask(true); } - static const int MAX_SEGS = DT_VERTS_PER_POLYGON*4; + static const int MAX_SEGS = RD_VERTS_PER_POLYGON*4; float segs[MAX_SEGS*6]; dtPolyRef refs[MAX_SEGS]; memset(refs, 0, sizeof(dtPolyRef)*MAX_SEGS); diff --git a/src/thirdparty/recast/Detour/Include/DetourNavMesh.h b/src/thirdparty/recast/Detour/Include/DetourNavMesh.h index 223550e0..c6bfc0f0 100644 --- a/src/thirdparty/recast/Detour/Include/DetourNavMesh.h +++ b/src/thirdparty/recast/Detour/Include/DetourNavMesh.h @@ -20,6 +20,7 @@ #define DETOURNAVMESH_H #include "Shared/Include/SharedAlloc.h" +#include "Shared/Include/SharedConst.h" #include "Detour/Include/DetourStatus.h" // NOTE: these are defines as we need to be able to switch between code that is @@ -72,10 +73,6 @@ static const int DT_FULL_UNLINKED_TILE_USER_ID = 1; /// to anything (tagged as #DT_UNLINKED_POLY_GROUP), and 1 that does link to something. static const int DT_SEMI_UNLINKED_TILE_USER_ID = 2; -/// The maximum number of vertices per navigation polygon. -/// @ingroup detour -static const int DT_VERTS_PER_POLYGON = 6; - /// A value that indicates that this poly hasn't been assigned to a group yet. static const unsigned short DT_NULL_POLY_GROUP = 0; @@ -287,10 +284,10 @@ struct dtPoly /// The indices of the polygon's vertices. /// The actual vertices are located in dtMeshTile::verts. - unsigned short verts[DT_VERTS_PER_POLYGON]; + unsigned short verts[RD_VERTS_PER_POLYGON]; /// Packed data representing neighbor polygons references and flags for each edge. - unsigned short neis[DT_VERTS_PER_POLYGON]; + unsigned short neis[RD_VERTS_PER_POLYGON]; /// The user defined polygon flags. unsigned short flags; diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp index ccc6d856..f6f8417a 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp @@ -1101,7 +1101,7 @@ bool dtNavMesh::getPolyHeight(const dtMeshTile* tile, const dtPoly* poly, const const unsigned int ip = (unsigned int)(poly - tile->polys); const dtPolyDetail* pd = &tile->detailMeshes[ip]; - float verts[DT_VERTS_PER_POLYGON*3]; + float verts[RD_VERTS_PER_POLYGON*3]; const int nv = poly->vertCount; for (int i = 0; i < nv; ++i) rdVcopy(&verts[i*3], &tile->verts[poly->verts[i]*3]); diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp index 9d1ac15f..4fdd5f53 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp @@ -181,7 +181,7 @@ static bool createBVTree(dtNavMeshCreateParams* params, rdTempVector& no BVItem& it = items[i]; it.i = i; - float polyVerts[DT_VERTS_PER_POLYGON*3]; + float polyVerts[RD_VERTS_PER_POLYGON*3]; const float* targetVert; int vertCount; @@ -552,7 +552,7 @@ static bool createPolyMeshCells(const dtNavMeshCreateParams* params, rdTempVecto const unsigned int tb = params->detailMeshes[i*4+2]; const unsigned int tc = params->detailMeshes[i*4+3]; - float polyVerts[DT_VERTS_PER_POLYGON*3]; + float polyVerts[RD_VERTS_PER_POLYGON*3]; for (int j = 0; j < nv; ++j) { @@ -713,7 +713,7 @@ static bool createPolyMeshCells(const dtNavMeshCreateParams* params, rdTempVecto /// @see dtNavMesh, dtNavMesh::addTile() bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData, int* outDataSize) { - if (params->nvp > DT_VERTS_PER_POLYGON) + if (params->nvp > RD_VERTS_PER_POLYGON) return false; if (params->vertCount >= 0xffff) return false; @@ -1265,7 +1265,7 @@ bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/) { dtPoly* p = &polys[i]; // poly->firstLink is update when tile is added, no need to swap. - for (int j = 0; j < DT_VERTS_PER_POLYGON; ++j) + for (int j = 0; j < RD_VERTS_PER_POLYGON; ++j) { rdSwapEndian(&p->verts[j]); rdSwapEndian(&p->neis[j]); diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp index ecc7aa66..a50ca19e 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp @@ -288,8 +288,8 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr // Randomly pick point on polygon. const float* v = &tile->verts[poly->verts[0]*3]; - float verts[3*DT_VERTS_PER_POLYGON]; - float areas[DT_VERTS_PER_POLYGON]; + float verts[3*RD_VERTS_PER_POLYGON]; + float areas[RD_VERTS_PER_POLYGON]; rdVcopy(&verts[0*3],v); for (int j = 1; j < poly->vertCount; ++j) { @@ -468,8 +468,8 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f // Randomly pick point on polygon. const float* v = &randomTile->verts[randomPoly->verts[0]*3]; - float verts[3*DT_VERTS_PER_POLYGON]; - float areas[DT_VERTS_PER_POLYGON]; + float verts[3*RD_VERTS_PER_POLYGON]; + float areas[RD_VERTS_PER_POLYGON]; rdVcopy(&verts[0*3],v); for (int j = 1; j < randomPoly->vertCount; ++j) { @@ -540,9 +540,9 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float* return DT_FAILURE | DT_INVALID_PARAM; // Collect vertices. - float verts[DT_VERTS_PER_POLYGON*3]; - float edged[DT_VERTS_PER_POLYGON]; - float edget[DT_VERTS_PER_POLYGON]; + float verts[RD_VERTS_PER_POLYGON*3]; + float edged[RD_VERTS_PER_POLYGON]; + float edget[RD_VERTS_PER_POLYGON]; int nv = 0; for (int i = 0; i < (int)poly->vertCount; ++i) { @@ -2094,7 +2094,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start rdVlerp(searchPos, startPos, endPos, 0.5f); searchRadSqr = rdSqr(rdVdist(startPos, endPos)/2.0f + 0.001f); - float verts[DT_VERTS_PER_POLYGON*3]; + float verts[RD_VERTS_PER_POLYGON*3]; while (nstack) { @@ -2518,7 +2518,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons } float dir[3], curPos[3], lastPos[3]; - float verts[DT_VERTS_PER_POLYGON*3+3]; + float verts[RD_VERTS_PER_POLYGON*3+3]; int n = 0; rdVcopy(curPos, startPos); @@ -3155,8 +3155,8 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float* const float radiusSqr = rdSqr(radius); - float pa[DT_VERTS_PER_POLYGON*3]; - float pb[DT_VERTS_PER_POLYGON*3]; + float pa[RD_VERTS_PER_POLYGON*3]; + float pb[RD_VERTS_PER_POLYGON*3]; dtStatus status = DT_SUCCESS; diff --git a/src/thirdparty/recast/DetourCrowd/Source/DetourLocalBoundary.cpp b/src/thirdparty/recast/DetourCrowd/Source/DetourLocalBoundary.cpp index f8a8f1a7..0897ae1b 100644 --- a/src/thirdparty/recast/DetourCrowd/Source/DetourLocalBoundary.cpp +++ b/src/thirdparty/recast/DetourCrowd/Source/DetourLocalBoundary.cpp @@ -82,7 +82,7 @@ void dtLocalBoundary::addSegment(const float dist, const float* s) void dtLocalBoundary::update(dtPolyRef ref, const float* pos, const float collisionQueryRange, dtNavMeshQuery* navquery, const dtQueryFilter* filter) { - static const int MAX_SEGS_PER_POLY = DT_VERTS_PER_POLYGON*3; + static const int MAX_SEGS_PER_POLY = RD_VERTS_PER_POLYGON*3; if (!ref) { diff --git a/src/thirdparty/recast/DetourTileCache/Source/DetourTileCache.cpp b/src/thirdparty/recast/DetourTileCache/Source/DetourTileCache.cpp index fb0bee63..a2161613 100644 --- a/src/thirdparty/recast/DetourTileCache/Source/DetourTileCache.cpp +++ b/src/thirdparty/recast/DetourTileCache/Source/DetourTileCache.cpp @@ -732,7 +732,7 @@ dtStatus dtTileCache::buildNavMeshTile(const dtCompressedTileRef ref, dtNavMesh* params.polyAreas = bc.lmesh->areas; params.polyFlags = bc.lmesh->flags; params.polyCount = bc.lmesh->npolys; - params.nvp = DT_VERTS_PER_POLYGON; + params.nvp = RD_VERTS_PER_POLYGON; params.walkableHeight = m_params.walkableHeight; params.walkableRadius = m_params.walkableRadius; params.walkableClimb = m_params.walkableClimb; diff --git a/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp b/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp index f0622bc9..390d0c37 100644 --- a/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp +++ b/src/thirdparty/recast/DetourTileCache/Source/DetourTileCacheBuilder.cpp @@ -49,7 +49,6 @@ inline int getDirOffsetY(int dir) return offset[dir&0x03]; } -static const int MAX_VERTS_PER_POLY = 6; // TODO: use the DT_VERTS_PER_POLYGON static const int MAX_REM_EDGES = 48; // TODO: make this an expression. @@ -882,7 +881,7 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc, // Based on code by Eric Lengyel from: // http://www.terathon.com/code/edges.php - const int maxEdgeCount = npolys*MAX_VERTS_PER_POLY; + const int maxEdgeCount = npolys*RD_VERTS_PER_POLYGON; dtFixedArray firstEdge(alloc, nverts + maxEdgeCount); if (!firstEdge) return false; @@ -898,12 +897,12 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc, for (int i = 0; i < npolys; ++i) { - unsigned short* t = &polys[i*MAX_VERTS_PER_POLY*2]; - for (int j = 0; j < MAX_VERTS_PER_POLY; ++j) + unsigned short* t = &polys[i*RD_VERTS_PER_POLYGON*2]; + for (int j = 0; j < RD_VERTS_PER_POLYGON; ++j) { if (t[j] == DT_TILECACHE_NULL_IDX) break; unsigned short v0 = t[j]; - unsigned short v1 = (j+1 >= MAX_VERTS_PER_POLY || t[j+1] == DT_TILECACHE_NULL_IDX) ? t[0] : t[j+1]; + unsigned short v1 = (j+1 >= RD_VERTS_PER_POLYGON || t[j+1] == DT_TILECACHE_NULL_IDX) ? t[0] : t[j+1]; if (v0 < v1) { rcEdge& edge = edges[edgeCount]; @@ -923,12 +922,12 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc, for (int i = 0; i < npolys; ++i) { - unsigned short* t = &polys[i*MAX_VERTS_PER_POLY*2]; - for (int j = 0; j < MAX_VERTS_PER_POLY; ++j) + unsigned short* t = &polys[i*RD_VERTS_PER_POLYGON*2]; + for (int j = 0; j < RD_VERTS_PER_POLYGON; ++j) { if (t[j] == DT_TILECACHE_NULL_IDX) break; unsigned short v0 = t[j]; - unsigned short v1 = (j+1 >= MAX_VERTS_PER_POLY || t[j+1] == DT_TILECACHE_NULL_IDX) ? t[0] : t[j+1]; + unsigned short v1 = (j+1 >= RD_VERTS_PER_POLYGON || t[j+1] == DT_TILECACHE_NULL_IDX) ? t[0] : t[j+1]; if (v0 > v1) { bool found = false; @@ -1048,15 +1047,15 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc, const rcEdge& e = edges[i]; if (e.poly[0] != e.poly[1]) { - unsigned short* p0 = &polys[e.poly[0]*MAX_VERTS_PER_POLY*2]; - unsigned short* p1 = &polys[e.poly[1]*MAX_VERTS_PER_POLY*2]; - p0[MAX_VERTS_PER_POLY + e.polyEdge[0]] = e.poly[1]; - p1[MAX_VERTS_PER_POLY + e.polyEdge[1]] = e.poly[0]; + unsigned short* p0 = &polys[e.poly[0]*RD_VERTS_PER_POLYGON*2]; + unsigned short* p1 = &polys[e.poly[1]*RD_VERTS_PER_POLYGON*2]; + p0[RD_VERTS_PER_POLYGON + e.polyEdge[0]] = e.poly[1]; + p1[RD_VERTS_PER_POLYGON + e.polyEdge[1]] = e.poly[0]; } else if (e.polyEdge[1] != 0xff) { - unsigned short* p0 = &polys[e.poly[0]*MAX_VERTS_PER_POLY*2]; - p0[MAX_VERTS_PER_POLY + e.polyEdge[0]] = 0x8000 | (unsigned short)e.polyEdge[1]; + unsigned short* p0 = &polys[e.poly[0]*RD_VERTS_PER_POLYGON*2]; + p0[RD_VERTS_PER_POLYGON + e.polyEdge[0]] = 0x8000 | (unsigned short)e.polyEdge[1]; } } @@ -1317,10 +1316,10 @@ static int triangulate(int n, const unsigned char* verts, unsigned short* indice static int countPolyVerts(const unsigned short* p) { - for (int i = 0; i < MAX_VERTS_PER_POLY; ++i) + for (int i = 0; i < RD_VERTS_PER_POLYGON; ++i) if (p[i] == DT_TILECACHE_NULL_IDX) return i; - return MAX_VERTS_PER_POLY; + return RD_VERTS_PER_POLYGON; } inline bool uleft(const unsigned short* a, const unsigned short* b, const unsigned short* c) @@ -1341,7 +1340,7 @@ static int getPolyMergeValue(unsigned short* pa, unsigned short* pb, const int nb = countPolyVerts(pb); // If the merged polygon would be too big, do not merge. - if (na+nb-2 > MAX_VERTS_PER_POLY) + if (na+nb-2 > RD_VERTS_PER_POLYGON) return -1; // Check if the polygons share an edge. @@ -1407,13 +1406,13 @@ static int getPolyMergeValue(unsigned short* pa, unsigned short* pb, static void mergePolys(unsigned short* pa, unsigned short* pb, int ea, int eb) { - unsigned short tmp[MAX_VERTS_PER_POLY*2]; + unsigned short tmp[RD_VERTS_PER_POLYGON*2]; const int na = countPolyVerts(pa); const int nb = countPolyVerts(pb); // Merge polygons. - memset(tmp, 0xff, sizeof(unsigned short)*MAX_VERTS_PER_POLY*2); + memset(tmp, 0xff, sizeof(unsigned short)*RD_VERTS_PER_POLYGON*2); int n = 0; // Add pa for (int i = 0; i < na-1; ++i) @@ -1422,7 +1421,7 @@ static void mergePolys(unsigned short* pa, unsigned short* pb, int ea, int eb) for (int i = 0; i < nb-1; ++i) tmp[n++] = pb[(eb+1+i) % nb]; - memcpy(pa, tmp, sizeof(unsigned short)*MAX_VERTS_PER_POLY); + memcpy(pa, tmp, sizeof(unsigned short)*RD_VERTS_PER_POLYGON); } @@ -1448,7 +1447,7 @@ static bool canRemoveVertex(dtTileCachePolyMesh& mesh, const unsigned short rem) int numRemainingEdges = 0; for (int i = 0; i < mesh.npolys; ++i) { - unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2]; + unsigned short* p = &mesh.polys[i*RD_VERTS_PER_POLYGON*2]; const int nv = countPolyVerts(p); int numRemoved = 0; int numVerts = 0; @@ -1486,7 +1485,7 @@ static bool canRemoveVertex(dtTileCachePolyMesh& mesh, const unsigned short rem) for (int i = 0; i < mesh.npolys; ++i) { - unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2]; + unsigned short* p = &mesh.polys[i*RD_VERTS_PER_POLYGON*2]; const int nv = countPolyVerts(p); // Collect edges which touches the removed vertex. @@ -1554,7 +1553,7 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem int numRemovedVerts = 0; for (int i = 0; i < mesh.npolys; ++i) { - unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2]; + unsigned short* p = &mesh.polys[i*RD_VERTS_PER_POLYGON*2]; const int nv = countPolyVerts(p); for (int j = 0; j < nv; ++j) { @@ -1572,7 +1571,7 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem for (int i = 0; i < mesh.npolys; ++i) { - unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2]; + unsigned short* p = &mesh.polys[i*RD_VERTS_PER_POLYGON*2]; const int nv = countPolyVerts(p); bool hasRem = false; for (int j = 0; j < nv; ++j) @@ -1594,9 +1593,9 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem } } // Remove the polygon. - unsigned short* p2 = &mesh.polys[(mesh.npolys-1)*MAX_VERTS_PER_POLY*2]; - memcpy(p,p2,sizeof(unsigned short)*MAX_VERTS_PER_POLY); - memset(p+MAX_VERTS_PER_POLY,0xff,sizeof(unsigned short)*MAX_VERTS_PER_POLY); + unsigned short* p2 = &mesh.polys[(mesh.npolys-1)*RD_VERTS_PER_POLYGON*2]; + memcpy(p,p2,sizeof(unsigned short)*RD_VERTS_PER_POLYGON); + memset(p+RD_VERTS_PER_POLYGON,0xff,sizeof(unsigned short)*RD_VERTS_PER_POLYGON); mesh.areas[i] = mesh.areas[mesh.npolys-1]; mesh.npolys--; --i; @@ -1615,7 +1614,7 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem // Adjust indices to match the removed vertex layout. for (int i = 0; i < mesh.npolys; ++i) { - unsigned short* p = &mesh.polys[i*MAX_VERTS_PER_POLY*2]; + unsigned short* p = &mesh.polys[i*RD_VERTS_PER_POLYGON*2]; const int nv = countPolyVerts(p); for (int j = 0; j < nv; ++j) if (p[j] > rem) p[j]--; @@ -1705,20 +1704,20 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem if (ntris > MAX_REM_EDGES) return DT_FAILURE | DT_BUFFER_TOO_SMALL; - unsigned short polys[MAX_REM_EDGES*MAX_VERTS_PER_POLY]; + unsigned short polys[MAX_REM_EDGES*RD_VERTS_PER_POLYGON]; unsigned char pareas[MAX_REM_EDGES]; // Build initial polygons. int npolys = 0; - memset(polys, 0xff, ntris*MAX_VERTS_PER_POLY*sizeof(unsigned short)); + memset(polys, 0xff, ntris*RD_VERTS_PER_POLYGON*sizeof(unsigned short)); for (int j = 0; j < ntris; ++j) { unsigned short* t = &tris[j*3]; if (t[0] != t[1] && t[0] != t[2] && t[1] != t[2]) { - polys[npolys*MAX_VERTS_PER_POLY+0] = hole[t[0]]; - polys[npolys*MAX_VERTS_PER_POLY+1] = hole[t[1]]; - polys[npolys*MAX_VERTS_PER_POLY+2] = hole[t[2]]; + polys[npolys*RD_VERTS_PER_POLYGON+0] = hole[t[0]]; + polys[npolys*RD_VERTS_PER_POLYGON+1] = hole[t[1]]; + polys[npolys*RD_VERTS_PER_POLYGON+2] = hole[t[2]]; pareas[npolys] = (unsigned char)harea[t[0]]; npolys++; } @@ -1727,7 +1726,7 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem return DT_SUCCESS; // Merge polygons. - int maxVertsPerPoly = MAX_VERTS_PER_POLY; + int maxVertsPerPoly = RD_VERTS_PER_POLYGON; if (maxVertsPerPoly > 3) { for (;;) @@ -1738,10 +1737,10 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem for (int j = 0; j < npolys-1; ++j) { - unsigned short* pj = &polys[j*MAX_VERTS_PER_POLY]; + unsigned short* pj = &polys[j*RD_VERTS_PER_POLYGON]; for (int k = j+1; k < npolys; ++k) { - unsigned short* pk = &polys[k*MAX_VERTS_PER_POLY]; + unsigned short* pk = &polys[k*RD_VERTS_PER_POLYGON]; int ea, eb; int v = getPolyMergeValue(pj, pk, mesh.verts, ea, eb); if (v > bestMergeVal) @@ -1758,10 +1757,10 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem if (bestMergeVal > 0) { // Found best, merge. - unsigned short* pa = &polys[bestPa*MAX_VERTS_PER_POLY]; - unsigned short* pb = &polys[bestPb*MAX_VERTS_PER_POLY]; + unsigned short* pa = &polys[bestPa*RD_VERTS_PER_POLYGON]; + unsigned short* pb = &polys[bestPb*RD_VERTS_PER_POLYGON]; mergePolys(pa, pb, bestEa, bestEb); - memcpy(pb, &polys[(npolys-1)*MAX_VERTS_PER_POLY], sizeof(unsigned short)*MAX_VERTS_PER_POLY); + memcpy(pb, &polys[(npolys-1)*RD_VERTS_PER_POLYGON], sizeof(unsigned short)*RD_VERTS_PER_POLYGON); pareas[bestPb] = pareas[npolys-1]; npolys--; } @@ -1777,10 +1776,10 @@ static dtStatus removeVertex(dtTileCachePolyMesh& mesh, const unsigned short rem for (int i = 0; i < npolys; ++i) { if (mesh.npolys >= maxTris) break; - unsigned short* p = &mesh.polys[mesh.npolys*MAX_VERTS_PER_POLY*2]; - memset(p,0xff,sizeof(unsigned short)*MAX_VERTS_PER_POLY*2); - for (int j = 0; j < MAX_VERTS_PER_POLY; ++j) - p[j] = polys[i*MAX_VERTS_PER_POLY+j]; + unsigned short* p = &mesh.polys[mesh.npolys*RD_VERTS_PER_POLYGON*2]; + memset(p,0xff,sizeof(unsigned short)*RD_VERTS_PER_POLYGON*2); + for (int j = 0; j < RD_VERTS_PER_POLYGON; ++j) + p[j] = polys[i*RD_VERTS_PER_POLYGON+j]; mesh.areas[mesh.npolys] = pareas[i]; mesh.npolys++; if (mesh.npolys > maxTris) @@ -1811,7 +1810,7 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, // TODO: warn about too many vertices? - mesh.nvp = MAX_VERTS_PER_POLY; + mesh.nvp = RD_VERTS_PER_POLYGON; dtFixedArray vflags(alloc, maxVertices); if (!vflags) @@ -1822,7 +1821,7 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, if (!mesh.verts) return DT_FAILURE | DT_OUT_OF_MEMORY; - mesh.polys = (unsigned short*)alloc->alloc(sizeof(unsigned short)*maxTris*MAX_VERTS_PER_POLY*2); + mesh.polys = (unsigned short*)alloc->alloc(sizeof(unsigned short)*maxTris*RD_VERTS_PER_POLYGON*2); if (!mesh.polys) return DT_FAILURE | DT_OUT_OF_MEMORY; @@ -1841,7 +1840,7 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, mesh.npolys = 0; memset(mesh.verts, 0, sizeof(unsigned short)*maxVertices*3); - memset(mesh.polys, 0xff, sizeof(unsigned short)*maxTris*MAX_VERTS_PER_POLY*2); + memset(mesh.polys, 0xff, sizeof(unsigned short)*maxTris*RD_VERTS_PER_POLYGON*2); memset(mesh.areas, 0, sizeof(unsigned char)*maxTris); unsigned short firstVert[VERTEX_BUCKET_COUNT2]; @@ -1861,7 +1860,7 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, if (!tris) return DT_FAILURE | DT_OUT_OF_MEMORY; - dtFixedArray polys(alloc, maxVertsPerCont*MAX_VERTS_PER_POLY); + dtFixedArray polys(alloc, maxVertsPerCont*RD_VERTS_PER_POLYGON); if (!polys) return DT_FAILURE | DT_OUT_OF_MEMORY; @@ -1899,15 +1898,15 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, // Build initial polygons. int npolys = 0; - memset(polys, 0xff, sizeof(unsigned short) * maxVertsPerCont * MAX_VERTS_PER_POLY); + memset(polys, 0xff, sizeof(unsigned short) * maxVertsPerCont * RD_VERTS_PER_POLYGON); for (int j = 0; j < ntris; ++j) { const unsigned short* t = &tris[j*3]; if (t[0] != t[1] && t[0] != t[2] && t[1] != t[2]) { - polys[npolys*MAX_VERTS_PER_POLY+0] = indices[t[0]]; - polys[npolys*MAX_VERTS_PER_POLY+1] = indices[t[1]]; - polys[npolys*MAX_VERTS_PER_POLY+2] = indices[t[2]]; + polys[npolys*RD_VERTS_PER_POLYGON+0] = indices[t[0]]; + polys[npolys*RD_VERTS_PER_POLYGON+1] = indices[t[1]]; + polys[npolys*RD_VERTS_PER_POLYGON+2] = indices[t[2]]; npolys++; } } @@ -1915,7 +1914,7 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, continue; // Merge polygons. - int maxVertsPerPoly =MAX_VERTS_PER_POLY ; + int maxVertsPerPoly =RD_VERTS_PER_POLYGON ; if (maxVertsPerPoly > 3) { for(;;) @@ -1926,10 +1925,10 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, for (int j = 0; j < npolys-1; ++j) { - unsigned short* pj = &polys[j*MAX_VERTS_PER_POLY]; + unsigned short* pj = &polys[j*RD_VERTS_PER_POLYGON]; for (int k = j+1; k < npolys; ++k) { - unsigned short* pk = &polys[k*MAX_VERTS_PER_POLY]; + unsigned short* pk = &polys[k*RD_VERTS_PER_POLYGON]; int ea, eb; int v = getPolyMergeValue(pj, pk, mesh.verts, ea, eb); if (v > bestMergeVal) @@ -1946,10 +1945,10 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, if (bestMergeVal > 0) { // Found best, merge. - unsigned short* pa = &polys[bestPa*MAX_VERTS_PER_POLY]; - unsigned short* pb = &polys[bestPb*MAX_VERTS_PER_POLY]; + unsigned short* pa = &polys[bestPa*RD_VERTS_PER_POLYGON]; + unsigned short* pb = &polys[bestPb*RD_VERTS_PER_POLYGON]; mergePolys(pa, pb, bestEa, bestEb); - memcpy(pb, &polys[(npolys-1)*MAX_VERTS_PER_POLY], sizeof(unsigned short)*MAX_VERTS_PER_POLY); + memcpy(pb, &polys[(npolys-1)*RD_VERTS_PER_POLYGON], sizeof(unsigned short)*RD_VERTS_PER_POLYGON); npolys--; } else @@ -1963,9 +1962,9 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc, // Store polygons. for (int j = 0; j < npolys; ++j) { - unsigned short* p = &mesh.polys[mesh.npolys*MAX_VERTS_PER_POLY*2]; - unsigned short* q = &polys[j*MAX_VERTS_PER_POLY]; - for (int k = 0; k < MAX_VERTS_PER_POLY; ++k) + unsigned short* p = &mesh.polys[mesh.npolys*RD_VERTS_PER_POLYGON*2]; + unsigned short* q = &polys[j*RD_VERTS_PER_POLYGON]; + for (int k = 0; k < RD_VERTS_PER_POLYGON; ++k) p[k] = q[k]; mesh.areas[mesh.npolys] = cont.area; mesh.npolys++; diff --git a/src/thirdparty/recast/Shared/Include/SharedConst.h b/src/thirdparty/recast/Shared/Include/SharedConst.h index c4c90ee7..9792039d 100644 --- a/src/thirdparty/recast/Shared/Include/SharedConst.h +++ b/src/thirdparty/recast/Shared/Include/SharedConst.h @@ -27,6 +27,9 @@ static const int RD_BITS_PER_BIT_CELL = 32; /// @see rcPolyMesh::polys static const unsigned short RD_MESH_NULL_IDX = 0xffff; +/// The maximum number of vertices per navigation polygon. +static const int RD_VERTS_PER_POLYGON = 6; + /// Detail triangle edge flags used for various functions and fields. /// For an example, see dtNavMesh::connectTraverseLinks(). enum rdDetailTriEdgeFlags