From e57e85b88a8d8b9868e770fbcdbf0bc6302ca98e Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 18 Jul 2024 23:58:39 +0200 Subject: [PATCH] Recast: initial implementation of jump links for off-mesh links These should set them up properly in theory. Needs testing. --- .../recast/Detour/Include/DetourNavMesh.h | 2 ++ .../recast/Detour/Source/DetourNavMesh.cpp | 35 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/thirdparty/recast/Detour/Include/DetourNavMesh.h b/src/thirdparty/recast/Detour/Include/DetourNavMesh.h index 8e6fd5ce..08fbd51f 100644 --- a/src/thirdparty/recast/Detour/Include/DetourNavMesh.h +++ b/src/thirdparty/recast/Detour/Include/DetourNavMesh.h @@ -274,6 +274,8 @@ struct dtLink unsigned short reverseLink; ///< The reverse traversal link for this link. (Path returns through this link.) }; +unsigned char dtCalcLinkDistance(const float* spos, const float* epos); + /// Bounding volume node. /// @note This structure is rarely if ever used by the end user. /// @see dtMeshTile diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp index 9aeb3de1..c30cdd9a 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMesh.cpp @@ -213,9 +213,7 @@ dtNavMesh::dtNavMesh() : m_polyBits = 0; #endif memset(&m_params, 0, sizeof(dtNavMeshParams)); - m_orig[0] = 0; - m_orig[1] = 0; - m_orig[2] = 0; + rdVset(m_orig, 0.0f,0.0f,0.0f); } dtNavMesh::~dtNavMesh() // TODO: see [r5apex_ds + F43720] to re-implement this correctly @@ -526,7 +524,7 @@ void dtNavMesh::connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int // Make sure the location is on current mesh. float* v = &target->verts[targetPoly->verts[1]*3]; rdVcopy(v, nearestPt); - + // Link off-mesh connection to target poly. unsigned int idx = allocLink(target); dtLink* link = nullptr; @@ -569,14 +567,22 @@ void dtNavMesh::connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int } } - // Set the reverse link indices if there is a possibility to reverse. - // NOTE: it appears that Titanfall 2 doesn't seem to do this on their - // navmeshes, so we probably shouldn't do it either. Commented for now. - //if (link && tlink) - //{ - // link->reverseLinkIndex = (unsigned short)tidx; - // tlink->reverseLinkIndex = (unsigned short)idx; - //} + // NOTE: this might not be correct; Titanfall 2 off-mesh link dtLink + // objects don't set these, however when setting these, the jump links + // do work. More research is needed, this might also be correct, just + // not the way they are done originally. + if (link && tlink) + { + const unsigned char linkDist = dtCalcLinkDistance(&targetCon->pos[0], &targetCon->pos[3]); + + link->traverseType = targetCon->jumpType; + link->traverseDist = linkDist; + link->reverseLink = (unsigned short)tidx; + + tlink->traverseType = targetCon->jumpType; + tlink->traverseDist = linkDist; + tlink->reverseLink = (unsigned short)idx; + } } } @@ -1731,6 +1737,11 @@ dtStatus dtNavMesh::getPolyArea(dtPolyRef ref, unsigned char* resultArea) const return DT_SUCCESS; } +unsigned char dtCalcLinkDistance(const float* spos, const float* epos) +{ + return (unsigned char)rdVdist(spos, epos) / DT_TRAVERSE_DIST_QUANT_FACTOR; +} + float dtCalcPolySurfaceArea(const dtPoly* poly, const float* verts) { float polyArea = 0.0f;