From a10dae89cd8b7088739c5df577edd97603750df8 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 10 Jun 2023 12:37:39 +0900 Subject: [PATCH] add detail information at DtStatus --- src/DotRecast.Detour/DtNavMesh.cs | 20 ++++----- src/DotRecast.Detour/DtNavMeshQuery.cs | 42 +++++++++---------- src/DotRecast.Detour/DtStatus.cs | 25 +++++++---- src/DotRecast.Detour/DtStatusExtension.cs | 8 ++-- src/DotRecast.Detour/LegacyNavMeshQuery.cs | 18 ++++---- src/DotRecast.Detour/QueryResults/Result.cs | 14 +++---- .../Tools/TestNavmeshTool.cs | 4 +- .../UnityAStarPathfindingImporterTest.cs | 2 +- test/DotRecast.Detour.Test/FindPathTest.cs | 8 ++-- .../TiledFindPathTest.cs | 2 +- .../TileCacheNavigationTest.cs | 2 +- 11 files changed, 78 insertions(+), 67 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 92342d8..c3d65a7 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -1568,31 +1568,31 @@ namespace DotRecast.Detour { if (refs == 0) { - return DtStatus.FAILURE; + return DtStatus.DT_FAILURE; } DecodePolyId(refs, out var salt, out var it, out var ip); if (it >= m_maxTiles) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } if (m_tiles[it].salt != salt || m_tiles[it].data == null || m_tiles[it].data.header == null) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } DtMeshTile tile = m_tiles[it]; if (ip >= tile.data.header.polyCount) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } DtPoly poly = tile.data.polys[ip]; // Change flags. poly.flags = flags; - return DtStatus.SUCCSESS; + return DtStatus.DT_SUCCSESS; } public Result GetPolyFlags(long refs) @@ -1628,31 +1628,31 @@ namespace DotRecast.Detour { if (refs == 0) { - return DtStatus.FAILURE; + return DtStatus.DT_FAILURE; } DecodePolyId(refs, out var salt, out var it, out var ip); if (it >= m_maxTiles) { - return DtStatus.FAILURE; + return DtStatus.DT_FAILURE; } if (m_tiles[it].salt != salt || m_tiles[it].data == null || m_tiles[it].data.header == null) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } DtMeshTile tile = m_tiles[it]; if (ip >= tile.data.header.polyCount) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } DtPoly poly = tile.data.polys[ip]; poly.SetArea(area); - return DtStatus.SUCCSESS; + return DtStatus.DT_SUCCSESS; } public Result GetPolyArea(long refs) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 64e63d5..581ca4a 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -678,7 +678,7 @@ namespace DotRecast.Detour { if (!RcVec3f.IsFinite(center) || !RcVec3f.IsFinite(halfExtents) || null == filter) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } // Find tiles the query touches. @@ -689,7 +689,7 @@ namespace DotRecast.Detour QueryPolygonsInTile(t, bmin, bmax, filter, query); } - return DtStatus.SUCCSESS; + return DtStatus.DT_SUCCSESS; } /** @@ -793,7 +793,7 @@ namespace DotRecast.Detour DtNode lastBestNode = startNode; float lastBestNodeCost = startNode.total; - DtStatus status = DtStatus.SUCCSESS; + DtStatus status = DtStatus.DT_SUCCSESS; while (!m_openList.IsEmpty()) { @@ -979,7 +979,7 @@ namespace DotRecast.Detour if (lastBestNode.id != endRef) { - status = DtStatus.PARTIAL_RESULT; + status = DtStatus.DT_PARTIAL_RESULT; } return Results.Of(status, path); @@ -1022,7 +1022,7 @@ namespace DotRecast.Detour { // Init path state. m_query = new DtQueryData(); - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; m_query.startRef = startRef; m_query.endRef = endRef; m_query.startPos = startPos; @@ -1035,7 +1035,7 @@ namespace DotRecast.Detour // Validate input if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter) { - return DtStatus.FAILURE_INVALID_PARAM; + return DtStatus.DT_INVALID_PARAM; } // trade quality with performance? @@ -1050,8 +1050,8 @@ namespace DotRecast.Detour if (startRef == endRef) { - m_query.status = DtStatus.SUCCSESS; - return DtStatus.SUCCSESS; + m_query.status = DtStatus.DT_SUCCSESS; + return DtStatus.DT_SUCCSESS; } m_nodePool.Clear(); @@ -1066,7 +1066,7 @@ namespace DotRecast.Detour startNode.flags = DtNode.DT_NODE_OPEN; m_openList.Push(startNode); - m_query.status = DtStatus.IN_PROGRESS; + m_query.status = DtStatus.DT_IN_PROGRESS; m_query.lastBestNode = startNode; m_query.lastBestNodeCost = startNode.total; @@ -1090,7 +1090,7 @@ namespace DotRecast.Detour // Make sure the request is still valid. if (!m_nav.IsValidPolyRef(m_query.startRef) || !m_nav.IsValidPolyRef(m_query.endRef)) { - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; return Results.Of(m_query.status, 0); } @@ -1108,7 +1108,7 @@ namespace DotRecast.Detour if (bestNode.id == m_query.endRef) { m_query.lastBestNode = bestNode; - m_query.status = DtStatus.SUCCSESS; + m_query.status = DtStatus.DT_SUCCSESS; return Results.Of(m_query.status, iter); } @@ -1119,7 +1119,7 @@ namespace DotRecast.Detour Result> tileAndPoly = m_nav.GetTileAndPolyByRef(bestRef); if (tileAndPoly.Failed()) { - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; // The polygon has disappeared during the sliced query, fail. return Results.Of(m_query.status, iter); } @@ -1150,7 +1150,7 @@ namespace DotRecast.Detour { // The polygon has disappeared during the sliced query, // fail. - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; return Results.Of(m_query.status, iter); } @@ -1308,7 +1308,7 @@ namespace DotRecast.Detour // Exhausted all nodes, but could not find path. if (m_openList.IsEmpty()) { - m_query.status = DtStatus.PARTIAL_RESULT; + m_query.status = DtStatus.DT_PARTIAL_RESULT; } return Results.Of(m_query.status, iter); @@ -1338,7 +1338,7 @@ namespace DotRecast.Detour // Reverse the path. if (m_query.lastBestNode.id != m_query.endRef) { - m_query.status = DtStatus.PARTIAL_RESULT; + m_query.status = DtStatus.DT_PARTIAL_RESULT; } path = GetPathToNode(m_query.lastBestNode); @@ -1393,7 +1393,7 @@ namespace DotRecast.Detour if (node == null) { - m_query.status = DtStatus.PARTIAL_RESULT; + m_query.status = DtStatus.DT_PARTIAL_RESULT; node = m_query.lastBestNode; } @@ -1427,11 +1427,11 @@ namespace DotRecast.Detour // If reached end of path or there is no space to append more vertices, return. if (flags == DT_STRAIGHTPATH_END || straightPath.Count >= maxStraightPath) { - return DtStatus.SUCCSESS; + return DtStatus.DT_SUCCSESS; } } - return DtStatus.IN_PROGRESS; + return DtStatus.DT_IN_PROGRESS; } protected DtStatus AppendPortals(int startIdx, int endIdx, RcVec3f endPos, List path, @@ -1447,7 +1447,7 @@ namespace DotRecast.Detour Result> tileAndPoly = m_nav.GetTileAndPolyByRef(from); if (tileAndPoly.Failed()) { - return DtStatus.FAILURE; + return DtStatus.DT_FAILURE; } DtMeshTile fromTile = tileAndPoly.result.Item1; @@ -1457,7 +1457,7 @@ namespace DotRecast.Detour tileAndPoly = m_nav.GetTileAndPolyByRef(to); if (tileAndPoly.Failed()) { - return DtStatus.FAILURE; + return DtStatus.DT_FAILURE; } DtMeshTile toTile = tileAndPoly.result.Item1; @@ -1493,7 +1493,7 @@ namespace DotRecast.Detour } } - return DtStatus.IN_PROGRESS; + return DtStatus.DT_IN_PROGRESS; } /// @par diff --git a/src/DotRecast.Detour/DtStatus.cs b/src/DotRecast.Detour/DtStatus.cs index fd096e4..be9e059 100644 --- a/src/DotRecast.Detour/DtStatus.cs +++ b/src/DotRecast.Detour/DtStatus.cs @@ -22,15 +22,26 @@ namespace DotRecast.Detour { public class DtStatus { - public static readonly DtStatus FAILURE = new DtStatus(0); - public static readonly DtStatus SUCCSESS = new DtStatus(1); - public static readonly DtStatus IN_PROGRESS = new DtStatus(2); - public static readonly DtStatus PARTIAL_RESULT = new DtStatus(3); - public static readonly DtStatus FAILURE_INVALID_PARAM = new DtStatus(4); + // 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. + public static readonly DtStatus DT_IN_PROGRESS = new DtStatus(1u << 29); // Operation still in progress. - public readonly int Value; + // Detail information for status. + public static readonly DtStatus DT_STATUS_DETAIL_MASK = new DtStatus(0x0ffffff); + public static readonly DtStatus DT_WRONG_MAGIC = new DtStatus(1 << 0); // Input data is not recognized. + public static readonly DtStatus DT_WRONG_VERSION = new DtStatus(1 << 1); // Input data is in wrong version. + public static readonly DtStatus DT_OUT_OF_MEMORY = new DtStatus(1 << 2); // Operation ran out of memory. + public static readonly DtStatus DT_INVALID_PARAM = new DtStatus(1 << 3); // An input parameter was invalid. + public static readonly DtStatus DT_BUFFER_TOO_SMALL = new DtStatus(1 << 4); // Result buffer for the query was too small to store all results. + public static readonly DtStatus DT_OUT_OF_NODES = new DtStatus(1 << 5); // Query ran out of nodes during search. + public static readonly DtStatus DT_PARTIAL_RESULT = new DtStatus(1 << 6); // Query did not reach the end location, returning best guess. + public static readonly DtStatus DT_ALREADY_OCCUPIED = new DtStatus(1 << 7); // A tile has already been assigned to the given x,y coordinate - private DtStatus(int value) + + public readonly uint Value; + + private DtStatus(uint value) { Value = value; } diff --git a/src/DotRecast.Detour/DtStatusExtension.cs b/src/DotRecast.Detour/DtStatusExtension.cs index 20c62bc..8d0da09 100644 --- a/src/DotRecast.Detour/DtStatusExtension.cs +++ b/src/DotRecast.Detour/DtStatusExtension.cs @@ -4,22 +4,22 @@ { public static bool IsSuccess(this DtStatus @this) { - return @this == DtStatus.SUCCSESS || @this == DtStatus.PARTIAL_RESULT; + return @this == DtStatus.DT_SUCCSESS || @this == DtStatus.DT_PARTIAL_RESULT; } public static bool IsFailed(this DtStatus @this) { - return @this == DtStatus.FAILURE || @this == DtStatus.FAILURE_INVALID_PARAM; + return @this == DtStatus.DT_FAILURE || @this == DtStatus.DT_INVALID_PARAM; } public static bool IsInProgress(this DtStatus @this) { - return @this == DtStatus.IN_PROGRESS; + return @this == DtStatus.DT_IN_PROGRESS; } public static bool IsPartial(this DtStatus @this) { - return @this == DtStatus.PARTIAL_RESULT; + return @this == DtStatus.DT_PARTIAL_RESULT; } } } \ No newline at end of file diff --git a/src/DotRecast.Detour/LegacyNavMeshQuery.cs b/src/DotRecast.Detour/LegacyNavMeshQuery.cs index 8bc6528..defd50d 100644 --- a/src/DotRecast.Detour/LegacyNavMeshQuery.cs +++ b/src/DotRecast.Detour/LegacyNavMeshQuery.cs @@ -70,7 +70,7 @@ namespace DotRecast.Detour DtNode lastBestNode = startNode; float lastBestNodeCost = startNode.total; - DtStatus status = DtStatus.SUCCSESS; + DtStatus status = DtStatus.DT_SUCCSESS; while (!m_openList.IsEmpty()) { @@ -215,7 +215,7 @@ namespace DotRecast.Detour if (lastBestNode.id != endRef) { - status = DtStatus.PARTIAL_RESULT; + status = DtStatus.DT_PARTIAL_RESULT; } return Results.Of(status, path); @@ -238,7 +238,7 @@ namespace DotRecast.Detour // Make sure the request is still valid. if (!m_nav.IsValidPolyRef(m_query.startRef) || !m_nav.IsValidPolyRef(m_query.endRef)) { - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; return Results.Of(m_query.status, 0); } @@ -256,7 +256,7 @@ namespace DotRecast.Detour if (bestNode.id == m_query.endRef) { m_query.lastBestNode = bestNode; - m_query.status = DtStatus.SUCCSESS; + m_query.status = DtStatus.DT_SUCCSESS; return Results.Of(m_query.status, iter); } @@ -267,7 +267,7 @@ namespace DotRecast.Detour Result> tileAndPoly = m_nav.GetTileAndPolyByRef(bestRef); if (tileAndPoly.Failed()) { - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; // The polygon has disappeared during the sliced query, fail. return Results.Of(m_query.status, iter); } @@ -298,7 +298,7 @@ namespace DotRecast.Detour { // The polygon has disappeared during the sliced query, // fail. - m_query.status = DtStatus.FAILURE; + m_query.status = DtStatus.DT_FAILURE; return Results.Of(m_query.status, iter); } @@ -454,7 +454,7 @@ namespace DotRecast.Detour // Exhausted all nodes, but could not find path. if (m_openList.IsEmpty()) { - m_query.status = DtStatus.PARTIAL_RESULT; + m_query.status = DtStatus.DT_PARTIAL_RESULT; } return Results.Of(m_query.status, iter); @@ -484,7 +484,7 @@ namespace DotRecast.Detour // Reverse the path. if (m_query.lastBestNode.id != m_query.endRef) { - m_query.status = DtStatus.PARTIAL_RESULT; + m_query.status = DtStatus.DT_PARTIAL_RESULT; } DtNode prev = null; @@ -581,7 +581,7 @@ namespace DotRecast.Detour if (node == null) { - m_query.status = DtStatus.PARTIAL_RESULT; + m_query.status = DtStatus.DT_PARTIAL_RESULT; node = m_query.lastBestNode; } diff --git a/src/DotRecast.Detour/QueryResults/Result.cs b/src/DotRecast.Detour/QueryResults/Result.cs index b23d972..f0a1bcd 100644 --- a/src/DotRecast.Detour/QueryResults/Result.cs +++ b/src/DotRecast.Detour/QueryResults/Result.cs @@ -24,37 +24,37 @@ namespace DotRecast.Detour.QueryResults { public static Result Success(T result) { - return new Result(result, DtStatus.SUCCSESS, null); + return new Result(result, DtStatus.DT_SUCCSESS, null); } public static Result Failure() { - return new Result(default, DtStatus.FAILURE, null); + return new Result(default, DtStatus.DT_FAILURE, null); } public static Result InvalidParam() { - return new Result(default, DtStatus.FAILURE_INVALID_PARAM, null); + return new Result(default, DtStatus.DT_INVALID_PARAM, null); } public static Result Failure(string message) { - return new Result(default, DtStatus.FAILURE, message); + return new Result(default, DtStatus.DT_FAILURE, message); } public static Result InvalidParam(string message) { - return new Result(default, DtStatus.FAILURE_INVALID_PARAM, message); + return new Result(default, DtStatus.DT_INVALID_PARAM, message); } public static Result Failure(T result) { - return new Result(result, DtStatus.FAILURE, null); + return new Result(result, DtStatus.DT_FAILURE, null); } public static Result Partial(T result) { - return new Result(default, DtStatus.PARTIAL_RESULT, null); + return new Result(default, DtStatus.DT_PARTIAL_RESULT, null); } public static Result Of(DtStatus status, string message) diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index f998801..ffd3a43 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -40,7 +40,7 @@ public class TestNavmeshTool : ITool private float m_neighbourhoodRadius; private readonly float[] m_queryPoly = new float[12]; private List m_smoothPath; - private DtStatus m_pathFindStatus = DtStatus.FAILURE; + private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE; private bool enableRaycast = true; private readonly List randomPoints = new(); private bool constrainByCircle; @@ -1011,7 +1011,7 @@ public class TestNavmeshTool : ITool } } - m_pathFindStatus = DtStatus.FAILURE; + m_pathFindStatus = DtStatus.DT_FAILURE; } } } diff --git a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs index c38cd2d..0316598 100644 --- a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs +++ b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs @@ -37,7 +37,7 @@ public class UnityAStarPathfindingImporterTest RcVec3f startPos = RcVec3f.Of(8.200293f, 2.155071f, -26.176147f); RcVec3f endPos = RcVec3f.Of(11.971109f, 0.000000f, 8.663261f); Result> path = FindPath(mesh, startPos, endPos); - Assert.That(path.status, Is.EqualTo(DtStatus.SUCCSESS)); + Assert.That(path.status, Is.EqualTo(DtStatus.DT_SUCCSESS)); Assert.That(path.result.Count, Is.EqualTo(57)); SaveMesh(mesh, "v4_0_6"); } diff --git a/test/DotRecast.Detour.Test/FindPathTest.cs b/test/DotRecast.Detour.Test/FindPathTest.cs index 7b33b0b..325d782 100644 --- a/test/DotRecast.Detour.Test/FindPathTest.cs +++ b/test/DotRecast.Detour.Test/FindPathTest.cs @@ -28,8 +28,8 @@ public class FindPathTest : AbstractDetourTest { private static readonly DtStatus[] STATUSES = { - DtStatus.SUCCSESS, DtStatus.PARTIAL_RESULT, DtStatus.SUCCSESS, DtStatus.SUCCSESS, - DtStatus.SUCCSESS + DtStatus.DT_SUCCSESS, DtStatus.DT_PARTIAL_RESULT, DtStatus.DT_SUCCSESS, DtStatus.DT_SUCCSESS, + DtStatus.DT_SUCCSESS }; private static readonly long[][] RESULTS = @@ -159,8 +159,8 @@ public class FindPathTest : AbstractDetourTest var startPos = startPoss[i]; var endPos = endPoss[i]; query.InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE); - DtStatus status = DtStatus.IN_PROGRESS; - while (status == DtStatus.IN_PROGRESS) + DtStatus status = DtStatus.DT_IN_PROGRESS; + while (status == DtStatus.DT_IN_PROGRESS) { Result res = query.UpdateSlicedFindPath(10); status = res.status; diff --git a/test/DotRecast.Detour.Test/TiledFindPathTest.cs b/test/DotRecast.Detour.Test/TiledFindPathTest.cs index b378e84..1030c18 100644 --- a/test/DotRecast.Detour.Test/TiledFindPathTest.cs +++ b/test/DotRecast.Detour.Test/TiledFindPathTest.cs @@ -26,7 +26,7 @@ namespace DotRecast.Detour.Test; [Parallelizable] public class TiledFindPathTest { - private static readonly DtStatus[] STATUSES = { DtStatus.SUCCSESS }; + private static readonly DtStatus[] STATUSES = { DtStatus.DT_SUCCSESS }; private static readonly long[][] RESULTS = { diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs index 6e6c86d..fb51a0c 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs @@ -34,7 +34,7 @@ public class TileCacheNavigationTest : AbstractTileCacheTest protected readonly long[] endRefs = { 281474986147841L }; protected readonly RcVec3f[] startPoss = { RcVec3f.Of(39.447338f, 9.998177f, -0.784811f) }; protected readonly RcVec3f[] endPoss = { RcVec3f.Of(19.292645f, 11.611748f, -57.750366f) }; - private readonly DtStatus[] statuses = { DtStatus.SUCCSESS }; + private readonly DtStatus[] statuses = { DtStatus.DT_SUCCSESS }; private readonly long[][] results = {