class DtStatus => readonly struct DtStatus

This commit is contained in:
ikpil 2023-06-10 13:48:00 +09:00
parent 7bca7922eb
commit b75537d0b1
6 changed files with 29 additions and 13 deletions

View File

@ -698,7 +698,7 @@ namespace DotRecast.Detour.Crowd
// _telemetry.RecordPathWaitTime(ag.targetReplanTime);
// Poll path queue.
DtStatus status = ag.targetPathQueryResult.status;
if (status != null && status.IsFailed())
if (status.IsFailed())
{
// Path find failed, retry if the target location is still
// valid.
@ -714,7 +714,7 @@ namespace DotRecast.Detour.Crowd
ag.targetReplanTime = 0;
}
else if (status != null && status.IsSuccess())
else if (status.IsSuccess())
{
List<long> path = ag.corridor.GetPath();
if (0 == path.Count)

View File

@ -26,14 +26,12 @@ namespace DotRecast.Detour.Crowd
{
/// Path find start and end location.
public RcVec3f startPos = new RcVec3f();
public RcVec3f endPos = new RcVec3f();
public long startRef;
public long endRef;
public IDtQueryFilter filter;
/// < TODO: This is potentially dangerous!
public readonly DtPathQueryResult result = new DtPathQueryResult();
public IDtQueryFilter filter; // < TODO: This is potentially dangerous!
public DtNavMeshQuery navQuery;
}

View File

@ -49,7 +49,7 @@ namespace DotRecast.Detour.Crowd
queue.RemoveFirst();
// Handle query start.
if (q.result.status == null)
if (q.result.status.IsEmpty())
{
q.navQuery = new DtNavMeshQuery(navMesh);
q.result.status = q.navQuery.InitSlicedFindPath(q.startRef, q.endRef, q.startPos, q.endPos, q.filter, 0);
@ -89,7 +89,6 @@ namespace DotRecast.Detour.Crowd
q.startRef = startRef;
q.endPos = endPos;
q.endRef = endRef;
q.result.status = null;
q.filter = filter;
queue.AddLast(q);
return q.result;

View File

@ -22,8 +22,10 @@ using System.Runtime.CompilerServices;
namespace DotRecast.Detour
{
public class DtStatus
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.
@ -40,7 +42,6 @@ namespace DotRecast.Detour
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
public readonly uint Value;
private DtStatus(uint value)
@ -48,6 +49,12 @@ namespace DotRecast.Detour
Value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsEmpty()
{
return 0 == Value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsSuccess()
{
@ -71,5 +78,17 @@ namespace DotRecast.Detour
{
return 0 != (Value & DT_PARTIAL_RESULT.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static DtStatus operator |(DtStatus left, DtStatus right)
{
return new DtStatus(left.Value | right.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static DtStatus operator &(DtStatus left, DtStatus right)
{
return new DtStatus(left.Value & right.Value);
}
}
}

View File

@ -34,7 +34,7 @@ namespace DotRecast.Detour.QueryResults
public static Result<T> InvalidParam<T>()
{
return new Result<T>(default, DtStatus.DT_INVALID_PARAM, null);
return new Result<T>(default, DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM, null);
}
public static Result<T> Failure<T>(string message)
@ -44,7 +44,7 @@ namespace DotRecast.Detour.QueryResults
public static Result<T> InvalidParam<T>(string message)
{
return new Result<T>(default, DtStatus.DT_INVALID_PARAM, message);
return new Result<T>(default, DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM, message);
}
public static Result<T> Failure<T>(T result)

View File

@ -160,7 +160,7 @@ public class FindPathTest : AbstractDetourTest
var endPos = endPoss[i];
query.InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE);
DtStatus status = DtStatus.DT_IN_PROGRESS;
while (status == DtStatus.DT_IN_PROGRESS)
while (status.IsInProgress())
{
Result<int> res = query.UpdateSlicedFindPath(10);
status = res.status;