diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 3ccaa1e..1f69989 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -426,13 +426,14 @@ namespace DotRecast.Detour.Crowd public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter) { // Move along navmesh and update new position. - Result masResult = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter); - if (masResult.Succeeded()) + var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, out var visited); + if (status.Succeeded()) { - m_path = MergeCorridorStartMoved(m_path, masResult.result.GetVisited()); + m_path = MergeCorridorStartMoved(m_path, visited); + // Adjust the position to stay on top of the navmesh. - m_pos = masResult.result.GetResultPos(); - Result hr = navquery.GetPolyHeight(m_path[0], masResult.result.GetResultPos()); + m_pos = result; + Result hr = navquery.GetPolyHeight(m_path[0], result); if (hr.Succeeded()) { m_pos.y = hr.result; @@ -464,17 +465,17 @@ namespace DotRecast.Detour.Crowd public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter) { // Move along navmesh and update new position. - Result masResult = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter); - if (masResult.Succeeded()) + var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, out var visited); + if (status.Succeeded()) { - m_path = MergeCorridorEndMoved(m_path, masResult.result.GetVisited()); + m_path = MergeCorridorEndMoved(m_path, visited); // TODO: should we do that? // Adjust the position to stay on top of the navmesh. /* * float h = m_target.y; navquery->GetPolyHeight(m_path[m_npath-1], * result, &h); result.y = h; */ - m_target = masResult.result.GetResultPos(); + m_target = result; return true; } diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 0df7c70..0d5fa0f 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -1766,37 +1766,46 @@ namespace DotRecast.Detour /// @par /// - /// This method is optimized for small delta movement and a small number of - /// polygons. If used for too great a distance, the result set will form an + /// This method is optimized for small delta movement and a small number of + /// polygons. If used for too great a distance, the result set will form an /// incomplete path. /// - /// @p resultPos will equal the @p endPos if the end is reached. + /// @p resultPos will equal the @p endPos if the end is reached. /// Otherwise the closest reachable position will be returned. - /// - /// @p resultPos is not projected onto the surface of the navigation + /// + /// @p resultPos is not projected onto the surface of the navigation /// mesh. Use #getPolyHeight if this is needed. /// - /// This method treats the end position in the same manner as - /// the #raycast method. (As a 2D point.) See that method's documentation + /// This method treats the end position in the same manner as + /// the #raycast method. (As a 2D point.) See that method's documentation /// for details. - /// - /// If the @p visited array is too small to hold the entire result set, it will - /// be filled as far as possible from the start position toward the end + /// + /// If the @p visited array is too small to hold the entire result set, it will + /// be filled as far as possible from the start position toward the end /// position. /// /// Moves from the start to the end position constrained to the navigation mesh. - /// @param[in] startRef The reference id of the start polygon. - /// @param[in] startPos A position of the mover within the start polygon. [(x, y, x)] - /// @param[in] endPos The desired end position of the mover. [(x, y, z)] - /// @param[in] filter The polygon filter to apply to the query. - /// @returns Path - public Result MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter) + /// @param[in] startRef The reference id of the start polygon. + /// @param[in] startPos A position of the mover within the start polygon. [(x, y, x)] + /// @param[in] endPos The desired end position of the mover. [(x, y, z)] + /// @param[in] filter The polygon filter to apply to the query. + /// @param[out] resultPos The result position of the mover. [(x, y, z)] + /// @param[out] visited The reference ids of the polygons visited during the move. + /// @param[out] visitedCount The number of polygons visited during the move. + /// @param[in] maxVisitedSize The maximum number of polygons the @p visited array can hold. + /// @returns The status flags for the query. + public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos, + IDtQueryFilter filter, + out RcVec3f resultPos, out List visited) { + resultPos = RcVec3f.Zero; + visited = new List(); + // Validate input if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } DtNodePool tinyNodePool = new DtNodePool(); @@ -1932,7 +1941,6 @@ namespace DotRecast.Detour } } - List visited = new List(); if (bestNode != null) { // Reverse the path. @@ -1955,7 +1963,9 @@ namespace DotRecast.Detour } while (node != null); } - return Results.Success(new MoveAlongSurfaceResult(bestPos, visited)); + resultPos = bestPos; + + return DtStatus.DT_SUCCSESS; } protected Result GetPortalPoints(long from, long to) diff --git a/src/DotRecast.Detour/DtStatus.cs b/src/DotRecast.Detour/DtStatus.cs index 1872a6a..ae294bc 100644 --- a/src/DotRecast.Detour/DtStatus.cs +++ b/src/DotRecast.Detour/DtStatus.cs @@ -24,8 +24,6 @@ namespace DotRecast.Detour { public readonly struct DtStatus { - public static readonly DtStatus Empty = new DtStatus(0); - // High level status. public static readonly DtStatus DT_FAILURE = new DtStatus(1u << 31); // Operation failed. public static readonly DtStatus DT_SUCCSESS = new DtStatus(1u << 30); // Operation succeed. diff --git a/src/DotRecast.Detour/QueryResults/MoveAlongSurfaceResult.cs b/src/DotRecast.Detour/QueryResults/MoveAlongSurfaceResult.cs deleted file mode 100644 index 019f19b..0000000 --- a/src/DotRecast.Detour/QueryResults/MoveAlongSurfaceResult.cs +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright (c) 2009-2010 Mikko Mononen memon@inside.org -recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org -DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -using System.Collections.Generic; -using DotRecast.Core; - -namespace DotRecast.Detour.QueryResults -{ - public class MoveAlongSurfaceResult - { - /** The result position of the mover. [(x, y, z)] */ - private readonly RcVec3f resultPos; - - /** The reference ids of the polygons visited during the move. */ - private readonly List visited; - - public MoveAlongSurfaceResult(RcVec3f resultPos, List visited) - { - this.resultPos = resultPos; - this.visited = visited; - } - - public RcVec3f GetResultPos() - { - return resultPos; - } - - public List GetVisited() - { - return visited; - } - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 111f0c5..91c868b 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -238,20 +238,16 @@ public class TestNavmeshTool : IRcTool } RcVec3f moveTgt = RcVec3f.Mad(iterPos, delta, len); + // Move - Result result = m_navQuery.MoveAlongSurface(polys[0], iterPos, - moveTgt, m_filter); - MoveAlongSurfaceResult moveAlongSurface = result.result; + m_navQuery.MoveAlongSurface(polys[0], iterPos, moveTgt, m_filter, out var result, out var visited); - iterPos.x = moveAlongSurface.GetResultPos().x; - iterPos.y = moveAlongSurface.GetResultPos().y; - iterPos.z = moveAlongSurface.GetResultPos().z; + iterPos = result; - List visited = result.result.GetVisited(); polys = PathUtils.FixupCorridor(polys, visited); polys = PathUtils.FixupShortcuts(polys, m_navQuery); - Result polyHeight = m_navQuery.GetPolyHeight(polys[0], moveAlongSurface.GetResultPos()); + Result polyHeight = m_navQuery.GetPolyHeight(polys[0], result); if (polyHeight.Succeeded()) { iterPos.y = polyHeight.result; diff --git a/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs b/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs index 18d61b8..1da1c98 100644 --- a/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs +++ b/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs @@ -74,18 +74,18 @@ public class MoveAlongSurfaceTest : AbstractDetourTest long startRef = startRefs[i]; RcVec3f startPos = startPoss[i]; RcVec3f endPos = endPoss[i]; - Result result = query.MoveAlongSurface(startRef, startPos, endPos, filter); - Assert.That(result.Succeeded(), Is.True); - MoveAlongSurfaceResult path = result.result; + var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, out var visited); + Assert.That(status.Succeeded(), Is.True); + for (int v = 0; v < 3; v++) { - Assert.That(path.GetResultPos()[v], Is.EqualTo(POSITION[i][v]).Within(0.01f)); + Assert.That(result[v], Is.EqualTo(POSITION[i][v]).Within(0.01f)); } - Assert.That(path.GetVisited().Count, Is.EqualTo(VISITED[i].Length)); + Assert.That(visited.Count, Is.EqualTo(VISITED[i].Length)); for (int j = 0; j < POSITION[i].Length; j++) { - Assert.That(path.GetVisited()[j], Is.EqualTo(VISITED[i][j])); + Assert.That(visited[j], Is.EqualTo(VISITED[i][j])); } } }