add detail information at DtStatus

This commit is contained in:
ikpil 2023-06-10 12:37:39 +09:00
parent c42d89003b
commit a10dae89cd
11 changed files with 78 additions and 67 deletions

View File

@ -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<int> 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<int> GetPolyArea(long refs)

View File

@ -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<Tuple<DtMeshTile, DtPoly>> 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<long> path,
@ -1447,7 +1447,7 @@ namespace DotRecast.Detour
Result<Tuple<DtMeshTile, DtPoly>> 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

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

@ -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<Tuple<DtMeshTile, DtPoly>> 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;
}

View File

@ -24,37 +24,37 @@ namespace DotRecast.Detour.QueryResults
{
public static Result<T> Success<T>(T result)
{
return new Result<T>(result, DtStatus.SUCCSESS, null);
return new Result<T>(result, DtStatus.DT_SUCCSESS, null);
}
public static Result<T> Failure<T>()
{
return new Result<T>(default, DtStatus.FAILURE, null);
return new Result<T>(default, DtStatus.DT_FAILURE, null);
}
public static Result<T> InvalidParam<T>()
{
return new Result<T>(default, DtStatus.FAILURE_INVALID_PARAM, null);
return new Result<T>(default, DtStatus.DT_INVALID_PARAM, null);
}
public static Result<T> Failure<T>(string message)
{
return new Result<T>(default, DtStatus.FAILURE, message);
return new Result<T>(default, DtStatus.DT_FAILURE, message);
}
public static Result<T> InvalidParam<T>(string message)
{
return new Result<T>(default, DtStatus.FAILURE_INVALID_PARAM, message);
return new Result<T>(default, DtStatus.DT_INVALID_PARAM, message);
}
public static Result<T> Failure<T>(T result)
{
return new Result<T>(result, DtStatus.FAILURE, null);
return new Result<T>(result, DtStatus.DT_FAILURE, null);
}
public static Result<T> Partial<T>(T result)
{
return new Result<T>(default, DtStatus.PARTIAL_RESULT, null);
return new Result<T>(default, DtStatus.DT_PARTIAL_RESULT, null);
}
public static Result<T> Of<T>(DtStatus status, string message)

View File

@ -40,7 +40,7 @@ public class TestNavmeshTool : ITool
private float m_neighbourhoodRadius;
private readonly float[] m_queryPoly = new float[12];
private List<RcVec3f> m_smoothPath;
private DtStatus m_pathFindStatus = DtStatus.FAILURE;
private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE;
private bool enableRaycast = true;
private readonly List<RcVec3f> randomPoints = new();
private bool constrainByCircle;
@ -1011,7 +1011,7 @@ public class TestNavmeshTool : ITool
}
}
m_pathFindStatus = DtStatus.FAILURE;
m_pathFindStatus = DtStatus.DT_FAILURE;
}
}
}

View File

@ -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<List<long>> 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");
}

View File

@ -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<int> res = query.UpdateSlicedFindPath(10);
status = res.status;

View File

@ -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 =
{

View File

@ -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 =
{