From 66dfd140a15219d5d1dfa8c61db05bc70e4d1dbe Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 13 Mar 2026 15:12:34 +0200 Subject: [PATCH 01/31] Fix BasicVector axis typo Bug from 2a78129e which breaks polyhedron math --- src/public/mathlib/polyhedron.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/public/mathlib/polyhedron.h b/src/public/mathlib/polyhedron.h index 22859167fb..1ce75a4434 100644 --- a/src/public/mathlib/polyhedron.h +++ b/src/public/mathlib/polyhedron.h @@ -26,8 +26,8 @@ struct BasicVector { BasicVector res; res.x = x + v.x; - res.x = y + v.y; - res.x = z + v.z; + res.y = y + v.y; + res.z = z + v.z; return res; } @@ -35,8 +35,8 @@ struct BasicVector { BasicVector res; res.x = x - v.x; - res.x = y - v.y; - res.x = z - v.z; + res.y = y - v.y; + res.z = z - v.z; return res; } @@ -44,8 +44,8 @@ struct BasicVector { BasicVector res; res.x = x * v; - res.x = y * v; - res.x = z * v; + res.y = y * v; + res.z = z * v; return res; } From 758b99be291099d34a648b541a84d136a5dd9364 Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 13 Mar 2026 13:47:51 +0200 Subject: [PATCH 02/31] wip --- src/game/server/nav_generate.cpp | 22 ++ src/game/server/nav_mesh.cpp | 465 ++++++++++++++++++++++++++++++ src/game/server/nav_mesh.h | 4 + src/game/server/ndebugoverlay.cpp | 11 +- src/game/server/ndebugoverlay.h | 4 + 5 files changed, 505 insertions(+), 1 deletion(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 0282559ddf..ce085b409f 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -3437,6 +3437,16 @@ void CNavMesh::AddWalkableSeeds( void ) */ void CNavMesh::BeginGeneration( bool incremental ) { + if (!BuildBrushLaddersFromBsp()) + { + Warning("Generating brush ladders...FAIL\n"); + } + else + { + Msg( "Generating brush ladders...DONE\n" ); + } + return; + IGameEvent *event = gameeventmanager->CreateEvent( "nav_generate" ); if ( event ) { @@ -4048,6 +4058,18 @@ bool CNavMesh::UpdateGeneration( float maxTime ) m_isAnalyzed = true; } +#if 0 //def NEO + // Post-gen because we want automatic merge with the final navmesh + if (!BuildBrushLaddersFromBsp()) + { + Warning("Generating brush ladders...FAIL\n"); + } + else + { + Msg( "Generating brush ladders...DONE\n" ); + } +#endif + // generation complete! float generationTime = Plat_FloatTime() - m_generationStartTime; Msg( "Generation complete! %0.1f seconds elapsed.\n", generationTime ); diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index de1255ae73..a2579b5ce8 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -26,6 +26,12 @@ #include "tf/nav_mesh/tf_nav_area.h" #endif +#ifdef NEO +#include "mathlib/polyhedron.h" +#include "nav.h" +#include "polylib.h" +#endif + #ifdef NEXT_BOT #include "NextBot/NavMeshEntities/func_nav_prerequisite.h" #endif @@ -3230,6 +3236,465 @@ void CNavMesh::DestroyLadders( void ) m_selectedLadder = NULL; } +#ifdef NEO +namespace Neo +{ + struct MockBspHdr { + decltype(dheader_t::ident) ident; + decltype(dheader_t::version) version; + }; + + // Sanity check BSP header, version, and endianness compatibility. + // Has the side-effect of reading sizeof(Neo::MockBspHdr) into the file handle. + static bool ValidateBspHeader(FileHandle_t f) + { + static_assert(VALVE_LITTLE_ENDIAN); + + MockBspHdr hdr; + filesystem->Read(&hdr, sizeof(hdr), f); + if (hdr.ident != IDBSPHEADER) + { + CByteswap().SwapBuffer(&hdr.ident, &hdr.ident); + if (hdr.ident != IDBSPHEADER) + { + Warning("%s: invalid BSP file ident 0x%x (expected 0x%x)\n", + __FUNCTION__, hdr.ident, IDBSPHEADER); + return false; + } + else + { + Warning("%s: BSP had unsupported endianness (expected %s, was %s)\n", + __FUNCTION__, + VALVE_LITTLE_ENDIAN ? "little" : "big", + VALVE_LITTLE_ENDIAN ? "big" : "little"); + return false; + } + } + else if (hdr.version < MINBSPVERSION || hdr.version > BSPVERSION) + { + Warning("%s: unsupported BSP file version %d (expected in range %d-%d)\n", + __FUNCTION__, hdr.version, MINBSPVERSION, BSPVERSION); + return false; + } + + return true; + } + + constexpr static auto LumpHdrOffs(GameLumpId_t id) + { + auto lumpBegin = _hacky_datamap_offsetof(dheader_t, lumps); + return narrow_cast(lumpBegin + id * sizeof(lump_t)); + } + + [[nodiscard]] static bool ReadLumpHdr(GameLumpId_t id, FileHandle_t f, lump_t* out) + { + constexpr auto lumpSize = sizeof(std::remove_pointer_t); + static_assert(lumpSize > 0); + + Assert(filesystem); + Assert(f); + + const auto seekOffs = LumpHdrOffs(id); + if (seekOffs < 0) + { + Assert(false); + return false; + } + else if (seekOffs > filesystem->Size(f) + lumpSize) + { + Assert(false); + return false; + } + + filesystem->Seek(f, LumpHdrOffs(id), FILESYSTEM_SEEK_HEAD); + + const auto totalRead = filesystem->Read(out, lumpSize, f); + const bool ok = (totalRead == lumpSize); + Assert(ok); + return ok; + } + + template + [[nodiscard]] static bool ReadLump(GameLumpId_t id, FileHandle_t f, T* out, + int startLump = 0, int numLumpsToRead = 1, const lump_t* lump = {}) + { + if (numLumpsToRead == 0) + { + return true; // if they want to read nothing, that's fine I suppose + } + else + { + Assert(filesystem); + } + + if (numLumpsToRead < 0) + { + Warning("%s: Cannot read negative amount of lumps (%d)\n", __FUNCTION__, numLumpsToRead); + return false; + } + if (startLump < 0) + { + Warning("%s: Lump start position cannot be negative\n", __FUNCTION__); + return false; + } + if (!f) + { + Warning("%s: Invalid file handle\n", __FUNCTION__); + return false; + } + + lump_t hdr; + if (!ReadLumpHdr(id, f, &hdr)) + { + Warning("%s: Failed to read BSP header for lump %d\n", __FUNCTION__, id); + return false; + } + if (hdr.fileofs < 0) + { + Warning("%s: Lump hdr reported negative target lump offset %d\n", __FUNCTION__, hdr.fileofs); + return false; + } + if (hdr.filelen < 0) + { + Warning("%s: File hdr reported negative target lump length %d\n", __FUNCTION__, hdr.filelen); + return false; + } + + const auto fileTargetLumpOffset = hdr.fileofs + startLump * sizeof(T); + if (fileTargetLumpOffset <= 0) + { + Warning("%s: Expected a positive target lump offset for lump %d but got %zu\n", __FUNCTION__, id, fileTargetLumpOffset); + return false; + } + else if (fileTargetLumpOffset > std::numeric_limits::max()) + { + Warning("%s: Reading starting to read lumpid(s) of type %d from index %d would require lump offset of %zu which is >max: %d\n", + __FUNCTION__, id, fileTargetLumpOffset, std::numeric_limits::max()); + return false; + } + + const auto numLumpsAvailable = hdr.filelen / sizeof(T); + Assert(numLumpsAvailable >= 0); + + if (numLumpsToRead > numLumpsAvailable) + { + Warning("%s: Requested %d lump(s) of type %d but only %zu such lump(s) available\n", + __FUNCTION__, numLumpsToRead, id, numLumpsAvailable); + return false; + } + + const auto fileSize = filesystem->Size(f); + const auto sizeToRead = sizeof(T) * numLumpsToRead; + if (sizeToRead > std::numeric_limits::max()) + { + Warning("%s: Reading %d lumps of lumpid %d would require %zu bytes which >max: %d\n", + __FUNCTION__, numLumpsToRead, id, sizeToRead, std::numeric_limits::max()); + return false; + } + + const auto requiredSize = fileTargetLumpOffset + sizeToRead; + Assert(fileSize > 0); + Assert(requiredSize > 0); + if (fileSize < requiredSize) + { + Warning("%s: File size (%d bytes) not large enough to process %d lump(s) offset for lumpid %d (%zu bytes)\n", + __FUNCTION__, fileSize, numLumpsToRead, id, requiredSize); + return false; + } + + filesystem->Seek(f, narrow_cast(fileTargetLumpOffset), FILESYSTEM_SEEK_HEAD); + + const auto bytesReadTotal = filesystem->Read(out, narrow_cast(sizeToRead), f); + if (bytesReadTotal != sizeToRead) + { + Warning("%s: Expected to read %d bytes from %d lump(s) of type %d, but read %d bytes\n", + __FUNCTION__, sizeToRead, numLumpsToRead, id, bytesReadTotal); + return false; + } + + return true; + } + + template + [[nodiscard]] static bool ReadLump(GameLumpId_t id, FileHandle_t f, T& out, + int startLump = 0, const lump_t* lump = {}) + { + return ReadLump(id, f, &out, startLump, 1, lump); + } + + [[nodiscard]] static bool ReadBrushes(FileHandle_t f, CUtlVector& out) + { + lump_t brushHdr; + if (!ReadLumpHdr(LUMP_BRUSHES, f, &brushHdr)) + { + Warning("%s: failed to read brush lump hdr\n", __FUNCTION__); + return false; + } + const auto mapBrushCount = narrow_cast(brushHdr.filelen / sizeof(dbrush_t)); + if (mapBrushCount <= 0) + { + Warning("%s: could not find any brushes for bsp\n", __FUNCTION__); + return false; + } + else if (mapBrushCount > MAX_MAP_BRUSHES) + { + Warning("%s: map reported to contain %d brushes but max is %d\n", + __FUNCTION__, mapBrushCount, MAX_MAP_BRUSHES); + return false; + } + + out.EnsureCapacity(mapBrushCount); + dbrush_t brush; + for (int i = 0; i < mapBrushCount; ++i) + { + if (!ReadLump(LUMP_BRUSHES, f, brush, i, &brushHdr)) + { + Warning("%s: failed to read brush %d lump contents\n", __FUNCTION__, i); + return false; + } + + if (!(brush.contents & CONTENTS_LADDER)) + { + continue; + } + + if (brush.numsides < 4) + { + Warning("%s ladder brush %d reported %d numsides which is insufficient to construct a polyhedron\n", + __FUNCTION__, i, brush.numsides); + continue; + } + + if (brush.numsides > MAX_MAP_BRUSHSIDES) + { + Warning("%s ladder brush %d reported %d numsides which is more than max supported: %d\n", + __FUNCTION__, i, brush.numsides, MAX_MAP_BRUSHSIDES); + continue; + } + + out.AddToTail(brush); + } + + return true; + } + + [[nodiscard]] static bool ReadCSG(FileHandle_t f, + CUtlVector>& out) + { + CUtlVector brushes; + if (!ReadBrushes(f, brushes)) + { + return false; + } + + CUtlVector ladderSides; + CUtlVector ladderPlanes; + + out.EnsureCapacity(brushes.Count()); + Assert(out.Count() == 0); + for (const auto& brush : brushes) + { + ladderSides.SetCount(brush.numsides); + if (!Neo::ReadLump(LUMP_BRUSHSIDES, f, ladderSides.Base(), brush.firstside, brush.numsides)) + { + Warning("%s: failed to read brush sides lump contents %d - %d\n", __FUNCTION__, brush.firstside, brush.firstside + brush.numsides); + return false; + } + + ladderPlanes.Purge(); + for (int j = 0; j < ladderSides.Count(); ++j) + { + auto* storeAddr = ladderPlanes.AddToTailGetPtr(); + Assert(storeAddr); + if (!Neo::ReadLump(LUMP_PLANES, f, storeAddr, ladderSides[j].planenum)) + { + Warning("%s: failed to read plane lump contents for ladder side %d of plane num %d\n", __FUNCTION__, + j, ladderSides[j].planenum); + return false; + } + Assert(storeAddr->normal.IsValid()); + Assert(IsFinite(storeAddr->dist)); + } + Assert(ladderPlanes.Count() > 0); + + auto* nextPlanes = out.AddToTailGetPtr(); + nextPlanes->EnsureCapacity(ladderPlanes.Count()); + Assert(nextPlanes->Count() == 0); + for (const auto& p : ladderPlanes) + { + Vector4D alignedPlane{ p.normal.x, p.normal.y, p.normal.z, p.dist }; + Assert(alignedPlane.IsValid()); + nextPlanes->AddToTail(alignedPlane); + } + Assert(nextPlanes->Count() == ladderPlanes.Count()); + } + Assert(out.Count() == brushes.Count()); + + return true; + } + + [[nodiscard]] static bool LadderFromPolyhedron(const CPolyhedron* polyhedron) + { + Assert(polyhedron); + + Vector polyMins, polyMaxs, center; + for (int i = 0; i < polyhedron->iPolygonCount; ++i) + { + const auto& polygon = polyhedron->pPolygons[i]; + DevMsg("---\n\t%d POLYGON: %d\n", i, polygon.iIndexCount); + + ClearBounds(polyMins, polyMaxs); + + for (int j = 0; j < polygon.iIndexCount; ++j) + { + auto index = polygon.iFirstIndex + j; + const auto& idxLineRef = polyhedron->pIndices[index]; + const auto& pointIndices = polyhedron->pLines[idxLineRef.iLineIndex].iPointIndices; + + const Vector& linePos1 = polyhedron->pVertices[pointIndices[0]]; + const Vector& linePos2 = polyhedron->pVertices[pointIndices[1]]; + Assert(linePos1.IsValid()); + Assert(linePos2.IsValid()); + Assert(linePos1 != linePos2); + DevMsg("\t\tVERT: %f %f %f -> %f %f %f\n", + linePos1.x, linePos1.y, linePos1.z, + linePos2.x, linePos2.y, linePos2.z); + + AddPointToBounds(linePos1, polyMins, polyMaxs); + AddPointToBounds(linePos2, polyMins, polyMaxs); + + static int r = 0; + r = (r + 25) % 255; + Color color{ r,255,255,255 }; + UTIL_AddDebugLine(linePos1, linePos2, + true, false, color); + } + DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); + + center = VectorLerp(polyMins, polyMaxs, 0.5); + UTIL_AddDebugLine(center, center + (polygon.polyNormal * GenerationStepSize), true, false); + } + + return true; // TODO + } +} + +bool CNavMesh::BuildBrushLaddersFromBsp() +{ + bool ok = true; + + FileHandle_t f = {}; + CUtlVector> planesOfLadderBrushes; + + Assert(gpGlobals); + if (gpGlobals->bMapLoadFailed) + { + Warning("%s: map load failed\n", __FUNCTION__); + goto fail; + } + + char mapPath[MAX_PATH]; + Assert(!!gpGlobals->mapname && *gpGlobals->mapname.ToCStr()); + Assert(V_strlen(gpGlobals->mapname.ToCStr()) < MAX_MAP_NAME); + V_sprintf_safe(mapPath, "maps/%s.bsp", gpGlobals->mapname.ToCStr()); + if (!(mapPath || *mapPath)) + { + Warning("%s: failed to get map name\n", __FUNCTION__); + goto fail; + } + + Assert(filesystem); + if (!filesystem->FileExists(mapPath)) + { + Warning("%s: failed to locate map from filesystem: \"%s\"\n", + __FUNCTION__, mapPath); + goto fail; + } + + f = filesystem->Open(mapPath, "rb"); + if (!f) + { + Warning("%s: failed to open map file handle\n", __FUNCTION__); + goto fail; + } + + if (!Neo::ValidateBspHeader(f)) + { + goto fail; + } + + if (!Neo::ReadCSG(f, planesOfLadderBrushes)) + { + goto fail; + } + + if (planesOfLadderBrushes.Count() == 0) // no ladders? + { + goto cleanup; + } + + for (const auto& planesOfLadderBrush : planesOfLadderBrushes) + { + auto* polyhedron = GeneratePolyhedronFromPlanes( + planesOfLadderBrush.Base()->Base(), + planesOfLadderBrush.Count(), + ON_EPSILON, true); + + if (!polyhedron) + { + Assert(false); + goto fail; + } + + const bool ladderGenOk = Neo::LadderFromPolyhedron(polyhedron); + + polyhedron->Release(); + + if (!ladderGenOk) + { + Warning("%s: failed to generate ladder from polyhedron\n", __FUNCTION__); + + if (polyhedron->iVertexCount <= 0) + { + Warning("\tAdditionally, generated polyhedron reports %d sides but expected >0\n", + polyhedron->iVertexCount); + Assert(false); + continue; + } + + CUtlVectorpVertices)> vertices; + vertices.EnsureCapacity(polyhedron->iVertexCount); + for (int i = 0; i < polyhedron->iVertexCount; ++i) + { + auto** pVert = vertices.AddToTailGetPtr(); + *pVert = polyhedron->pVertices + i; + Assert(*pVert); + } + Assert(vertices.Count() == polyhedron->iVertexCount); + + CUtlString errMsg; + errMsg.Format("\t%d verts: ", polyhedron->iVertexCount); + for (const auto& vert : vertices) + { + errMsg.Format("%s [%f %f %f],", errMsg.String(), vert->x, vert->y, vert->z); + } + errMsg.SetLength(errMsg.Length() - 1); // remove final comma from the above loop + Warning("%s\n", errMsg.String()); + } + } + +cleanup: + if (f) + { + filesystem->Close(f); + } + return ok; +fail: + ok = false; + goto cleanup; +} +#endif + //-------------------------------------------------------------------------------------------------------------- /** * Strip the "analyzed" data out of all navigation areas diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index b4a665b024..94427929dc 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -1213,6 +1213,10 @@ class CNavMesh : public CGameEventListener NavLadderVector m_ladders; // list of ladder navigation representations void BuildLadders( void ); void DestroyLadders( void ); +#ifdef NEO + // Build ladders from the BSP brush lump ladders (rather than func_ladder) + [[nodiscard]] bool BuildBrushLaddersFromBsp(); +#endif bool SampleStep( void ); // sample the walkable areas of the map void CreateNavAreasFromNodes( void ); // cover all of the sampled nodes with nav areas diff --git a/src/game/server/ndebugoverlay.cpp b/src/game/server/ndebugoverlay.cpp index fa152ba3fc..87a72f0d6a 100644 --- a/src/game/server/ndebugoverlay.cpp +++ b/src/game/server/ndebugoverlay.cpp @@ -66,7 +66,11 @@ OverlayLine_t* GetDebugOverlayLine(void) // Input : If testLOS is true, color is based on line of sight test // Output : //----------------------------------------------------------------------------- +#ifdef NEO +void UTIL_AddDebugLine(const Vector &startPos, const Vector &endPos, bool noDepthTest, bool testLOS, const Color& color) +#else void UTIL_AddDebugLine(const Vector &startPos, const Vector &endPos, bool noDepthTest, bool testLOS) +#endif { OverlayLine_t* debugLine = GetDebugOverlayLine(); @@ -87,10 +91,15 @@ void UTIL_AddDebugLine(const Vector &startPos, const Vector &endPos, bool noDept return; } } - +#ifdef NEO + debugLine->r = color.r(); + debugLine->g = color.g(); + debugLine->b = color.b(); +#else debugLine->r = 255; debugLine->g = 255; debugLine->b = 255; +#endif } //----------------------------------------------------------------------------- diff --git a/src/game/server/ndebugoverlay.h b/src/game/server/ndebugoverlay.h index 7b0a64a9d3..2a68d7e15c 100644 --- a/src/game/server/ndebugoverlay.h +++ b/src/game/server/ndebugoverlay.h @@ -25,7 +25,11 @@ struct OverlayLine_t bool draw; }; +#ifdef NEO +extern void UTIL_AddDebugLine( const Vector &startPos, const Vector &endPos, bool noDepthTest, bool testLOS, const Color& color={255,255,255,255}); +#else extern void UTIL_AddDebugLine( const Vector &startPos, const Vector &endPos, bool noDepthTest, bool testLOS ); +#endif extern void UTIL_DrawPositioningOverlay( float flCrossDistance ); extern void UTIL_DrawOverlayLines( void ); From a35a1c81c86c058de5175e0eaf819fc640c7563e Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 13 Mar 2026 19:39:03 +0200 Subject: [PATCH 03/31] default-disable debug short-circuit --- src/game/server/nav_generate.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index ce085b409f..a2aa575447 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -25,6 +25,9 @@ // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" +#ifdef NEO +#define LADDER_BRUSH_GEN_DEBUG false // Don't enable this unless you need to debug the ladder brush autogen +#endif enum { MAX_BLOCKED_AREAS = 256 }; static unsigned int blockedID[ MAX_BLOCKED_AREAS ]; @@ -3437,6 +3440,8 @@ void CNavMesh::AddWalkableSeeds( void ) */ void CNavMesh::BeginGeneration( bool incremental ) { +#ifdef NEO +#if LADDER_BRUSH_GEN_DEBUG // Fast debug path while skipping the other nav stuff. Don't enable this expect for ladder debug! if (!BuildBrushLaddersFromBsp()) { Warning("Generating brush ladders...FAIL\n"); @@ -3446,6 +3451,8 @@ void CNavMesh::BeginGeneration( bool incremental ) Msg( "Generating brush ladders...DONE\n" ); } return; +#endif +#endif IGameEvent *event = gameeventmanager->CreateEvent( "nav_generate" ); if ( event ) @@ -4058,7 +4065,8 @@ bool CNavMesh::UpdateGeneration( float maxTime ) m_isAnalyzed = true; } -#if 0 //def NEO +#ifdef NEO +#if !(LADDER_BRUSH_GEN_DEBUG) // Post-gen because we want automatic merge with the final navmesh if (!BuildBrushLaddersFromBsp()) { @@ -4068,6 +4076,7 @@ bool CNavMesh::UpdateGeneration( float maxTime ) { Msg( "Generating brush ladders...DONE\n" ); } +#endif #endif // generation complete! From 6384d0767900b3d23cd1ca058c57820ca59d7286 Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 13 Mar 2026 19:39:53 +0200 Subject: [PATCH 04/31] refactor --- src/game/server/nav_mesh.cpp | 78 ++++++++++++++++++------------------ src/game/server/nav_mesh.h | 2 + 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index a2579b5ce8..0cad3f2d00 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3532,51 +3532,53 @@ namespace Neo return true; } +} - [[nodiscard]] static bool LadderFromPolyhedron(const CPolyhedron* polyhedron) - { - Assert(polyhedron); - - Vector polyMins, polyMaxs, center; - for (int i = 0; i < polyhedron->iPolygonCount; ++i) - { - const auto& polygon = polyhedron->pPolygons[i]; - DevMsg("---\n\t%d POLYGON: %d\n", i, polygon.iIndexCount); +[[nodiscard]] bool CNavMesh::LadderFromPolyhedron(const CPolyhedron* polyhedron) +{ + Assert(polyhedron); - ClearBounds(polyMins, polyMaxs); + Vector polyMins, polyMaxs, center; + for (int i = 0; i < polyhedron->iPolygonCount; ++i) + { + const auto& polygon = polyhedron->pPolygons[i]; + DevMsg("---\n\t%d POLYGON: %d\n", i, polygon.iIndexCount); - for (int j = 0; j < polygon.iIndexCount; ++j) - { - auto index = polygon.iFirstIndex + j; - const auto& idxLineRef = polyhedron->pIndices[index]; - const auto& pointIndices = polyhedron->pLines[idxLineRef.iLineIndex].iPointIndices; - - const Vector& linePos1 = polyhedron->pVertices[pointIndices[0]]; - const Vector& linePos2 = polyhedron->pVertices[pointIndices[1]]; - Assert(linePos1.IsValid()); - Assert(linePos2.IsValid()); - Assert(linePos1 != linePos2); - DevMsg("\t\tVERT: %f %f %f -> %f %f %f\n", - linePos1.x, linePos1.y, linePos1.z, - linePos2.x, linePos2.y, linePos2.z); - - AddPointToBounds(linePos1, polyMins, polyMaxs); - AddPointToBounds(linePos2, polyMins, polyMaxs); - - static int r = 0; - r = (r + 25) % 255; - Color color{ r,255,255,255 }; - UTIL_AddDebugLine(linePos1, linePos2, - true, false, color); - } - DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); + ClearBounds(polyMins, polyMaxs); - center = VectorLerp(polyMins, polyMaxs, 0.5); - UTIL_AddDebugLine(center, center + (polygon.polyNormal * GenerationStepSize), true, false); + for (int j = 0; j < polygon.iIndexCount; ++j) + { + auto index = polygon.iFirstIndex + j; + const auto& idxLineRef = polyhedron->pIndices[index]; + const auto& pointIndices = polyhedron->pLines[idxLineRef.iLineIndex].iPointIndices; + + const Vector& linePos1 = polyhedron->pVertices[pointIndices[0]]; + const Vector& linePos2 = polyhedron->pVertices[pointIndices[1]]; + Assert(linePos1.IsValid()); + Assert(linePos2.IsValid()); + Assert(linePos1 != linePos2); + DevMsg("\t\tVERT: %f %f %f -> %f %f %f\n", + linePos1.x, linePos1.y, linePos1.z, + linePos2.x, linePos2.y, linePos2.z); + + AddPointToBounds(linePos1, polyMins, polyMaxs); + AddPointToBounds(linePos2, polyMins, polyMaxs); + + static int r = 0; + r = (r + 25) % 255; + Color color{ r,255,255,255 }; + UTIL_AddDebugLine(linePos1, linePos2, + true, false, color); } + DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); + + center = VectorLerp(polyMins, polyMaxs, 0.5); + UTIL_AddDebugLine(center, center + (polygon.polyNormal * GenerationStepSize), true, false); return true; // TODO } + + return true; } bool CNavMesh::BuildBrushLaddersFromBsp() @@ -3646,7 +3648,7 @@ bool CNavMesh::BuildBrushLaddersFromBsp() goto fail; } - const bool ladderGenOk = Neo::LadderFromPolyhedron(polyhedron); + const bool ladderGenOk = LadderFromPolyhedron(polyhedron); polyhedron->Release(); diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index 94427929dc..40da4189c4 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -1216,6 +1216,8 @@ class CNavMesh : public CGameEventListener #ifdef NEO // Build ladders from the BSP brush lump ladders (rather than func_ladder) [[nodiscard]] bool BuildBrushLaddersFromBsp(); +private: + [[nodiscard]] bool LadderFromPolyhedron(const CPolyhedron* polyhedron); #endif bool SampleStep( void ); // sample the walkable areas of the map From 79e11e8a1b5843fa8b7d46d24ef91f3103e8670c Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 13 Mar 2026 19:40:05 +0200 Subject: [PATCH 05/31] wip: auto-generate brush ladders --- src/game/server/nav_mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 0cad3f2d00..9c887f7dce 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3575,7 +3575,7 @@ namespace Neo center = VectorLerp(polyMins, polyMaxs, 0.5); UTIL_AddDebugLine(center, center + (polygon.polyNormal * GenerationStepSize), true, false); - return true; // TODO + CreateLadder(polyMins, polyMaxs, HumanHeight); } return true; From 771034f33898bc62869575cc569ffe430e666e4a Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 13 Mar 2026 20:42:40 +0200 Subject: [PATCH 06/31] Fix format specifier typos --- src/game/server/nav_mesh.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 9c887f7dce..af0b1d570e 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3368,8 +3368,8 @@ namespace Neo } else if (fileTargetLumpOffset > std::numeric_limits::max()) { - Warning("%s: Reading starting to read lumpid(s) of type %d from index %d would require lump offset of %zu which is >max: %d\n", - __FUNCTION__, id, fileTargetLumpOffset, std::numeric_limits::max()); + Warning("%s: Starting to read lumpid(s) of type %d from index %d would require lump offset of %zu which is >max: %d\n", + __FUNCTION__, id, startLump, fileTargetLumpOffset, std::numeric_limits::max()); return false; } @@ -3407,7 +3407,7 @@ namespace Neo const auto bytesReadTotal = filesystem->Read(out, narrow_cast(sizeToRead), f); if (bytesReadTotal != sizeToRead) { - Warning("%s: Expected to read %d bytes from %d lump(s) of type %d, but read %d bytes\n", + Warning("%s: Expected to read %zu bytes from %d lump(s) of type %d, but read %d bytes\n", __FUNCTION__, sizeToRead, numLumpsToRead, id, bytesReadTotal); return false; } From 72c6ae874ead0a048516b0827271e2f26f140358 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 07:57:39 +0200 Subject: [PATCH 07/31] Refactor --- src/game/server/nav_generate.cpp | 46 ++++++++++++++------------- src/game/server/nav_mesh.cpp | 54 +++++++++++++++++++++++++------- src/game/server/nav_mesh.h | 3 ++ 3 files changed, 71 insertions(+), 32 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index a2aa575447..2b07cf56d6 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -22,12 +22,13 @@ #include "func_simpleladder.h" #endif +#ifdef NEO +#include "nav_mesh.h" +#endif + // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" -#ifdef NEO -#define LADDER_BRUSH_GEN_DEBUG false // Don't enable this unless you need to debug the ladder brush autogen -#endif enum { MAX_BLOCKED_AREAS = 256 }; static unsigned int blockedID[ MAX_BLOCKED_AREAS ]; @@ -3441,17 +3442,18 @@ void CNavMesh::AddWalkableSeeds( void ) void CNavMesh::BeginGeneration( bool incremental ) { #ifdef NEO -#if LADDER_BRUSH_GEN_DEBUG // Fast debug path while skipping the other nav stuff. Don't enable this expect for ladder debug! - if (!BuildBrushLaddersFromBsp()) + if (nav_generate_debug_brushladders.GetBool()) { - Warning("Generating brush ladders...FAIL\n"); - } - else - { - Msg( "Generating brush ladders...DONE\n" ); + if (!BuildBrushLaddersFromBsp()) + { + Warning("Generating brush ladders...FAIL\n"); + } + else + { + Msg( "Generating brush ladders...DONE\n" ); + } + return; } - return; -#endif #endif IGameEvent *event = gameeventmanager->CreateEvent( "nav_generate" ); @@ -4066,17 +4068,19 @@ bool CNavMesh::UpdateGeneration( float maxTime ) } #ifdef NEO -#if !(LADDER_BRUSH_GEN_DEBUG) - // Post-gen because we want automatic merge with the final navmesh - if (!BuildBrushLaddersFromBsp()) - { - Warning("Generating brush ladders...FAIL\n"); - } - else + // This runs earlier during the generation for the debug==true case, so skip here. + if (!nav_generate_debug_brushladders.GetBool()) { - Msg( "Generating brush ladders...DONE\n" ); + // Post-gen because we want automatic merge with the final navmesh + if (!BuildBrushLaddersFromBsp()) + { + Warning("Generating brush ladders...FAIL\n"); + } + else + { + Msg( "Generating brush ladders...DONE\n" ); + } } -#endif #endif // generation complete! diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index af0b1d570e..a41bd23e54 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -41,8 +41,15 @@ // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" - +#ifdef NEO +static auto DrawLine(const Vector& from, const Vector& to, float duration = NDEBUG_PERSIST_TILL_NEXT_SERVER, + int r = 255, int g=255, int b=255) +{ + return NDebugOverlay::Line(from, to, r, g, b, true, duration); +} +#else #define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ) +#endif /** @@ -62,6 +69,12 @@ ConVar nav_max_vis_delta_list_length( "nav_max_vis_delta_list_length", "64", FCV extern ConVar nav_show_potentially_visible; +#ifdef NEO +ConVar nav_generate_debug_brushladders("nav_generate_debug_brushladders", "0", FCVAR_CHEAT, + "If non-zero, will only visualize ladder brush generation during nav_generate and do nothing else. " + "The visualization will remain visible for the amount of seconds specified by cvar value.", + true, false, false, 0); +#endif bool FindGroundForNode( Vector *pos, Vector *normal ); @@ -3538,6 +3551,11 @@ namespace Neo { Assert(polyhedron); + if (nav_generate_debug_brushladders.GetBool()) + { + Assert(debugoverlay); + } + Vector polyMins, polyMaxs, center; for (int i = 0; i < polyhedron->iPolygonCount; ++i) { @@ -3557,23 +3575,37 @@ namespace Neo Assert(linePos1.IsValid()); Assert(linePos2.IsValid()); Assert(linePos1 != linePos2); - DevMsg("\t\tVERT: %f %f %f -> %f %f %f\n", - linePos1.x, linePos1.y, linePos1.z, - linePos2.x, linePos2.y, linePos2.z); AddPointToBounds(linePos1, polyMins, polyMaxs); AddPointToBounds(linePos2, polyMins, polyMaxs); - static int r = 0; - r = (r + 25) % 255; - Color color{ r,255,255,255 }; - UTIL_AddDebugLine(linePos1, linePos2, - true, false, color); + if (nav_generate_debug_brushladders.GetBool()) + { + DevMsg("\t\tLINE: %f %f %f -> %f %f %f\n", + linePos1.x, linePos1.y, linePos1.z, + linePos2.x, linePos2.y, linePos2.z); + + static int r = 0; + r = (r + 25) % 255; + DrawLine(linePos1, linePos2, + nav_generate_debug_brushladders.GetFloat(), r, 255, 255); + } } - DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); center = VectorLerp(polyMins, polyMaxs, 0.5); - UTIL_AddDebugLine(center, center + (polygon.polyNormal * GenerationStepSize), true, false); + + if (nav_generate_debug_brushladders.GetBool()) + { + DevMsg("\t\tPOLY NORMAL: %f %f %f\n", + polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); + const Color c = COLOR_BLUE; + DrawLine(center, center + (polygon.polyNormal * GenerationStepSize), + nav_generate_debug_brushladders.GetFloat(), c.r(), c.g(), c.b()); + + continue; + } + + // TODO: filter CreateLadder(polyMins, polyMaxs, HumanHeight); } diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index 40da4189c4..74e794126c 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -36,6 +36,9 @@ extern ConVar nav_edit; extern ConVar nav_quicksave; extern ConVar nav_show_approach_points; extern ConVar nav_show_danger; +#ifdef NEO +extern ConVar nav_generate_debug_brushladders; +#endif //-------------------------------------------------------------------------------------------------------- class NavAreaCollector From 764aedfe255270c5c2489ac72eb84aeaf75844a3 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 09:46:45 +0200 Subject: [PATCH 08/31] Improve debug --- src/game/server/nav_mesh.cpp | 83 ++++++++++++++++++++++++++++++++++-- src/game/shared/shareddefs.h | 3 ++ 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index a41bd23e54..fbe79ca8e3 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3557,9 +3557,24 @@ namespace Neo } Vector polyMins, polyMaxs, center; + trace_t tr; for (int i = 0; i < polyhedron->iPolygonCount; ++i) { const auto& polygon = polyhedron->pPolygons[i]; +#ifdef DBGFLAG_ASSERT + { + const Vector dbgVec{ polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z }; + Assert(dbgVec.IsValid()); + Assert(!dbgVec.IsZero()); + AssertFloatEquals(dbgVec.Length(), 1.f, 0.01f); // unit vector + } +#endif + // Can't build up/down facing ladder mounting points, skip + if (!polygon.polyNormal.x && !polygon.polyNormal.y) + { + continue; + } + DevMsg("---\n\t%d POLYGON: %d\n", i, polygon.iIndexCount); ClearBounds(polyMins, polyMaxs); @@ -3591,21 +3606,83 @@ namespace Neo nav_generate_debug_brushladders.GetFloat(), r, 255, 255); } } - center = VectorLerp(polyMins, polyMaxs, 0.5); + enum LadderPolyFilterReason { + ThisIsFine = 0, // No problems detected, do not filter this poly. + TooSlim, // At least one of the dimensions of this 2D poly is unacceptably slim for bot navigation. + TooCramped, // Insufficient nav clearance for bots to meaningfully mount here. + } filter = ThisIsFine; + + // Ignore ladder polygons that are super slim, because it's likely either a side + // or a bevel of the actual intended mounting point. + // While such surfaces *could* sometimes be used by humans, they require a lot of + // finesse to meaningfully traverse, so it's better for the bots to prefer the obvious + // large mapper-intended primary climb surfaces. Of course, the mapper could opt + // to manually markup their custom slim ladders as usual outside the auto-gen. + constexpr float smallestLadderDimToConsider = 4; + int nSmaller = 0; + nSmaller += (polyMaxs.x - polyMins.x < smallestLadderDimToConsider); + nSmaller += (polyMaxs.y - polyMins.y < smallestLadderDimToConsider); + nSmaller += (polyMaxs.z - polyMins.z < smallestLadderDimToConsider); + + // Because the poly mins/maxs are modeling a 2D surface, it is expected for + // one of the dimensions to be 0 or near 0. But if 2 or more are below + // smallestLadderDimToConsider, then we do want to filter. + if (nSmaller > 1) + { + filter = TooSlim; + } + + if (filter == ThisIsFine) + { + // Cull ladder sides facing the wall etc. + // Need clearance of at least GenerationStepSize in front of the ladder to mount. + UTIL_TraceLine( + center + (polygon.polyNormal * ON_EPSILON), + center + (polygon.polyNormal * GenerationStepSize), + MASK_PLAYERSOLID_BRUSHONLY, NULL, COLLISION_GROUP_NONE, &tr); + if (tr.DidHit()) + { + filter = TooCramped; + } + } + if (nav_generate_debug_brushladders.GetBool()) { + Color c; + switch (filter) + { + case ThisIsFine: + c = COLOR_LIME; + break; + case TooSlim: + c = COLOR_DARK_ORANGE; + break; + case TooCramped: + c = COLOR_NEON_PINK; + break; + default: + c = COLOR_BLACK; + Assert(false); + break; + } DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); - const Color c = COLOR_BLUE; + if (filter != ThisIsFine) + { + DevMsg("\t\t\tREJECTED! enum: %d\n", filter); + } DrawLine(center, center + (polygon.polyNormal * GenerationStepSize), nav_generate_debug_brushladders.GetFloat(), c.r(), c.g(), c.b()); + } + if (filter) + { continue; } - // TODO: filter + continue; // TODO: debug CreateLadder(polyMins, polyMaxs, HumanHeight); } diff --git a/src/game/shared/shareddefs.h b/src/game/shared/shareddefs.h index b290d6486e..e0ad452dd3 100644 --- a/src/game/shared/shareddefs.h +++ b/src/game/shared/shareddefs.h @@ -628,6 +628,9 @@ typedef enum #define COLOR_TRANSPARENT Color(0, 0, 0, 0) #define COLOR_DARK Color(55, 55, 55, 255) #define COLOR_FADED_DARK Color(55, 55, 55, 176) +#define COLOR_NEON_PINK Color(255, 16, 240) +#define COLOR_DARK_ORANGE Color(255, 140, 0) +#define COLOR_LIME Color(0, 255, 0) #endif // All NPCs need this data From 675af8a06d3f5f4532959a92062171d668dbb4cb Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 09:46:57 +0200 Subject: [PATCH 09/31] Make GenerationStepSize constexpr --- src/game/server/nav.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/nav.h b/src/game/server/nav.h index 35899935e4..bb09068c59 100644 --- a/src/game/server/nav.h +++ b/src/game/server/nav.h @@ -24,7 +24,7 @@ */ #ifdef NEO -const float GenerationStepSize = 20.0f; // NEO: some hallways/openings were missing connections with larger value +constexpr float GenerationStepSize = 20.0f; // NEO: some hallways/openings were missing connections with larger value #else const float GenerationStepSize = 25.0f; // (30) was 20, but bots can't fit always fit #endif From dd203625ff96362c0fda7bab1a8a7b856388d042 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 09:51:29 +0200 Subject: [PATCH 10/31] refactor --- src/game/server/nav_mesh.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index fbe79ca8e3..90222131ad 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3669,22 +3669,20 @@ namespace Neo } DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); - if (filter != ThisIsFine) - { - DevMsg("\t\t\tREJECTED! enum: %d\n", filter); - } DrawLine(center, center + (polygon.polyNormal * GenerationStepSize), nav_generate_debug_brushladders.GetFloat(), c.r(), c.g(), c.b()); } - if (filter) + if (filter != ThisIsFine) { + if (nav_generate_debug_brushladders.GetBool()) + { + DevMsg("\t\tREJECTED! enum: %d\n", filter); + } continue; } - continue; // TODO: debug - - CreateLadder(polyMins, polyMaxs, HumanHeight); + //CreateLadder(polyMins, polyMaxs, HumanHeight); } return true; From d1e2219b0f08c50e827c2281ec54e76243772e8e Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 09:52:42 +0200 Subject: [PATCH 11/31] CreateLadder for !nav_generate_debug_brushladders runs --- src/game/server/nav_mesh.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 90222131ad..0e2f59ae14 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3682,7 +3682,11 @@ namespace Neo continue; } - //CreateLadder(polyMins, polyMaxs, HumanHeight); + // Create for real only if we're not debugging this logic + if (!nav_generate_debug_brushladders.GetBool()) + { + CreateLadder(polyMins, polyMaxs, HumanHeight); + } } return true; From ee13d3f072604f795ca26b7cb601fa48898241a4 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 15:35:47 +0200 Subject: [PATCH 12/31] wip: Fix ladder generation for slanted angles --- src/game/server/nav_mesh.cpp | 44 ++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 0e2f59ae14..defe7468a5 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3556,6 +3556,11 @@ namespace Neo Assert(debugoverlay); } + decltype(m_surfaceNormal) backup_m_surfaceNormal; + decltype(m_editCursorPos) backup_m_editCursorPos; + decltype(m_editMode) backup_m_editMode; + decltype(m_climbableSurface) backup_m_climbableSurface; + Vector polyMins, polyMaxs, center; trace_t tr; for (int i = 0; i < polyhedron->iPolygonCount; ++i) @@ -3683,9 +3688,44 @@ namespace Neo } // Create for real only if we're not debugging this logic - if (!nav_generate_debug_brushladders.GetBool()) + if (nav_generate_debug_brushladders.GetBool()) + { + continue; + } + + // NEO JANK (Rain): manipulate edit mode state to fake a ladder build. + // Should probs just make our own version of the function to clean this up. { - CreateLadder(polyMins, polyMaxs, HumanHeight); + // Backup state + { + backup_m_surfaceNormal = m_surfaceNormal; + backup_m_editCursorPos = m_editCursorPos; + backup_m_editMode = m_editMode; + backup_m_climbableSurface = m_climbableSurface; + } + // Overwrite the state in preparetion for CommandNavBuildLadder + { + m_editCursorPos = center; + m_surfaceNormal = Vector{ + polygon.polyNormal.x, + polygon.polyNormal.y, + polygon.polyNormal.z }; + m_editMode = EditModeType::NORMAL; + m_climbableSurface = true; + } + // The state-dependent ladder build call + { + CommandNavBuildLadder(); + } + // Finally, restore state + { + m_editMode = backup_m_editMode; + m_editCursorPos = backup_m_editCursorPos; + m_surfaceNormal = backup_m_surfaceNormal; + m_climbableSurface = backup_m_climbableSurface; + } + + //CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f ); } } From 1597841c73398bc17ad63a2b194520e3a08aecd1 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 17:31:58 +0200 Subject: [PATCH 13/31] refactor --- src/game/server/nav_mesh.cpp | 53 ++++++++++-------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index defe7468a5..5c05e0289a 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3556,12 +3556,12 @@ namespace Neo Assert(debugoverlay); } - decltype(m_surfaceNormal) backup_m_surfaceNormal; - decltype(m_editCursorPos) backup_m_editCursorPos; - decltype(m_editMode) backup_m_editMode; - decltype(m_climbableSurface) backup_m_climbableSurface; + // To be used for the center position of each polygon of the polyhedron. + // By reference, because the final CommandNavBuildLadder call which actually builds the ladder + // depends on this state, and we can spare the extra Vector by just assigning to it directly. + Vector& center = m_editCursorPos; - Vector polyMins, polyMaxs, center; + Vector polyMins, polyMaxs; trace_t tr; for (int i = 0; i < polyhedron->iPolygonCount; ++i) { @@ -3580,7 +3580,10 @@ namespace Neo continue; } - DevMsg("---\n\t%d POLYGON: %d\n", i, polygon.iIndexCount); + if (nav_generate_debug_brushladders.GetBool()) + { + DevMsg("---\n\t%d POLYGON: %d\n", i, polygon.iIndexCount); + } ClearBounds(polyMins, polyMaxs); @@ -3693,40 +3696,12 @@ namespace Neo continue; } - // NEO JANK (Rain): manipulate edit mode state to fake a ladder build. - // Should probs just make our own version of the function to clean this up. - { - // Backup state - { - backup_m_surfaceNormal = m_surfaceNormal; - backup_m_editCursorPos = m_editCursorPos; - backup_m_editMode = m_editMode; - backup_m_climbableSurface = m_climbableSurface; - } - // Overwrite the state in preparetion for CommandNavBuildLadder - { - m_editCursorPos = center; - m_surfaceNormal = Vector{ - polygon.polyNormal.x, - polygon.polyNormal.y, - polygon.polyNormal.z }; - m_editMode = EditModeType::NORMAL; - m_climbableSurface = true; - } - // The state-dependent ladder build call - { - CommandNavBuildLadder(); - } - // Finally, restore state - { - m_editMode = backup_m_editMode; - m_editCursorPos = backup_m_editCursorPos; - m_surfaceNormal = backup_m_surfaceNormal; - m_climbableSurface = backup_m_climbableSurface; - } + // Set up state as required by the CommandNavBuildLadder call below + m_surfaceNormal = Vector{ polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z }; + m_editMode = EditModeType::NORMAL; + m_climbableSurface = true; - //CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f ); - } + CommandNavBuildLadder(); } return true; From 2da162aabf5468f1b8c6bf40dfb20d3e43ad3f23 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 18:48:07 +0200 Subject: [PATCH 14/31] wip --- src/game/server/nav_mesh.cpp | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 5c05e0289a..01de24c016 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3559,26 +3559,38 @@ namespace Neo // To be used for the center position of each polygon of the polyhedron. // By reference, because the final CommandNavBuildLadder call which actually builds the ladder // depends on this state, and we can spare the extra Vector by just assigning to it directly. - Vector& center = m_editCursorPos; + Vector& polyCenter = m_editCursorPos; + Vector& polyNormal = m_surfaceNormal; Vector polyMins, polyMaxs; trace_t tr; for (int i = 0; i < polyhedron->iPolygonCount; ++i) { const auto& polygon = polyhedron->pPolygons[i]; + polyNormal = { polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z }; #ifdef DBGFLAG_ASSERT { - const Vector dbgVec{ polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z }; - Assert(dbgVec.IsValid()); - Assert(!dbgVec.IsZero()); - AssertFloatEquals(dbgVec.Length(), 1.f, 0.01f); // unit vector + Assert(polyNormal.IsValid()); + Assert(!polyNormal.IsZero()); + AssertFloatEquals(polyNormal.Length(), 1.f, 0.01f); // unit vector } #endif // Can't build up/down facing ladder mounting points, skip - if (!polygon.polyNormal.x && !polygon.polyNormal.y) + if (!polyNormal.x && !polyNormal.y) { continue; } + // Also reject sides that the nav system considers too flat for ladders + if (polyNormal.z) + { + extern ConVar nav_slope_limit; + Assert(nav_slope_limit.GetFloat() >= 0); + Assert(nav_slope_limit.GetFloat() <= 1); + if (abs(polyNormal.z) > nav_slope_limit.GetFloat()) + { + continue; + } + } if (nav_generate_debug_brushladders.GetBool()) { @@ -3614,7 +3626,7 @@ namespace Neo nav_generate_debug_brushladders.GetFloat(), r, 255, 255); } } - center = VectorLerp(polyMins, polyMaxs, 0.5); + polyCenter = VectorLerp(polyMins, polyMaxs, 0.5); enum LadderPolyFilterReason { ThisIsFine = 0, // No problems detected, do not filter this poly. @@ -3633,7 +3645,6 @@ namespace Neo nSmaller += (polyMaxs.x - polyMins.x < smallestLadderDimToConsider); nSmaller += (polyMaxs.y - polyMins.y < smallestLadderDimToConsider); nSmaller += (polyMaxs.z - polyMins.z < smallestLadderDimToConsider); - // Because the poly mins/maxs are modeling a 2D surface, it is expected for // one of the dimensions to be 0 or near 0. But if 2 or more are below // smallestLadderDimToConsider, then we do want to filter. @@ -3642,14 +3653,14 @@ namespace Neo filter = TooSlim; } - if (filter == ThisIsFine) + else if (filter == ThisIsFine) { // Cull ladder sides facing the wall etc. // Need clearance of at least GenerationStepSize in front of the ladder to mount. UTIL_TraceLine( - center + (polygon.polyNormal * ON_EPSILON), - center + (polygon.polyNormal * GenerationStepSize), - MASK_PLAYERSOLID_BRUSHONLY, NULL, COLLISION_GROUP_NONE, &tr); + polyCenter + (polyNormal * ON_EPSILON), + polyCenter + (polyNormal * GenerationStepSize), + GetGenerationTraceMask(), nullptr, COLLISION_GROUP_NONE, &tr); if (tr.DidHit()) { filter = TooCramped; @@ -3676,8 +3687,8 @@ namespace Neo break; } DevMsg("\t\tPOLY NORMAL: %f %f %f\n", - polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z); - DrawLine(center, center + (polygon.polyNormal * GenerationStepSize), + polyNormal.x, polyNormal.y, polyNormal.z); + DrawLine(polyCenter, polyCenter + (polyNormal * GenerationStepSize), nav_generate_debug_brushladders.GetFloat(), c.r(), c.g(), c.b()); } @@ -3697,7 +3708,6 @@ namespace Neo } // Set up state as required by the CommandNavBuildLadder call below - m_surfaceNormal = Vector{ polygon.polyNormal.x, polygon.polyNormal.y, polygon.polyNormal.z }; m_editMode = EditModeType::NORMAL; m_climbableSurface = true; From 17ea32bf1ac5ea318e8a40db914f6b152565a775 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 19:32:23 +0200 Subject: [PATCH 15/31] cleanup --- src/game/server/nav_generate.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 2b07cf56d6..b6e2eb93e1 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -22,10 +22,6 @@ #include "func_simpleladder.h" #endif -#ifdef NEO -#include "nav_mesh.h" -#endif - // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" From 838caf1eca61026cb4e2e3cd5d6fd5b1c72cd233 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 14 Mar 2026 19:49:47 +0200 Subject: [PATCH 16/31] Fix nav_generate bot kick command --- src/game/server/nav_generate.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index b6e2eb93e1..6037004556 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -3458,6 +3458,9 @@ void CNavMesh::BeginGeneration( bool incremental ) gameeventmanager->FireEvent( event ); } +#ifdef NEO + engine->ServerCommand( "neo_bot_kick all\n" ); +#else #ifdef TERROR engine->ServerCommand( "director_stop\nnb_delete_all\n" ); if ( !incremental && !engine->IsDedicatedServer() ) @@ -3471,6 +3474,7 @@ void CNavMesh::BeginGeneration( bool incremental ) #else engine->ServerCommand( "bot_kick\n" ); #endif +#endif // NEO // Right now, incrementally-generated areas won't connect to existing areas automatically. // Since this means hand-editing will be necessary, don't do a full analyze. From 2933f080b0e27ea972790f1be2d91e1a7188bd4a Mon Sep 17 00:00:00 2001 From: Rain Date: Wed, 3 Jun 2026 12:56:29 +0300 Subject: [PATCH 17/31] Fix redundant null check Stack array ptr cannot be null --- src/game/server/nav_mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 01de24c016..253616c944 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3735,7 +3735,7 @@ bool CNavMesh::BuildBrushLaddersFromBsp() Assert(!!gpGlobals->mapname && *gpGlobals->mapname.ToCStr()); Assert(V_strlen(gpGlobals->mapname.ToCStr()) < MAX_MAP_NAME); V_sprintf_safe(mapPath, "maps/%s.bsp", gpGlobals->mapname.ToCStr()); - if (!(mapPath || *mapPath)) + if (!*mapPath) { Warning("%s: failed to get map name\n", __FUNCTION__); goto fail; From 1f9cb26a9fdc102d1fa9edd1dee4bff3607a75a2 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:28:19 -0700 Subject: [PATCH 18/31] Reject collapsed brush-generated nav ladders Validate the remaining signed span before linking a brush ladder. Preserve legacy manual and entity ladder creation. Co-authored-by: Rainyan --- src/game/server/nav_edit.cpp | 4 ++-- src/game/server/nav_generate.cpp | 28 +++++++++++++++++++++++++++- src/game/server/nav_mesh.cpp | 2 +- src/game/server/nav_mesh.h | 4 ++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/game/server/nav_edit.cpp b/src/game/server/nav_edit.cpp index c9997552b0..13e1d355e6 100644 --- a/src/game/server/nav_edit.cpp +++ b/src/game/server/nav_edit.cpp @@ -555,7 +555,7 @@ void StepAlongClimbableSurface( Vector &pos, const Vector &increment, const Vect //-------------------------------------------------------------------------------------------------------------- -void CNavMesh::CommandNavBuildLadder( void ) +void CNavMesh::CommandNavBuildLadder( bool brushGenerated ) { if ( !IsEditMode( NORMAL ) || !m_climbableSurface ) { @@ -590,7 +590,7 @@ void CNavMesh::CommandNavBuildLadder( void ) Vector bottom = top; bottom.z = bottomEdge.z; - CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f ); + CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f, brushGenerated ); } diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 6037004556..1c5083a019 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -282,7 +282,7 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m /** * Create a navigation representation of a ladder. */ -void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea ) +void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, bool brushGenerated ) { CNavLadder *ladder = new CNavLadder; @@ -322,6 +322,7 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt // adjust bottom to bypass blockages const float inc = 10.0f; float t; + bool bottomTrimmedByClearance = false; trace_t result; for( t = 0.0f; t <= length; t += inc ) { @@ -334,12 +335,14 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt if (result.fraction == 1.0f && !result.startsolid) { // found viable ladder bottom + bottomTrimmedByClearance = (t > 0.0f); ladder->m_bottom = on; break; } } // adjust top to bypass blockages + bool topTrimmedByClearance = false; for( t = 0.0f; t <= length; t += inc ) { on = ladder->m_top - t * along; @@ -351,12 +354,35 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt if (result.fraction == 1.0f && !result.startsolid) { // found viable ladder top + topTrimmedByClearance = (t > 0.0f); ladder->m_top = on; break; } } ladder->m_length = (ladder->m_top - ladder->m_bottom).Length(); + if (brushGenerated) + { + const float finalSignedSpan = DotProduct(ladder->m_top - ladder->m_bottom, along); + const bool trimmedByClearance = bottomTrimmedByClearance || topTrimmedByClearance; + const char *rejectReason = nullptr; + if (finalSignedSpan <= 0.0f) + { + rejectReason = "coincident or crossed endpoints"; + } + // One scan interval is the prototype floor: shorter remnants are below this scan's resolution. + else if (trimmedByClearance && finalSignedSpan < inc) + { + rejectReason = "clearance-trimmed span below scan interval"; + } + if (rejectReason) + { + DevMsg("Brush ladder rejected (%s): raw span %.1f, final signed span %.1f\n", + rejectReason, length, finalSignedSpan); + delete ladder; + return; + } + } ladder->SetDir( ladder->GetDir() ); // now that we've adjusted the top and bottom, re-check the normal diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 253616c944..8c8da9ebbb 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3711,7 +3711,7 @@ namespace Neo m_editMode = EditModeType::NORMAL; m_climbableSurface = true; - CommandNavBuildLadder(); + CommandNavBuildLadder(true); } return true; diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index 74e794126c..cba440c099 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -459,7 +459,7 @@ class CNavMesh : public CGameEventListener void CommandNavLadderFlip( void ); // Flips the direction a ladder faces void CommandNavToggleAttribute( NavAttributeType attribute ); // toggle an attribute on current area void CommandNavMakeSniperSpots( void ); // cuts up the marked area into individual areas suitable for sniper spots - void CommandNavBuildLadder( void ); // builds a nav ladder on the climbable surface under the cursor + void CommandNavBuildLadder( bool brushGenerated = false ); // builds a nav ladder on the climbable surface under the cursor void CommandNavRemoveJumpAreas( void ); // removes jump areas, replacing them with connections void CommandNavSubdivide( const CCommand &args ); // subdivide each nav area in X and Y to create 4 new areas - limit min size void CommandNavSaveSelected( const CCommand &args ); // Save selected set to disk @@ -489,7 +489,7 @@ class CNavMesh : public CGameEventListener } void CreateLadder( const Vector &mins, const Vector &maxs, float maxHeightAboveTopArea ); - void CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea ); + void CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, bool brushGenerated = false ); float SnapToGrid( float x, bool forceGrid = false ) const; // snap given coordinate to generation grid boundary Vector SnapToGrid( const Vector& in, bool snapX = true, bool snapY = true, bool forceGrid = false ) const; // snap given vector's X & Y coordinates to generation grid boundary From 77a408a452541d69474946703380f5ca6bdafd94 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:42:57 -0700 Subject: [PATCH 19/31] Preserve brush ladder ascent links on shared landings Keep the descent backlink and clear the behind slot explicitly when generating a brush ladder. A shared landing can also be a valid forward or side result. Co-authored-by: Rainyan --- src/game/server/nav_generate.cpp | 14 +++++++++++--- src/game/server/nav_ladder.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 1c5083a019..738d62f40f 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -391,7 +391,7 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt ladder->m_topLeftArea = NULL; ladder->m_topRightArea = NULL; ladder->m_topBehindArea = NULL; - ladder->ConnectGeneratedLadder( maxHeightAboveTopArea ); + ladder->ConnectGeneratedLadder( maxHeightAboveTopArea, brushGenerated ); // add ladder to global list m_ladders.AddToTail( ladder ); @@ -399,7 +399,7 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt //-------------------------------------------------------------------------------------------------------------- -void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) +void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brushGenerated ) { const float nearLadderRange = 75.0f; // 50 @@ -469,7 +469,15 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) if (m_topBehindArea) { m_topBehindArea->AddLadderDown( this ); - Disconnect( m_topBehindArea ); + if (brushGenerated) + { + // The generic disconnect may clear a valid forward/side slot when both searches found this area. + m_topBehindArea = NULL; + } + else + { + Disconnect( m_topBehindArea ); + } } // adjust top of ladder to highest connected area diff --git a/src/game/server/nav_ladder.h b/src/game/server/nav_ladder.h index 295dc90b9d..9a6d8200e0 100644 --- a/src/game/server/nav_ladder.h +++ b/src/game/server/nav_ladder.h @@ -71,7 +71,7 @@ class CNavLadder bool IsConnected( const CNavArea *area, LadderDirectionType dir ) const; ///< returns true if given area is connected in given direction - void ConnectGeneratedLadder( float maxHeightAboveTopArea ); ///< Connect a generated ladder to nav areas at the end of nav generation + void ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brushGenerated = false ); ///< Connect a generated ladder to nav areas at the end of nav generation void ConnectTo( CNavArea *area ); ///< connect this ladder to given area void Disconnect( CNavArea *area ); ///< disconnect this ladder from given area From 21da285a9226799186c7b04db148bc0ad1b1b6c4 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:44:31 -0700 Subject: [PATCH 20/31] Seed nav sampling from brush ladder ends Brush ladders were built after sampling, so the sampler never continued from their ends and a landing reached only by the climb got no nav area. 31 of 43 generated climbs with a linked bottom and no top exit on the ntre_ maps had no area at the landing at all. Build brush ladders before sampling, as stock Source does with its ladders, and connect them once areas exist. Skip a ladder-end seed whose ground is more than a player height below the ladder end, so a climbable brush over a void does not seed the void's floor. When connecting a brush ladder, take the floor under the foot as the bottom area before falling back to the nearest area: for a foot that hangs above the floor the nearest area can be the top landing, which then drops every top exit. If no top exit is found, scan again from a step higher, for a climbable brush that ends below the landing's lip. From-scratch nav_generate on 21 ntre_ maps against the curated meshes: climbs linked up and down to the curated areas 100 -> 120 of 157, no top exit 45 -> 27, no climb that matched before lost its match. Bullet, Transit, Ridgeline and Skyline output is unchanged. --- src/game/server/nav_generate.cpp | 81 +++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 738d62f40f..528d336abb 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -391,7 +391,11 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt ladder->m_topLeftArea = NULL; ladder->m_topRightArea = NULL; ladder->m_topBehindArea = NULL; - ladder->ConnectGeneratedLadder( maxHeightAboveTopArea, brushGenerated ); + // Brush ladders are built before sampling; area creation connects them once areas exist. + if (!brushGenerated) + { + ladder->ConnectGeneratedLadder( maxHeightAboveTopArea ); + } // add ladder to global list m_ladders.AddToTail( ladder ); @@ -411,7 +415,19 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush Vector center = m_bottom + Vector( 0, 0, GenerationStepSize ); AddDirectionVector( ¢er, m_dir, HalfHumanWidth ); - m_bottomArea = TheNavMesh->GetNearestNavArea( center, true ); + m_bottomArea = NULL; + if (brushGenerated) + { + // The nearest area can be the top landing when the foot hangs above the floor, + // so prefer the floor under the foot, within the reach the dangling check allows. + m_bottomArea = TheNavMesh->GetNavArea( center, GenerationStepSize + HumanHeight ); + } + + if (!m_bottomArea) + { + m_bottomArea = TheNavMesh->GetNearestNavArea( center, true ); + } + if (!m_bottomArea) { DevMsg( "ERROR: Unconnected ladder bottom at ( %g, %g, %g )\n", m_bottom.x, m_bottom.y, m_bottom.z ); @@ -452,6 +468,25 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush if (m_topBehindArea == m_bottomArea) m_topBehindArea = NULL; + if (brushGenerated && !m_topForwardArea && !m_topLeftArea && !m_topRightArea) + { + // A climbable brush can end below the landing, where the scan hits the landing's lip. + const Vector raised = center + Vector( 0, 0, StepHeight ); + auto findTopArea = [&]( NavDirType dir, float range ) -> CNavArea * + { + CNavArea *area = findFirstAreaInDirection( &raised, dir, range, beneathLimit, NULL ); + return (area == m_bottomArea) ? NULL : area; + }; + + m_topForwardArea = findTopArea( OppositeDirection( m_dir ), nearLadderRange ); + m_topLeftArea = findTopArea( DirectionLeft( m_dir ), nearLadderRange ); + m_topRightArea = findTopArea( DirectionRight( m_dir ), nearLadderRange ); + if (!m_topBehindArea) + { + m_topBehindArea = findTopArea( m_dir, 2.0f*nearLadderRange ); + } + } + // can't include behind area, since it is not used when going up a ladder if (!m_topForwardArea && !m_topLeftArea && !m_topRightArea) DevMsg( "ERROR: Unconnected ladder top at ( %g, %g, %g )\n", m_top.x, m_top.y, m_top.z ); @@ -3437,7 +3472,12 @@ void CNavMesh::CreateNavAreasFromNodes( void ) for ( int i=0; iConnectGeneratedLadder( 0.0f, true ); +#else ladder->ConnectGeneratedLadder( 0.0f ); +#endif } } } @@ -3531,6 +3571,18 @@ void CNavMesh::BeginGeneration( bool incremental ) if ( !incremental ) ///< @incremental update doesn't build ladders to avoid overlapping existing ones { BuildLadders(); +#ifdef NEO + // Before sampling, so the sampler also explores from the ladder ends and reaches + // landings that only a climb leads to. + if (!BuildBrushLaddersFromBsp()) + { + Warning("Generating brush ladders...FAIL\n"); + } + else + { + Msg( "Generating brush ladders...DONE\n" ); + } +#endif } // start sampling from a spawn point @@ -4101,22 +4153,6 @@ bool CNavMesh::UpdateGeneration( float maxTime ) m_isAnalyzed = true; } -#ifdef NEO - // This runs earlier during the generation for the debug==true case, so skip here. - if (!nav_generate_debug_brushladders.GetBool()) - { - // Post-gen because we want automatic merge with the final navmesh - if (!BuildBrushLaddersFromBsp()) - { - Warning("Generating brush ladders...FAIL\n"); - } - else - { - Msg( "Generating brush ladders...DONE\n" ); - } - } -#endif - // generation complete! float generationTime = Plat_FloatTime() - m_generationStartTime; Msg( "Generation complete! %0.1f seconds elapsed.\n", generationTime ); @@ -4291,6 +4327,15 @@ inline CNavNode *LadderEndSearch( const Vector *pos, NavDirType mountDir ) if (TheNavMesh->GetGroundHeight( tryPos, &tryPos.z, &tryNormal ) == false) continue; +#ifdef NEO + // Ground this far below the ladder end is a fall, not a dismount; a climbable brush + // over a void would otherwise seed the void's floor. + if (pos->z - tryPos.z > HumanHeight) + { + continue; + } +#endif + // make sure this point is not on the other side of a wall const float fudge = 4.0f; trace_t result; From 0bf36af87a6fffcfc329a927f5f8164063552567 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:46:52 -0700 Subject: [PATCH 21/31] Drop narrow end-face ladders of climb brushes A climbable brush often gets a ladder on its wide face and more on its narrow end faces. The player hull overhangs an end face narrower than itself, so a small sideways drift while climbing loses the surface: on Transit, bots mounted the 19-unit end faces of the 19x34 brush and fell off about 30 units up on every try, while the 34-unit face worked. After building the ladders of one brush, remove a ladder when a wider ladder of the same brush faces another way and covers its height. End faces that reach lower than the wide face's ladder stay. From-scratch nav_generate on 21 ntre_ maps: linked end-face ladders 106 -> 56 (the rest are Apparatus end faces that bots climb), matched curated climbs with up/down links unchanged at 120/120, none lost. Transit, 4 pinned CTG rounds: 33 ascents, all on the 34-unit face, all reached the top. --- src/game/server/nav_mesh.cpp | 37 ++++++++++++++++++++++++++++++++++++ src/game/server/nav_mesh.h | 1 + 2 files changed, 38 insertions(+) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 8c8da9ebbb..de34a6bc94 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3562,6 +3562,8 @@ namespace Neo Vector& polyCenter = m_editCursorPos; Vector& polyNormal = m_surfaceNormal; + const int firstLadder = m_ladders.Count(); + Vector polyMins, polyMaxs; trace_t tr; for (int i = 0; i < polyhedron->iPolygonCount; ++i) @@ -3714,9 +3716,44 @@ namespace Neo CommandNavBuildLadder(true); } + RemoveNarrowSideLadders(firstLadder); + return true; } +// A climb brush often has climbable end faces narrower than its main face. The player hull +// overhangs such a face, so a small sideways drift while climbing loses the surface, and bots +// mounting one fall off. Drop a ladder of the brush when a wider one facing another way covers +// the same height. +void CNavMesh::RemoveNarrowSideLadders(int firstLadder) +{ + constexpr float widthTolerance = 1.0f; + + for (int i = m_ladders.Count() - 1; i >= firstLadder; --i) + { + const CNavLadder* ladder = m_ladders[i]; + bool covered = false; + for (int j = firstLadder; j < m_ladders.Count() && !covered; ++j) + { + const CNavLadder* other = m_ladders[j]; + covered = other->GetDir() != ladder->GetDir() + && other->m_width > ladder->m_width + widthTolerance + && other->m_top.z >= ladder->m_top.z - StepHeight + && other->m_bottom.z <= ladder->m_bottom.z + StepHeight; + } + + if (!covered) + { + continue; + } + + CNavLadder* sideLadder = m_ladders[i]; + m_ladders.Remove(i); + OnEditDestroyNotify(sideLadder); + delete sideLadder; + } +} + bool CNavMesh::BuildBrushLaddersFromBsp() { bool ok = true; diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index cba440c099..c35bc3c6f0 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -1221,6 +1221,7 @@ class CNavMesh : public CGameEventListener [[nodiscard]] bool BuildBrushLaddersFromBsp(); private: [[nodiscard]] bool LadderFromPolyhedron(const CPolyhedron* polyhedron); + void RemoveNarrowSideLadders(int firstLadder); #endif bool SampleStep( void ); // sample the walkable areas of the map From d538fc5061fcfd83c9fa4b72022a24f9c5c57690 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:49:10 -0700 Subject: [PATCH 22/31] Fix brush ladder clearance and top-exit scans CreateLadder's clearance traces start on the ladder's own face. On a climbable brush that the generation trace mask treats as solid, every trace starts in solid, so the bottom moves up until it leaves the brush. The wide face of a climb brush then loses its ladder or keeps a stub, and only the narrow end faces remain, which bots fall off. Start the traces just off the face. The full-height ladders this restores can top out under a prop or ceiling, where the top-exit scan starts inside solid and finds no landing. Retry that scan from the ladder top as well as above it. From-scratch generation of the 21 ntre_ ladder maps: matched climbs linked both ways 119 -> 130 of 157, none lost; short ladders 23 -> 0. --- src/game/server/nav_generate.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 528d336abb..f7dbc52ba6 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -319,6 +319,11 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt Vector on, out; const float minLadderClearance = 32.0f; + // A brush ladder's ends lie on the face of its own climbable brush, which the trace mask + // can count as solid, so start the clearance traces just off the face. + const float faceOffset = 0.1f; + const Vector offFace = ladder->GetNormal() * faceOffset; + // adjust bottom to bypass blockages const float inc = 10.0f; float t; @@ -330,7 +335,7 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt out = on + ladder->GetNormal() * minLadderClearance; - UTIL_TraceLine( on, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); + UTIL_TraceLine( on + offFace, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); if (result.fraction == 1.0f && !result.startsolid) { @@ -349,7 +354,7 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt out = on + ladder->GetNormal() * minLadderClearance; - UTIL_TraceLine( on, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); + UTIL_TraceLine( on + offFace, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); if (result.fraction == 1.0f && !result.startsolid) { @@ -468,13 +473,20 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush if (m_topBehindArea == m_bottomArea) m_topBehindArea = NULL; - if (brushGenerated && !m_topForwardArea && !m_topLeftArea && !m_topRightArea) + // A climbable brush can end below the landing, where the scan hits the landing's lip. + // Or the space above its top can be solid (a ceiling or prop), so the scan starts inside it. + const float topRetryOffsets[] = { StepHeight, -GenerationStepSize }; + for ( const float offset : topRetryOffsets ) { - // A climbable brush can end below the landing, where the scan hits the landing's lip. - const Vector raised = center + Vector( 0, 0, StepHeight ); + if (!brushGenerated || m_topForwardArea || m_topLeftArea || m_topRightArea) + { + break; + } + + const Vector retryStart = center + Vector( 0, 0, offset ); auto findTopArea = [&]( NavDirType dir, float range ) -> CNavArea * { - CNavArea *area = findFirstAreaInDirection( &raised, dir, range, beneathLimit, NULL ); + CNavArea *area = findFirstAreaInDirection( &retryStart, dir, range, beneathLimit, NULL ); return (area == m_bottomArea) ? NULL : area; }; From 2173900e70341c2524d6692ed635230162022a55 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:51:37 -0700 Subject: [PATCH 23/31] Find brush ladder top exits missed by the grid Merging grows nav areas without re-adding them to the area grid, so during generation a grid lookup misses the merged-in part of an area. Brush ladder top scans now look the landing up in the area list directly. On 21 ntre_ maps this links Sentinel C1/C2 (CTG and JGR) both ways; no climb that linked before loses its links. The wider lookup also finds floors past the far side of a climb, and snapping the ladder top down to such a floor ends the climb under the brush top (Dawn/Dusk C1, bots fell off 3 of 3). A brush ladder now drops a forward exit more than a step below its top. --- src/game/server/nav_generate.cpp | 66 ++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index f7dbc52ba6..2700ef884f 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -103,11 +103,50 @@ class ApproachAreaCost }; +//-------------------------------------------------------------------------------------------------------------- +enum AreaLookupType +{ + AREA_LOOKUP_GRID, + AREA_LOOKUP_ALL_AREAS, +}; + +// Merging grows areas without re-adding them to the grid, so during generation +// a grid lookup can miss the part of an area added by a merge. +static CNavArea *GetAreaBeneathFromAllAreas( const Vector &pos, float beneathLimit ) +{ + // Same probe lift as CNavMesh::GetNavArea. + const float probeLift = 5.0f; + const Vector testPos = pos + Vector( 0, 0, probeLift ); + CNavArea *use = NULL; + float useZ = -FLT_MAX; + + FOR_EACH_VEC( TheNavAreas, it ) + { + CNavArea *area = TheNavAreas[ it ]; + if (!area->IsOverlapping( testPos )) + { + continue; + } + + const float z = area->GetZ( testPos ); + if (z > testPos.z || z < pos.z - beneathLimit || z <= useZ) + { + continue; + } + + use = area; + useZ = z; + } + + return use; +} + + //-------------------------------------------------------------------------------------------------------------- /** * Start at given position and find first area in given direction */ -inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, float range, float beneathLimit, CBaseEntity *traceIgnore = NULL, Vector *closePos = NULL ) +inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, float range, float beneathLimit, CBaseEntity *traceIgnore = NULL, Vector *closePos = NULL, AreaLookupType lookup = AREA_LOOKUP_GRID ) { CNavArea *area = NULL; @@ -127,7 +166,7 @@ inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, if (result.fraction < 1.0f) break; - area = TheNavMesh->GetNavArea( pos, beneathLimit ); + area = (lookup == AREA_LOOKUP_ALL_AREAS) ? GetAreaBeneathFromAllAreas( pos, beneathLimit ) : TheNavMesh->GetNavArea( pos, beneathLimit ); if (area) { if (closePos) @@ -452,24 +491,25 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush AddDirectionVector( ¢er, m_dir, HalfHumanWidth ); float beneathLimit = MIN( 120.0f, m_top.z - m_bottom.z + HalfHumanWidth ); + const AreaLookupType topLookup = brushGenerated ? AREA_LOOKUP_ALL_AREAS : AREA_LOOKUP_GRID; // find "ahead" area - m_topForwardArea = findFirstAreaInDirection( ¢er, OppositeDirection( m_dir ), nearLadderRange, beneathLimit, NULL ); + m_topForwardArea = findFirstAreaInDirection( ¢er, OppositeDirection( m_dir ), nearLadderRange, beneathLimit, NULL, NULL, topLookup ); if (m_topForwardArea == m_bottomArea) m_topForwardArea = NULL; // find "left" area - m_topLeftArea = findFirstAreaInDirection( ¢er, DirectionLeft( m_dir ), nearLadderRange, beneathLimit, NULL ); + m_topLeftArea = findFirstAreaInDirection( ¢er, DirectionLeft( m_dir ), nearLadderRange, beneathLimit, NULL, NULL, topLookup ); if (m_topLeftArea == m_bottomArea) m_topLeftArea = NULL; // find "right" area - m_topRightArea = findFirstAreaInDirection( ¢er, DirectionRight( m_dir ), nearLadderRange, beneathLimit, NULL ); + m_topRightArea = findFirstAreaInDirection( ¢er, DirectionRight( m_dir ), nearLadderRange, beneathLimit, NULL, NULL, topLookup ); if (m_topRightArea == m_bottomArea) m_topRightArea = NULL; // find "behind" area - must look farther, since ladder is against the wall away from this area - m_topBehindArea = findFirstAreaInDirection( ¢er, m_dir, 2.0f*nearLadderRange, beneathLimit, NULL ); + m_topBehindArea = findFirstAreaInDirection( ¢er, m_dir, 2.0f*nearLadderRange, beneathLimit, NULL, NULL, topLookup ); if (m_topBehindArea == m_bottomArea) m_topBehindArea = NULL; @@ -486,7 +526,7 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush const Vector retryStart = center + Vector( 0, 0, offset ); auto findTopArea = [&]( NavDirType dir, float range ) -> CNavArea * { - CNavArea *area = findFirstAreaInDirection( &retryStart, dir, range, beneathLimit, NULL ); + CNavArea *area = findFirstAreaInDirection( &retryStart, dir, range, beneathLimit, NULL, NULL, topLookup ); return (area == m_bottomArea) ? NULL : area; }; @@ -499,6 +539,18 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush } } + // Over the top of a climbable brush, a floor well below the top lies past the far side of + // the climb, not on a landing; snapping the top down to it would end the climb under the brush top. + if (brushGenerated && m_topForwardArea) + { + Vector close; + m_topForwardArea->GetClosestPointOnArea( m_top, &close ); + if (close.z < m_top.z - StepHeight) + { + m_topForwardArea = NULL; + } + } + // can't include behind area, since it is not used when going up a ladder if (!m_topForwardArea && !m_topLeftArea && !m_topRightArea) DevMsg( "ERROR: Unconnected ladder top at ( %g, %g, %g )\n", m_top.x, m_top.y, m_top.z ); From bd898b56bbe556aeddb2bbea8036490e8269a314 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 6 Nov 2026 23:53:48 -0700 Subject: [PATCH 24/31] Name brush ladder generation constants Replace the brush-ladder bool parameter of CreateLadder, CommandNavBuildLadder and ConnectGeneratedLadder with a NavLadderSourceType enum, so call sites read as the ladder source instead of a bare true. Name the bottom-floor reach and the behind-exit range, and reword two comments that restated history or code. No behavior change: nav_generate of Transit, Rogue and Sentinel CTG with this build matches the previous build's output byte for byte. --- src/game/server/nav_edit.cpp | 4 ++-- src/game/server/nav_generate.cpp | 22 ++++++++++++++-------- src/game/server/nav_ladder.h | 8 +++++++- src/game/server/nav_mesh.cpp | 2 +- src/game/server/nav_mesh.h | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/game/server/nav_edit.cpp b/src/game/server/nav_edit.cpp index 13e1d355e6..34d4d8f1f7 100644 --- a/src/game/server/nav_edit.cpp +++ b/src/game/server/nav_edit.cpp @@ -555,7 +555,7 @@ void StepAlongClimbableSurface( Vector &pos, const Vector &increment, const Vect //-------------------------------------------------------------------------------------------------------------- -void CNavMesh::CommandNavBuildLadder( bool brushGenerated ) +void CNavMesh::CommandNavBuildLadder( NavLadderSourceType source ) { if ( !IsEditMode( NORMAL ) || !m_climbableSurface ) { @@ -590,7 +590,7 @@ void CNavMesh::CommandNavBuildLadder( bool brushGenerated ) Vector bottom = top; bottom.z = bottomEdge.z; - CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f, brushGenerated ); + CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f, source ); } diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 2700ef884f..455893901f 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -321,8 +321,9 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m /** * Create a navigation representation of a ladder. */ -void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, bool brushGenerated ) +void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, NavLadderSourceType source ) { + const bool brushGenerated = (source == NAV_LADDER_SOURCE_BRUSH); CNavLadder *ladder = new CNavLadder; ladder->m_top = top; @@ -405,6 +406,7 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt } ladder->m_length = (ladder->m_top - ladder->m_bottom).Length(); + if (brushGenerated) { const float finalSignedSpan = DotProduct(ladder->m_top - ladder->m_bottom, along); @@ -414,11 +416,12 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt { rejectReason = "coincident or crossed endpoints"; } - // One scan interval is the prototype floor: shorter remnants are below this scan's resolution. + // The clearance scans cannot resolve a remnant shorter than their step. else if (trimmedByClearance && finalSignedSpan < inc) { rejectReason = "clearance-trimmed span below scan interval"; } + if (rejectReason) { DevMsg("Brush ladder rejected (%s): raw span %.1f, final signed span %.1f\n", @@ -447,9 +450,11 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt //-------------------------------------------------------------------------------------------------------------- -void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brushGenerated ) +void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderSourceType source ) { const float nearLadderRange = 75.0f; // 50 + const float behindLadderRange = 2.0f * nearLadderRange; + const bool brushGenerated = (source == NAV_LADDER_SOURCE_BRUSH); // // Find naviagtion area at bottom of ladder @@ -463,8 +468,9 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush if (brushGenerated) { // The nearest area can be the top landing when the foot hangs above the floor, - // so prefer the floor under the foot, within the reach the dangling check allows. - m_bottomArea = TheNavMesh->GetNavArea( center, GenerationStepSize + HumanHeight ); + // so prefer the floor under the foot, down to the deepest drop the dangling check accepts. + const float floorReach = GenerationStepSize + HumanHeight; + m_bottomArea = TheNavMesh->GetNavArea( center, floorReach ); } if (!m_bottomArea) @@ -509,7 +515,7 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush m_topRightArea = NULL; // find "behind" area - must look farther, since ladder is against the wall away from this area - m_topBehindArea = findFirstAreaInDirection( ¢er, m_dir, 2.0f*nearLadderRange, beneathLimit, NULL, NULL, topLookup ); + m_topBehindArea = findFirstAreaInDirection( ¢er, m_dir, behindLadderRange, beneathLimit, NULL, NULL, topLookup ); if (m_topBehindArea == m_bottomArea) m_topBehindArea = NULL; @@ -535,7 +541,7 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brush m_topRightArea = findTopArea( DirectionRight( m_dir ), nearLadderRange ); if (!m_topBehindArea) { - m_topBehindArea = findTopArea( m_dir, 2.0f*nearLadderRange ); + m_topBehindArea = findTopArea( m_dir, behindLadderRange ); } } @@ -3538,7 +3544,7 @@ void CNavMesh::CreateNavAreasFromNodes( void ) CNavLadder *ladder = m_ladders[i]; #ifdef NEO // Every ladder of a full generation comes from BuildBrushLaddersFromBsp. - ladder->ConnectGeneratedLadder( 0.0f, true ); + ladder->ConnectGeneratedLadder( 0.0f, NAV_LADDER_SOURCE_BRUSH ); #else ladder->ConnectGeneratedLadder( 0.0f ); #endif diff --git a/src/game/server/nav_ladder.h b/src/game/server/nav_ladder.h index 9a6d8200e0..99b08b1c11 100644 --- a/src/game/server/nav_ladder.h +++ b/src/game/server/nav_ladder.h @@ -15,6 +15,12 @@ class CNavArea; +enum NavLadderSourceType +{ + NAV_LADDER_SOURCE_DEFAULT, + NAV_LADDER_SOURCE_BRUSH, ///< built from a climbable brush of the BSP +}; + //-------------------------------------------------------------------------------------------------------------- /** * The NavLadder represents ladders in the Navigation Mesh, and their connections to adjacent NavAreas @@ -71,7 +77,7 @@ class CNavLadder bool IsConnected( const CNavArea *area, LadderDirectionType dir ) const; ///< returns true if given area is connected in given direction - void ConnectGeneratedLadder( float maxHeightAboveTopArea, bool brushGenerated = false ); ///< Connect a generated ladder to nav areas at the end of nav generation + void ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderSourceType source = NAV_LADDER_SOURCE_DEFAULT ); ///< Connect a generated ladder to nav areas at the end of nav generation void ConnectTo( CNavArea *area ); ///< connect this ladder to given area void Disconnect( CNavArea *area ); ///< disconnect this ladder from given area diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index de34a6bc94..28671aeb89 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3713,7 +3713,7 @@ namespace Neo m_editMode = EditModeType::NORMAL; m_climbableSurface = true; - CommandNavBuildLadder(true); + CommandNavBuildLadder(NAV_LADDER_SOURCE_BRUSH); } RemoveNarrowSideLadders(firstLadder); diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index c35bc3c6f0..3597ff8d58 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -459,7 +459,7 @@ class CNavMesh : public CGameEventListener void CommandNavLadderFlip( void ); // Flips the direction a ladder faces void CommandNavToggleAttribute( NavAttributeType attribute ); // toggle an attribute on current area void CommandNavMakeSniperSpots( void ); // cuts up the marked area into individual areas suitable for sniper spots - void CommandNavBuildLadder( bool brushGenerated = false ); // builds a nav ladder on the climbable surface under the cursor + void CommandNavBuildLadder( NavLadderSourceType source = NAV_LADDER_SOURCE_DEFAULT ); // builds a nav ladder on the climbable surface under the cursor void CommandNavRemoveJumpAreas( void ); // removes jump areas, replacing them with connections void CommandNavSubdivide( const CCommand &args ); // subdivide each nav area in X and Y to create 4 new areas - limit min size void CommandNavSaveSelected( const CCommand &args ); // Save selected set to disk @@ -489,7 +489,7 @@ class CNavMesh : public CGameEventListener } void CreateLadder( const Vector &mins, const Vector &maxs, float maxHeightAboveTopArea ); - void CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, bool brushGenerated = false ); + void CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, NavLadderSourceType source = NAV_LADDER_SOURCE_DEFAULT ); float SnapToGrid( float x, bool forceGrid = false ) const; // snap given coordinate to generation grid boundary Vector SnapToGrid( const Vector& in, bool snapX = true, bool snapY = true, bool forceGrid = false ) const; // snap given vector's X & Y coordinates to generation grid boundary From cbf31c3df5a4afbde93ae1362aca26fa2d586ddf Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Mon, 9 Nov 2026 22:28:37 -0700 Subject: [PATCH 25/31] Guard brush ladder changes to SDK nav files Valve SDK files keep their original code under #else, so every NEO change to them sits behind #ifdef NEO. Move the brush ladder paths of CreateLadder and ConnectGeneratedLadder into NEO-only helpers: end clearance and span reject, the bottom area lookup, and the top area search with its retries. The SDK bodies keep their lines and call a helper at each hook point. Guard the source parameter, the area lookup option and the ladder source enum, and restore blank lines the branch had changed outside the guards. No behavior change: nav_generate of 8 ntre_ ladder maps (Release) gives byte-identical navs before and after. Rogue varies under load in both builds; at 2 wide its six runs are identical. --- src/game/server/nav_edit.cpp | 8 + src/game/server/nav_generate.cpp | 310 +++++++++++++++++++++--------- src/game/server/nav_ladder.h | 6 + src/game/server/nav_mesh.cpp | 4 +- src/game/server/nav_mesh.h | 8 + src/game/server/ndebugoverlay.cpp | 1 + 6 files changed, 239 insertions(+), 98 deletions(-) diff --git a/src/game/server/nav_edit.cpp b/src/game/server/nav_edit.cpp index 34d4d8f1f7..1bc77c2af2 100644 --- a/src/game/server/nav_edit.cpp +++ b/src/game/server/nav_edit.cpp @@ -555,7 +555,11 @@ void StepAlongClimbableSurface( Vector &pos, const Vector &increment, const Vect //-------------------------------------------------------------------------------------------------------------- +#ifdef NEO void CNavMesh::CommandNavBuildLadder( NavLadderSourceType source ) +#else +void CNavMesh::CommandNavBuildLadder( void ) +#endif { if ( !IsEditMode( NORMAL ) || !m_climbableSurface ) { @@ -590,7 +594,11 @@ void CNavMesh::CommandNavBuildLadder( NavLadderSourceType source ) Vector bottom = top; bottom.z = bottomEdge.z; +#ifdef NEO CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f, source ); +#else + CreateLadder( topEdge, bottomEdge, leftEdge.DistTo( rightEdge ), m_ladderNormal.AsVector2D(), 0.0f ); +#endif } diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 455893901f..9cdbdb0f58 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -103,6 +103,7 @@ class ApproachAreaCost }; +#ifdef NEO //-------------------------------------------------------------------------------------------------------------- enum AreaLookupType { @@ -142,11 +143,16 @@ static CNavArea *GetAreaBeneathFromAllAreas( const Vector &pos, float beneathLim } +#endif // NEO //-------------------------------------------------------------------------------------------------------------- /** * Start at given position and find first area in given direction */ +#ifdef NEO inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, float range, float beneathLimit, CBaseEntity *traceIgnore = NULL, Vector *closePos = NULL, AreaLookupType lookup = AREA_LOOKUP_GRID ) +#else +inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, float range, float beneathLimit, CBaseEntity *traceIgnore = NULL, Vector *closePos = NULL ) +#endif // NEO { CNavArea *area = NULL; @@ -166,7 +172,11 @@ inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, if (result.fraction < 1.0f) break; +#ifdef NEO area = (lookup == AREA_LOOKUP_ALL_AREAS) ? GetAreaBeneathFromAllAreas( pos, beneathLimit ) : TheNavMesh->GetNavArea( pos, beneathLimit ); +#else + area = TheNavMesh->GetNavArea( pos, beneathLimit ); +#endif // NEO if (area) { if (closePos) @@ -317,13 +327,96 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m } +#ifdef NEO +//-------------------------------------------------------------------------------------------------------------- +static const float LadderEndScanStep = 10.0f; + +/** + * Move a ladder end along the ladder until the space in front of it is clear. + * Returns true if the end moved. + */ +static bool ClearLadderEnd( Vector *end, const Vector &along, float length, const Vector &normal ) +{ + const float minLadderClearance = 32.0f; + + // A brush ladder's ends lie on the face of its own climbable brush, which the trace mask + // can count as solid, so start the clearance traces just off the face. + const float faceOffset = 0.1f; + const Vector offFace = normal * faceOffset; + + trace_t result; + for ( float t = 0.0f; t <= length; t += LadderEndScanStep ) + { + const Vector on = *end + t * along; + const Vector out = on + normal * minLadderClearance; + + UTIL_TraceLine( on + offFace, out, TheNavMesh->GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); + + if (result.fraction == 1.0f && !result.startsolid) + { + *end = on; + return t > 0.0f; + } + } + + return false; +} + + +//-------------------------------------------------------------------------------------------------------------- +/** + * Move both ends of a new ladder to where they are reachable. + * Returns false if a brush ladder has too little climb left to keep. + */ +static bool TrimLadderEnds( CNavLadder *ladder, NavLadderSourceType source ) +{ + Vector along = ladder->m_top - ladder->m_bottom; + const float length = along.NormalizeInPlace(); + + const bool bottomTrimmed = ClearLadderEnd( &ladder->m_bottom, along, length, ladder->GetNormal() ); + const bool topTrimmed = ClearLadderEnd( &ladder->m_top, -along, length, ladder->GetNormal() ); + + ladder->m_length = (ladder->m_top - ladder->m_bottom).Length(); + + if (source != NAV_LADDER_SOURCE_BRUSH) + { + return true; + } + + const float finalSignedSpan = DotProduct( ladder->m_top - ladder->m_bottom, along ); + const char *rejectReason = nullptr; + if (finalSignedSpan <= 0.0f) + { + rejectReason = "coincident or crossed endpoints"; + } + // The clearance scans cannot resolve a remnant shorter than their step. + else if ((bottomTrimmed || topTrimmed) && finalSignedSpan < LadderEndScanStep) + { + rejectReason = "clearance-trimmed span below scan interval"; + } + + if (!rejectReason) + { + return true; + } + + DevMsg( "Brush ladder rejected (%s): raw span %.1f, final signed span %.1f\n", + rejectReason, length, finalSignedSpan ); + return false; +} + + +#endif // NEO //-------------------------------------------------------------------------------------------------------------- /** * Create a navigation representation of a ladder. */ +#ifdef NEO void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, NavLadderSourceType source ) +#else +void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea ) +#endif // NEO { - const bool brushGenerated = (source == NAV_LADDER_SOURCE_BRUSH); CNavLadder *ladder = new CNavLadder; ladder->m_top = top; @@ -354,20 +447,21 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt // adjust top and bottom of ladder to make sure they are reachable // (cs_office has a crate right in front of the base of a ladder) +#ifdef NEO + if (!TrimLadderEnds( ladder, source )) + { + delete ladder; + return; + } +#else Vector along = ladder->m_top - ladder->m_bottom; float length = along.NormalizeInPlace(); Vector on, out; const float minLadderClearance = 32.0f; - // A brush ladder's ends lie on the face of its own climbable brush, which the trace mask - // can count as solid, so start the clearance traces just off the face. - const float faceOffset = 0.1f; - const Vector offFace = ladder->GetNormal() * faceOffset; - // adjust bottom to bypass blockages const float inc = 10.0f; float t; - bool bottomTrimmedByClearance = false; trace_t result; for( t = 0.0f; t <= length; t += inc ) { @@ -375,61 +469,35 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt out = on + ladder->GetNormal() * minLadderClearance; - UTIL_TraceLine( on + offFace, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); + UTIL_TraceLine( on, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); if (result.fraction == 1.0f && !result.startsolid) { // found viable ladder bottom - bottomTrimmedByClearance = (t > 0.0f); ladder->m_bottom = on; break; } } // adjust top to bypass blockages - bool topTrimmedByClearance = false; for( t = 0.0f; t <= length; t += inc ) { on = ladder->m_top - t * along; out = on + ladder->GetNormal() * minLadderClearance; - UTIL_TraceLine( on + offFace, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); + UTIL_TraceLine( on, out, GetGenerationTraceMask(), NULL, COLLISION_GROUP_NONE, &result ); if (result.fraction == 1.0f && !result.startsolid) { // found viable ladder top - topTrimmedByClearance = (t > 0.0f); ladder->m_top = on; break; } } ladder->m_length = (ladder->m_top - ladder->m_bottom).Length(); - - if (brushGenerated) - { - const float finalSignedSpan = DotProduct(ladder->m_top - ladder->m_bottom, along); - const bool trimmedByClearance = bottomTrimmedByClearance || topTrimmedByClearance; - const char *rejectReason = nullptr; - if (finalSignedSpan <= 0.0f) - { - rejectReason = "coincident or crossed endpoints"; - } - // The clearance scans cannot resolve a remnant shorter than their step. - else if (trimmedByClearance && finalSignedSpan < inc) - { - rejectReason = "clearance-trimmed span below scan interval"; - } - - if (rejectReason) - { - DevMsg("Brush ladder rejected (%s): raw span %.1f, final signed span %.1f\n", - rejectReason, length, finalSignedSpan); - delete ladder; - return; - } - } +#endif // NEO ladder->SetDir( ladder->GetDir() ); // now that we've adjusted the top and bottom, re-check the normal @@ -438,23 +506,109 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt ladder->m_topLeftArea = NULL; ladder->m_topRightArea = NULL; ladder->m_topBehindArea = NULL; +#ifdef NEO // Brush ladders are built before sampling; area creation connects them once areas exist. - if (!brushGenerated) + if (source != NAV_LADDER_SOURCE_BRUSH) { ladder->ConnectGeneratedLadder( maxHeightAboveTopArea ); } +#else + ladder->ConnectGeneratedLadder( maxHeightAboveTopArea ); +#endif // NEO // add ladder to global list m_ladders.AddToTail( ladder ); } +#ifdef NEO +//-------------------------------------------------------------------------------------------------------------- +/** + * Find the area at the bottom of a generated ladder. + */ +static CNavArea *FindLadderBottomArea( const Vector ¢er, NavLadderSourceType source ) +{ + if (source == NAV_LADDER_SOURCE_BRUSH) + { + // The nearest area can be the top landing when the foot hangs above the floor, + // so prefer the floor under the foot, down to the deepest drop the dangling check accepts. + const float floorReach = GenerationStepSize + HumanHeight; + CNavArea *floor = TheNavMesh->GetNavArea( center, floorReach ); + if (floor) + { + return floor; + } + } + + return TheNavMesh->GetNearestNavArea( center, true ); +} + + +//-------------------------------------------------------------------------------------------------------------- +/** + * Find the areas at the top of a brush ladder, searching all areas rather than the grid. + */ +static void FindBrushLadderTopAreas( CNavLadder *ladder, const Vector ¢er, float beneathLimit, float nearLadderRange ) +{ + const float behindLadderRange = 2.0f * nearLadderRange; + const NavDirType dir = ladder->GetDir(); + + auto findTopArea = [&]( const Vector &start, NavDirType searchDir, float range ) -> CNavArea * + { + CNavArea *area = findFirstAreaInDirection( &start, searchDir, range, beneathLimit, NULL, NULL, AREA_LOOKUP_ALL_AREAS ); + return (area == ladder->m_bottomArea) ? NULL : area; + }; + + ladder->m_topForwardArea = findTopArea( center, OppositeDirection( dir ), nearLadderRange ); + ladder->m_topLeftArea = findTopArea( center, DirectionLeft( dir ), nearLadderRange ); + ladder->m_topRightArea = findTopArea( center, DirectionRight( dir ), nearLadderRange ); + ladder->m_topBehindArea = findTopArea( center, dir, behindLadderRange ); + + // A climbable brush can end below the landing, where the scan hits the landing's lip. + // Or the space above its top can be solid (a ceiling or prop), so the scan starts inside it. + const float topRetryOffsets[] = { StepHeight, -GenerationStepSize }; + for ( const float offset : topRetryOffsets ) + { + if (ladder->m_topForwardArea || ladder->m_topLeftArea || ladder->m_topRightArea) + { + break; + } + + const Vector retryStart = center + Vector( 0, 0, offset ); + ladder->m_topForwardArea = findTopArea( retryStart, OppositeDirection( dir ), nearLadderRange ); + ladder->m_topLeftArea = findTopArea( retryStart, DirectionLeft( dir ), nearLadderRange ); + ladder->m_topRightArea = findTopArea( retryStart, DirectionRight( dir ), nearLadderRange ); + if (!ladder->m_topBehindArea) + { + ladder->m_topBehindArea = findTopArea( retryStart, dir, behindLadderRange ); + } + } + + if (!ladder->m_topForwardArea) + { + return; + } + + // Over the top of a climbable brush, a floor well below the top lies past the far side of + // the climb, not on a landing; snapping the top down to it would end the climb under the brush top. + Vector close; + ladder->m_topForwardArea->GetClosestPointOnArea( ladder->m_top, &close ); + if (close.z < ladder->m_top.z - StepHeight) + { + ladder->m_topForwardArea = NULL; + } +} + + +#endif // NEO //-------------------------------------------------------------------------------------------------------------- +#ifdef NEO void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderSourceType source ) +#else +void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) +#endif // NEO { const float nearLadderRange = 75.0f; // 50 - const float behindLadderRange = 2.0f * nearLadderRange; - const bool brushGenerated = (source == NAV_LADDER_SOURCE_BRUSH); // // Find naviagtion area at bottom of ladder @@ -464,20 +618,11 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderS Vector center = m_bottom + Vector( 0, 0, GenerationStepSize ); AddDirectionVector( ¢er, m_dir, HalfHumanWidth ); - m_bottomArea = NULL; - if (brushGenerated) - { - // The nearest area can be the top landing when the foot hangs above the floor, - // so prefer the floor under the foot, down to the deepest drop the dangling check accepts. - const float floorReach = GenerationStepSize + HumanHeight; - m_bottomArea = TheNavMesh->GetNavArea( center, floorReach ); - } - - if (!m_bottomArea) - { - m_bottomArea = TheNavMesh->GetNearestNavArea( center, true ); - } - +#ifdef NEO + m_bottomArea = FindLadderBottomArea( center, source ); +#else + m_bottomArea = TheNavMesh->GetNearestNavArea( center, true ); +#endif // NEO if (!m_bottomArea) { DevMsg( "ERROR: Unconnected ladder bottom at ( %g, %g, %g )\n", m_bottom.x, m_bottom.y, m_bottom.z ); @@ -497,65 +642,34 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderS AddDirectionVector( ¢er, m_dir, HalfHumanWidth ); float beneathLimit = MIN( 120.0f, m_top.z - m_bottom.z + HalfHumanWidth ); - const AreaLookupType topLookup = brushGenerated ? AREA_LOOKUP_ALL_AREAS : AREA_LOOKUP_GRID; // find "ahead" area - m_topForwardArea = findFirstAreaInDirection( ¢er, OppositeDirection( m_dir ), nearLadderRange, beneathLimit, NULL, NULL, topLookup ); + m_topForwardArea = findFirstAreaInDirection( ¢er, OppositeDirection( m_dir ), nearLadderRange, beneathLimit, NULL ); if (m_topForwardArea == m_bottomArea) m_topForwardArea = NULL; // find "left" area - m_topLeftArea = findFirstAreaInDirection( ¢er, DirectionLeft( m_dir ), nearLadderRange, beneathLimit, NULL, NULL, topLookup ); + m_topLeftArea = findFirstAreaInDirection( ¢er, DirectionLeft( m_dir ), nearLadderRange, beneathLimit, NULL ); if (m_topLeftArea == m_bottomArea) m_topLeftArea = NULL; // find "right" area - m_topRightArea = findFirstAreaInDirection( ¢er, DirectionRight( m_dir ), nearLadderRange, beneathLimit, NULL, NULL, topLookup ); + m_topRightArea = findFirstAreaInDirection( ¢er, DirectionRight( m_dir ), nearLadderRange, beneathLimit, NULL ); if (m_topRightArea == m_bottomArea) m_topRightArea = NULL; // find "behind" area - must look farther, since ladder is against the wall away from this area - m_topBehindArea = findFirstAreaInDirection( ¢er, m_dir, behindLadderRange, beneathLimit, NULL, NULL, topLookup ); + m_topBehindArea = findFirstAreaInDirection( ¢er, m_dir, 2.0f*nearLadderRange, beneathLimit, NULL ); if (m_topBehindArea == m_bottomArea) m_topBehindArea = NULL; +#ifdef NEO - // A climbable brush can end below the landing, where the scan hits the landing's lip. - // Or the space above its top can be solid (a ceiling or prop), so the scan starts inside it. - const float topRetryOffsets[] = { StepHeight, -GenerationStepSize }; - for ( const float offset : topRetryOffsets ) - { - if (!brushGenerated || m_topForwardArea || m_topLeftArea || m_topRightArea) - { - break; - } - - const Vector retryStart = center + Vector( 0, 0, offset ); - auto findTopArea = [&]( NavDirType dir, float range ) -> CNavArea * - { - CNavArea *area = findFirstAreaInDirection( &retryStart, dir, range, beneathLimit, NULL, NULL, topLookup ); - return (area == m_bottomArea) ? NULL : area; - }; - - m_topForwardArea = findTopArea( OppositeDirection( m_dir ), nearLadderRange ); - m_topLeftArea = findTopArea( DirectionLeft( m_dir ), nearLadderRange ); - m_topRightArea = findTopArea( DirectionRight( m_dir ), nearLadderRange ); - if (!m_topBehindArea) - { - m_topBehindArea = findTopArea( m_dir, behindLadderRange ); - } - } - - // Over the top of a climbable brush, a floor well below the top lies past the far side of - // the climb, not on a landing; snapping the top down to it would end the climb under the brush top. - if (brushGenerated && m_topForwardArea) + if (source == NAV_LADDER_SOURCE_BRUSH) { - Vector close; - m_topForwardArea->GetClosestPointOnArea( m_top, &close ); - if (close.z < m_top.z - StepHeight) - { - m_topForwardArea = NULL; - } + // A grid lookup misses the parts merging added to an area, so search again over all areas. + FindBrushLadderTopAreas( this, center, beneathLimit, nearLadderRange ); } +#endif // NEO // can't include behind area, since it is not used when going up a ladder if (!m_topForwardArea && !m_topLeftArea && !m_topRightArea) @@ -574,7 +688,8 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderS if (m_topBehindArea) { m_topBehindArea->AddLadderDown( this ); - if (brushGenerated) +#ifdef NEO + if (source == NAV_LADDER_SOURCE_BRUSH) { // The generic disconnect may clear a valid forward/side slot when both searches found this area. m_topBehindArea = NULL; @@ -583,6 +698,9 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderS { Disconnect( m_topBehindArea ); } +#else + Disconnect( m_topBehindArea ); +#endif // NEO } // adjust top of ladder to highest connected area @@ -3594,8 +3712,8 @@ void CNavMesh::BeginGeneration( bool incremental ) } return; } -#endif +#endif IGameEvent *event = gameeventmanager->CreateEvent( "nav_generate" ); if ( event ) { @@ -4396,8 +4514,8 @@ inline CNavNode *LadderEndSearch( const Vector *pos, NavDirType mountDir ) Vector tryNormal; if (TheNavMesh->GetGroundHeight( tryPos, &tryPos.z, &tryNormal ) == false) continue; - #ifdef NEO + // Ground this far below the ladder end is a fall, not a dismount; a climbable brush // over a void would otherwise seed the void's floor. if (pos->z - tryPos.z > HumanHeight) diff --git a/src/game/server/nav_ladder.h b/src/game/server/nav_ladder.h index 99b08b1c11..0679184a08 100644 --- a/src/game/server/nav_ladder.h +++ b/src/game/server/nav_ladder.h @@ -15,12 +15,14 @@ class CNavArea; +#ifdef NEO enum NavLadderSourceType { NAV_LADDER_SOURCE_DEFAULT, NAV_LADDER_SOURCE_BRUSH, ///< built from a climbable brush of the BSP }; +#endif // NEO //-------------------------------------------------------------------------------------------------------------- /** * The NavLadder represents ladders in the Navigation Mesh, and their connections to adjacent NavAreas @@ -77,7 +79,11 @@ class CNavLadder bool IsConnected( const CNavArea *area, LadderDirectionType dir ) const; ///< returns true if given area is connected in given direction +#ifdef NEO void ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderSourceType source = NAV_LADDER_SOURCE_DEFAULT ); ///< Connect a generated ladder to nav areas at the end of nav generation +#else + void ConnectGeneratedLadder( float maxHeightAboveTopArea ); ///< Connect a generated ladder to nav areas at the end of nav generation +#endif void ConnectTo( CNavArea *area ); ///< connect this ladder to given area void Disconnect( CNavArea *area ); ///< disconnect this ladder from given area diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 28671aeb89..cf92e516e8 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -31,7 +31,6 @@ #include "nav.h" #include "polylib.h" #endif - #ifdef NEXT_BOT #include "NextBot/NavMeshEntities/func_nav_prerequisite.h" #endif @@ -41,6 +40,7 @@ // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" + #ifdef NEO static auto DrawLine(const Vector& from, const Vector& to, float duration = NDEBUG_PERSIST_TILL_NEXT_SERVER, int r = 255, int g=255, int b=255) @@ -3248,8 +3248,8 @@ void CNavMesh::DestroyLadders( void ) m_markedLadder = NULL; m_selectedLadder = NULL; } - #ifdef NEO + namespace Neo { struct MockBspHdr { diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index 3597ff8d58..439b5c2290 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -459,7 +459,11 @@ class CNavMesh : public CGameEventListener void CommandNavLadderFlip( void ); // Flips the direction a ladder faces void CommandNavToggleAttribute( NavAttributeType attribute ); // toggle an attribute on current area void CommandNavMakeSniperSpots( void ); // cuts up the marked area into individual areas suitable for sniper spots +#ifdef NEO void CommandNavBuildLadder( NavLadderSourceType source = NAV_LADDER_SOURCE_DEFAULT ); // builds a nav ladder on the climbable surface under the cursor +#else + void CommandNavBuildLadder( void ); // builds a nav ladder on the climbable surface under the cursor +#endif void CommandNavRemoveJumpAreas( void ); // removes jump areas, replacing them with connections void CommandNavSubdivide( const CCommand &args ); // subdivide each nav area in X and Y to create 4 new areas - limit min size void CommandNavSaveSelected( const CCommand &args ); // Save selected set to disk @@ -489,7 +493,11 @@ class CNavMesh : public CGameEventListener } void CreateLadder( const Vector &mins, const Vector &maxs, float maxHeightAboveTopArea ); +#ifdef NEO void CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea, NavLadderSourceType source = NAV_LADDER_SOURCE_DEFAULT ); +#else + void CreateLadder( const Vector &top, const Vector &bottom, float width, const Vector2D &ladderDir, float maxHeightAboveTopArea ); +#endif float SnapToGrid( float x, bool forceGrid = false ) const; // snap given coordinate to generation grid boundary Vector SnapToGrid( const Vector& in, bool snapX = true, bool snapY = true, bool forceGrid = false ) const; // snap given vector's X & Y coordinates to generation grid boundary diff --git a/src/game/server/ndebugoverlay.cpp b/src/game/server/ndebugoverlay.cpp index 87a72f0d6a..934adb0ff1 100644 --- a/src/game/server/ndebugoverlay.cpp +++ b/src/game/server/ndebugoverlay.cpp @@ -91,6 +91,7 @@ void UTIL_AddDebugLine(const Vector &startPos, const Vector &endPos, bool noDept return; } } + #ifdef NEO debugLine->r = color.r(); debugLine->g = color.g(); From a685d2ca46f4b507cd1b81589c2d6ffba10520a9 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Thu, 12 Nov 2026 19:03:17 -0700 Subject: [PATCH 26/31] Drop unreachable ladder generation failure branch LadderFromPolyhedron has a single exit that returns true, so the warning branch in BuildBrushLaddersFromBsp never ran. It also read the polyhedron after Release(). Make the function void and remove the branch. --- src/game/server/nav_mesh.cpp | 39 ++---------------------------------- src/game/server/nav_mesh.h | 2 +- 2 files changed, 3 insertions(+), 38 deletions(-) diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index cf92e516e8..3d289c7219 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -3547,7 +3547,7 @@ namespace Neo } } -[[nodiscard]] bool CNavMesh::LadderFromPolyhedron(const CPolyhedron* polyhedron) +void CNavMesh::LadderFromPolyhedron(const CPolyhedron* polyhedron) { Assert(polyhedron); @@ -3717,8 +3717,6 @@ namespace Neo } RemoveNarrowSideLadders(firstLadder); - - return true; } // A climb brush often has climbable end faces narrower than its main face. The player hull @@ -3821,41 +3819,8 @@ bool CNavMesh::BuildBrushLaddersFromBsp() goto fail; } - const bool ladderGenOk = LadderFromPolyhedron(polyhedron); - + LadderFromPolyhedron(polyhedron); polyhedron->Release(); - - if (!ladderGenOk) - { - Warning("%s: failed to generate ladder from polyhedron\n", __FUNCTION__); - - if (polyhedron->iVertexCount <= 0) - { - Warning("\tAdditionally, generated polyhedron reports %d sides but expected >0\n", - polyhedron->iVertexCount); - Assert(false); - continue; - } - - CUtlVectorpVertices)> vertices; - vertices.EnsureCapacity(polyhedron->iVertexCount); - for (int i = 0; i < polyhedron->iVertexCount; ++i) - { - auto** pVert = vertices.AddToTailGetPtr(); - *pVert = polyhedron->pVertices + i; - Assert(*pVert); - } - Assert(vertices.Count() == polyhedron->iVertexCount); - - CUtlString errMsg; - errMsg.Format("\t%d verts: ", polyhedron->iVertexCount); - for (const auto& vert : vertices) - { - errMsg.Format("%s [%f %f %f],", errMsg.String(), vert->x, vert->y, vert->z); - } - errMsg.SetLength(errMsg.Length() - 1); // remove final comma from the above loop - Warning("%s\n", errMsg.String()); - } } cleanup: diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index 439b5c2290..b6270c0feb 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -1228,7 +1228,7 @@ class CNavMesh : public CGameEventListener // Build ladders from the BSP brush lump ladders (rather than func_ladder) [[nodiscard]] bool BuildBrushLaddersFromBsp(); private: - [[nodiscard]] bool LadderFromPolyhedron(const CPolyhedron* polyhedron); + void LadderFromPolyhedron(const CPolyhedron* polyhedron); void RemoveNarrowSideLadders(int firstLadder); #endif From fa37776d1c32308037995a9e2ec31a18b8d4df54 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Thu, 12 Nov 2026 19:05:02 -0700 Subject: [PATCH 27/31] Clarify brush ladder bottom and behind area comments Say what the ladder foot is and why the nearest-area lookup can return the top landing, and which slot Disconnect() clears when the behind area was also found by a forward or side scan. --- src/game/server/nav_generate.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 9cdbdb0f58..0b0f772fd6 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -530,8 +530,10 @@ static CNavArea *FindLadderBottomArea( const Vector ¢er, NavLadderSourceType { if (source == NAV_LADDER_SOURCE_BRUSH) { - // The nearest area can be the top landing when the foot hangs above the floor, - // so prefer the floor under the foot, down to the deepest drop the dangling check accepts. + // The foot is the ladder's bottom end, and it can sit above the floor. + // GetNearestNavArea picks by distance with no beneath test, so from a raised foot + // the top landing can be nearer than the floor. Look straight down first, + // as far as the dangling check lets a foot hang. const float floorReach = GenerationStepSize + HumanHeight; CNavArea *floor = TheNavMesh->GetNavArea( center, floorReach ); if (floor) @@ -691,7 +693,8 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) #ifdef NEO if (source == NAV_LADDER_SOURCE_BRUSH) { - // The generic disconnect may clear a valid forward/side slot when both searches found this area. + // Disconnect() clears the first slot holding the area, which is a forward or side slot + // when one of those scans found this area too. m_topBehindArea = NULL; } else From 52138a39c1f8921ec1492da6d54b07b9ee1b5e82 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Thu, 12 Nov 2026 19:07:41 -0700 Subject: [PATCH 28/31] Update the nav grid when areas merge Merging grows the surviving area in place, but the grid kept only the cells of its original extent, so a grid lookup could miss the merged part for the rest of generation. Add the area to the cells its new extent covers in FinishMerge and MergeEdit. With the grid current, brush ladder generation no longer needs its own lookup over all areas, so remove it. What is left of the top area helper is the retry scans, so name it for that. --- src/game/server/nav_area.cpp | 8 ++++ src/game/server/nav_generate.cpp | 63 ++------------------------------ src/game/server/nav_mesh.cpp | 27 ++++++++++++++ src/game/server/nav_mesh.h | 3 ++ 4 files changed, 42 insertions(+), 59 deletions(-) diff --git a/src/game/server/nav_area.cpp b/src/game/server/nav_area.cpp index 035662fa18..f85e6825fe 100644 --- a/src/game/server/nav_area.cpp +++ b/src/game/server/nav_area.cpp @@ -984,6 +984,10 @@ void CNavArea::FinishMerge( CNavArea *adjArea ) { m_invDxCorners = m_invDyCorners = 0; } +#ifdef NEO + + TheNavMesh->AddNavAreaToGrid( this ); +#endif // NEO // reassign the adjacent area's internal nodes to the final area adjArea->AssignNodes( this ); @@ -1830,6 +1834,10 @@ bool CNavArea::MergeEdit( CNavArea *adj ) MergeAdjacentConnections( adj ); InheritAttributes( adj ); +#ifdef NEO + + TheNavMesh->AddNavAreaToGrid( this ); +#endif // NEO // remove subsumed adjacent area TheNavAreas.FindAndRemove( adj ); diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 0b0f772fd6..d6aa8ca6d5 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -103,56 +103,11 @@ class ApproachAreaCost }; -#ifdef NEO -//-------------------------------------------------------------------------------------------------------------- -enum AreaLookupType -{ - AREA_LOOKUP_GRID, - AREA_LOOKUP_ALL_AREAS, -}; - -// Merging grows areas without re-adding them to the grid, so during generation -// a grid lookup can miss the part of an area added by a merge. -static CNavArea *GetAreaBeneathFromAllAreas( const Vector &pos, float beneathLimit ) -{ - // Same probe lift as CNavMesh::GetNavArea. - const float probeLift = 5.0f; - const Vector testPos = pos + Vector( 0, 0, probeLift ); - CNavArea *use = NULL; - float useZ = -FLT_MAX; - - FOR_EACH_VEC( TheNavAreas, it ) - { - CNavArea *area = TheNavAreas[ it ]; - if (!area->IsOverlapping( testPos )) - { - continue; - } - - const float z = area->GetZ( testPos ); - if (z > testPos.z || z < pos.z - beneathLimit || z <= useZ) - { - continue; - } - - use = area; - useZ = z; - } - - return use; -} - - -#endif // NEO //-------------------------------------------------------------------------------------------------------------- /** * Start at given position and find first area in given direction */ -#ifdef NEO -inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, float range, float beneathLimit, CBaseEntity *traceIgnore = NULL, Vector *closePos = NULL, AreaLookupType lookup = AREA_LOOKUP_GRID ) -#else inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, float range, float beneathLimit, CBaseEntity *traceIgnore = NULL, Vector *closePos = NULL ) -#endif // NEO { CNavArea *area = NULL; @@ -172,11 +127,7 @@ inline CNavArea *findFirstAreaInDirection( const Vector *start, NavDirType dir, if (result.fraction < 1.0f) break; -#ifdef NEO - area = (lookup == AREA_LOOKUP_ALL_AREAS) ? GetAreaBeneathFromAllAreas( pos, beneathLimit ) : TheNavMesh->GetNavArea( pos, beneathLimit ); -#else area = TheNavMesh->GetNavArea( pos, beneathLimit ); -#endif // NEO if (area) { if (closePos) @@ -548,24 +499,19 @@ static CNavArea *FindLadderBottomArea( const Vector ¢er, NavLadderSourceType //-------------------------------------------------------------------------------------------------------------- /** - * Find the areas at the top of a brush ladder, searching all areas rather than the grid. + * Retry the top scans of a brush ladder that found no exit, and drop a forward area far below the top. */ -static void FindBrushLadderTopAreas( CNavLadder *ladder, const Vector ¢er, float beneathLimit, float nearLadderRange ) +static void RetryBrushLadderTopScans( CNavLadder *ladder, const Vector ¢er, float beneathLimit, float nearLadderRange ) { const float behindLadderRange = 2.0f * nearLadderRange; const NavDirType dir = ladder->GetDir(); auto findTopArea = [&]( const Vector &start, NavDirType searchDir, float range ) -> CNavArea * { - CNavArea *area = findFirstAreaInDirection( &start, searchDir, range, beneathLimit, NULL, NULL, AREA_LOOKUP_ALL_AREAS ); + CNavArea *area = findFirstAreaInDirection( &start, searchDir, range, beneathLimit, NULL ); return (area == ladder->m_bottomArea) ? NULL : area; }; - ladder->m_topForwardArea = findTopArea( center, OppositeDirection( dir ), nearLadderRange ); - ladder->m_topLeftArea = findTopArea( center, DirectionLeft( dir ), nearLadderRange ); - ladder->m_topRightArea = findTopArea( center, DirectionRight( dir ), nearLadderRange ); - ladder->m_topBehindArea = findTopArea( center, dir, behindLadderRange ); - // A climbable brush can end below the landing, where the scan hits the landing's lip. // Or the space above its top can be solid (a ceiling or prop), so the scan starts inside it. const float topRetryOffsets[] = { StepHeight, -GenerationStepSize }; @@ -668,8 +614,7 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) if (source == NAV_LADDER_SOURCE_BRUSH) { - // A grid lookup misses the parts merging added to an area, so search again over all areas. - FindBrushLadderTopAreas( this, center, beneathLimit, nearLadderRange ); + RetryBrushLadderTopScans( this, center, beneathLimit, nearLadderRange ); } #endif // NEO diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index 3d289c7219..bd22d66209 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -550,6 +550,33 @@ void CNavMesh::AddNavArea( CNavArea *area ) ++m_areaCount; } +#ifdef NEO +//-------------------------------------------------------------------------------------------------------------- +/** + * Add an area to every grid cell of its extent that does not hold it yet. + * Merging grows an area in place, so its new part would otherwise be missing from the grid. + */ +void CNavMesh::AddNavAreaToGrid( CNavArea *area ) +{ + const int loX = WorldToGridX( area->GetCorner( NORTH_WEST ).x ); + const int loY = WorldToGridY( area->GetCorner( NORTH_WEST ).y ); + const int hiX = WorldToGridX( area->GetCorner( SOUTH_EAST ).x ); + const int hiY = WorldToGridY( area->GetCorner( SOUTH_EAST ).y ); + + for ( int y = loY; y <= hiY; ++y ) + { + for ( int x = loX; x <= hiX; ++x ) + { + NavAreaVector &cell = m_grid[ x + y*m_gridSizeX ]; + if ( !cell.HasElement( area ) ) + { + cell.AddToTail( area ); + } + } + } +} + +#endif // NEO //-------------------------------------------------------------------------------------------------------------- /** * Remove an area from the mesh diff --git a/src/game/server/nav_mesh.h b/src/game/server/nav_mesh.h index b6270c0feb..ccfa2bfab2 100644 --- a/src/game/server/nav_mesh.h +++ b/src/game/server/nav_mesh.h @@ -1139,6 +1139,9 @@ class CNavMesh : public CGameEventListener void GridToWorld( int gridX, int gridY, Vector *pos ) const; void AddNavArea( CNavArea *area ); // add an area to the grid +#ifdef NEO + void AddNavAreaToGrid( CNavArea *area ); // add an area to grid cells its grown extent now covers +#endif // NEO void DestroyNavigationMesh( bool incremental = false ); // free all resources of the mesh and reset it to empty state void DestroyHidingSpots( void ); From 551ab836b995ca9f6bbd29a45822bb6ac655d058 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Thu, 12 Nov 2026 19:51:12 -0700 Subject: [PATCH 29/31] Close blank gaps before NEO guard ends Keep the blank separator lines after #endif instead of before it, with the non-NEO text unchanged. --- src/game/server/nav_generate.cpp | 9 ++++----- src/game/server/nav_ladder.h | 4 ++-- src/game/server/nav_mesh.cpp | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index d6aa8ca6d5..991d12e3f9 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -276,9 +276,9 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m // add ladder to global list m_ladders.AddToTail( ladder ); } +#ifdef NEO -#ifdef NEO //-------------------------------------------------------------------------------------------------------------- static const float LadderEndScanStep = 10.0f; @@ -355,9 +355,9 @@ static bool TrimLadderEnds( CNavLadder *ladder, NavLadderSourceType source ) rejectReason, length, finalSignedSpan ); return false; } +#endif // NEO -#endif // NEO //-------------------------------------------------------------------------------------------------------------- /** * Create a navigation representation of a ladder. @@ -470,9 +470,9 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt // add ladder to global list m_ladders.AddToTail( ladder ); } +#ifdef NEO -#ifdef NEO //-------------------------------------------------------------------------------------------------------------- /** * Find the area at the bottom of a generated ladder. @@ -546,9 +546,9 @@ static void RetryBrushLadderTopScans( CNavLadder *ladder, const Vector ¢er, ladder->m_topForwardArea = NULL; } } +#endif // NEO -#endif // NEO //-------------------------------------------------------------------------------------------------------------- #ifdef NEO void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea, NavLadderSourceType source ) @@ -3660,7 +3660,6 @@ void CNavMesh::BeginGeneration( bool incremental ) } return; } - #endif IGameEvent *event = gameeventmanager->CreateEvent( "nav_generate" ); if ( event ) diff --git a/src/game/server/nav_ladder.h b/src/game/server/nav_ladder.h index 0679184a08..d686c57c09 100644 --- a/src/game/server/nav_ladder.h +++ b/src/game/server/nav_ladder.h @@ -14,15 +14,15 @@ #include "nav.h" class CNavArea; - #ifdef NEO + enum NavLadderSourceType { NAV_LADDER_SOURCE_DEFAULT, NAV_LADDER_SOURCE_BRUSH, ///< built from a climbable brush of the BSP }; - #endif // NEO + //-------------------------------------------------------------------------------------------------------------- /** * The NavLadder represents ladders in the Navigation Mesh, and their connections to adjacent NavAreas diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index bd22d66209..d511341069 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -549,8 +549,8 @@ void CNavMesh::AddNavArea( CNavArea *area ) ++m_areaCount; } - #ifdef NEO + //-------------------------------------------------------------------------------------------------------------- /** * Add an area to every grid cell of its extent that does not hold it yet. @@ -575,8 +575,8 @@ void CNavMesh::AddNavAreaToGrid( CNavArea *area ) } } } - #endif // NEO + //-------------------------------------------------------------------------------------------------------------- /** * Remove an area from the mesh From 63d57179cfc188632b44028954d85001d4e0d461 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Thu, 12 Nov 2026 19:58:21 -0700 Subject: [PATCH 30/31] Keep blank separator lines after NEO guard ends Put the separator lines before #ifdef NEO back where the SDK has them and keep the ones after #endif. --- src/game/server/nav_generate.cpp | 5 +++-- src/game/server/nav_ladder.h | 2 +- src/game/server/nav_mesh.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index 991d12e3f9..c4b1a255c9 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -276,9 +276,9 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m // add ladder to global list m_ladders.AddToTail( ladder ); } -#ifdef NEO +#ifdef NEO //-------------------------------------------------------------------------------------------------------------- static const float LadderEndScanStep = 10.0f; @@ -470,9 +470,9 @@ void CNavMesh::CreateLadder( const Vector &top, const Vector &bottom, float widt // add ladder to global list m_ladders.AddToTail( ladder ); } -#ifdef NEO +#ifdef NEO //-------------------------------------------------------------------------------------------------------------- /** * Find the area at the bottom of a generated ladder. @@ -3661,6 +3661,7 @@ void CNavMesh::BeginGeneration( bool incremental ) return; } #endif + IGameEvent *event = gameeventmanager->CreateEvent( "nav_generate" ); if ( event ) { diff --git a/src/game/server/nav_ladder.h b/src/game/server/nav_ladder.h index d686c57c09..e24ef224ae 100644 --- a/src/game/server/nav_ladder.h +++ b/src/game/server/nav_ladder.h @@ -14,8 +14,8 @@ #include "nav.h" class CNavArea; -#ifdef NEO +#ifdef NEO enum NavLadderSourceType { NAV_LADDER_SOURCE_DEFAULT, diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index d511341069..fa46c15270 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -549,8 +549,8 @@ void CNavMesh::AddNavArea( CNavArea *area ) ++m_areaCount; } -#ifdef NEO +#ifdef NEO //-------------------------------------------------------------------------------------------------------------- /** * Add an area to every grid cell of its extent that does not hold it yet. From 52d52f81fd8e06f307d1939cd64beb4d65b538a5 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Fri, 13 Nov 2026 21:52:25 -0700 Subject: [PATCH 31/31] Keep the SDK DrawLine macro for old call sites The brush ladder debug helper honored its duration and shadowed the SDK macro, which ignores it, so the existing sniper spot and ladder edit lines stayed up for 3 seconds. Give the helper its own name. Also make LadderEndScanStep constexpr. --- src/game/server/nav_generate.cpp | 2 +- src/game/server/nav_mesh.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game/server/nav_generate.cpp b/src/game/server/nav_generate.cpp index c4b1a255c9..d881772b8b 100644 --- a/src/game/server/nav_generate.cpp +++ b/src/game/server/nav_generate.cpp @@ -280,7 +280,7 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m #ifdef NEO //-------------------------------------------------------------------------------------------------------------- -static const float LadderEndScanStep = 10.0f; +static constexpr float LadderEndScanStep = 10.0f; /** * Move a ladder end along the ladder until the space in front of it is clear. diff --git a/src/game/server/nav_mesh.cpp b/src/game/server/nav_mesh.cpp index fa46c15270..fce5c5cad2 100644 --- a/src/game/server/nav_mesh.cpp +++ b/src/game/server/nav_mesh.cpp @@ -41,14 +41,14 @@ #include "tier0/memdbgon.h" +#define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ) + #ifdef NEO -static auto DrawLine(const Vector& from, const Vector& to, float duration = NDEBUG_PERSIST_TILL_NEXT_SERVER, +static auto DrawBrushLadderLine(const Vector& from, const Vector& to, float duration = NDEBUG_PERSIST_TILL_NEXT_SERVER, int r = 255, int g=255, int b=255) { return NDebugOverlay::Line(from, to, r, g, b, true, duration); } -#else -#define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ) #endif @@ -3651,7 +3651,7 @@ void CNavMesh::LadderFromPolyhedron(const CPolyhedron* polyhedron) static int r = 0; r = (r + 25) % 255; - DrawLine(linePos1, linePos2, + DrawBrushLadderLine(linePos1, linePos2, nav_generate_debug_brushladders.GetFloat(), r, 255, 255); } } @@ -3717,7 +3717,7 @@ void CNavMesh::LadderFromPolyhedron(const CPolyhedron* polyhedron) } DevMsg("\t\tPOLY NORMAL: %f %f %f\n", polyNormal.x, polyNormal.y, polyNormal.z); - DrawLine(polyCenter, polyCenter + (polyNormal * GenerationStepSize), + DrawBrushLadderLine(polyCenter, polyCenter + (polyNormal * GenerationStepSize), nav_generate_debug_brushladders.GetFloat(), c.r(), c.g(), c.b()); }