diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 1f69989..36d1e85 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -430,13 +430,13 @@ namespace DotRecast.Detour.Crowd if (status.Succeeded()) { m_path = MergeCorridorStartMoved(m_path, visited); - + // Adjust the position to stay on top of the navmesh. m_pos = result; - Result hr = navquery.GetPolyHeight(m_path[0], result); - if (hr.Succeeded()) + status = navquery.GetPolyHeight(m_path[0], result, out var h); + if (status.Succeeded()) { - m_pos.y = hr.result; + m_pos.y = h; } return true; diff --git a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs index 7eae0e4..fdaaa31 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs @@ -50,13 +50,12 @@ namespace DotRecast.Detour.Extras.Jumplink RcAtomicFloat minHeight = new RcAtomicFloat(pt.y); navMeshQuery.QueryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) => { - Result h = navMeshQuery.GetPolyHeight(refs, pt); - if (h.Succeeded()) + var status = navMeshQuery.GetPolyHeight(refs, pt, out var h); + if (status.Succeeded()) { - float y = h.result; - if (y > minHeight.Get() && y < maxHeight) + if (h > minHeight.Get() && h < maxHeight) { - minHeight.Exchange(y); + minHeight.Exchange(h); found.Set(true); } } diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 0d5fa0f..73e1c30 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -529,17 +529,19 @@ namespace DotRecast.Detour /// @param[in] pos A position within the xz-bounds of the polygon. [(x, y, z)] /// @param[out] height The height at the surface of the polygon. /// @returns The status flags for the query. - public Result GetPolyHeight(long refs, RcVec3f pos) + public DtStatus GetPolyHeight(long refs, RcVec3f pos, out float height) { + height = default; + var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly); if (status.Failed()) { - return Results.Of(status, ""); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } if (!RcVec3f.IsFinite2D(pos)) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } // We used to return success for offmesh connections, but the @@ -551,12 +553,18 @@ namespace DotRecast.Detour var v0 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] }; i = poly.verts[1] * 3; var v1 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] }; - var distSqr = DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var tseg); - return Results.Success(v0.y + (v1.y - v0.y) * tseg); + DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var t); + height = v0.y + (v1.y - v0.y) * t; + + return DtStatus.DT_SUCCSESS; } - float? height = m_nav.GetPolyHeight(tile, poly, pos); - return null != height ? Results.Success(height.Value) : Results.InvalidParam(); + float? h = m_nav.GetPolyHeight(tile, poly, pos); + if (!h.HasValue) + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; + + height = h.Value; + return DtStatus.DT_SUCCSESS; } /// Finds the polygon nearest to the specified center point. diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 91c868b..7f74906 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -247,10 +247,10 @@ public class TestNavmeshTool : IRcTool polys = PathUtils.FixupCorridor(polys, visited); polys = PathUtils.FixupShortcuts(polys, m_navQuery); - Result polyHeight = m_navQuery.GetPolyHeight(polys[0], result); - if (polyHeight.Succeeded()) + var status = m_navQuery.GetPolyHeight(polys[0], result, out var h); + if (status.Succeeded()) { - iterPos.y = polyHeight.result; + iterPos.y = h; } // Handle end of path and off-mesh links when close enough. @@ -265,8 +265,7 @@ public class TestNavmeshTool : IRcTool break; } - else if (offMeshConnection - && PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f)) + else if (offMeshConnection && PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f)) { // Reached off-mesh connection. // Advance the path up to and over the off-mesh connection. @@ -300,7 +299,8 @@ public class TestNavmeshTool : IRcTool // Move position at the other side of the off-mesh link. iterPos = endPos; - iterPos.y = m_navQuery.GetPolyHeight(polys[0], iterPos).result; + m_navQuery.GetPolyHeight(polys[0], iterPos, out var eh); + iterPos.y = eh; } } @@ -383,11 +383,10 @@ public class TestNavmeshTool : IRcTool // Adjust height. if (hit.result.path.Count > 0) { - Result result = m_navQuery - .GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos); + var result = m_navQuery.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos, out var h); if (result.Succeeded()) { - m_hitPos.y = result.result; + m_hitPos.y = h; } } }