remove FindRandomPointResult 2st

This commit is contained in:
ikpil 2023-06-10 22:20:56 +09:00
parent 6271dc71d9
commit e775e7ad83
3 changed files with 44 additions and 33 deletions

View File

@ -199,10 +199,14 @@ namespace DotRecast.Detour
* Function returning a random number [0..1).
* @return Random location
*/
public Result<FindRandomPointResult> FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
IDtQueryFilter filter, FRand frand)
public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt)
{
return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, NoOpPolygonByCircleConstraint.Noop);
var result = FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, NoOpPolygonByCircleConstraint.Noop);
randomRef = result.result.GetRandomRef();
randomPt = result.result.GetRandomPt();
return result.status;
}
/**
@ -220,14 +224,19 @@ namespace DotRecast.Detour
* Function returning a random number [0..1).
* @return Random location
*/
public Result<FindRandomPointResult> FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius,
IDtQueryFilter filter, FRand frand)
public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius,
IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt)
{
return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, StrictPolygonByCircleConstraint.Strict);
var result = FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, StrictPolygonByCircleConstraint.Strict);
randomRef = result.result.GetRandomRef();
randomPt = result.result.GetRandomPt();
return result.status;
}
public Result<FindRandomPointResult> FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
IDtQueryFilter filter, FRand frand, IPolygonByCircleConstraint constraint)
IDtQueryFilter filter, FRand frand,
IPolygonByCircleConstraint constraint)
{
// Validate input
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0

View File

@ -161,11 +161,11 @@ public class CrowdProfilingTool
if (0 < zones.Count)
{
int zone = (int)(rnd.Next() * zones.Count);
Result<FindRandomPointResult> result = navquery.FindRandomPointWithinCircle(zones[zone].GetRandomRef(),
zones[zone].GetRandomPt(), zoneRadius, filter, rnd);
if (result.Succeeded())
var status = navquery.FindRandomPointWithinCircle(zones[zone].GetRandomRef(), zones[zone].GetRandomPt(), zoneRadius, filter, rnd,
out var randomRef, out var randomPt);
if (status.Succeeded())
{
return result.result.GetRandomPt();
return randomPt;
}
}
@ -282,11 +282,11 @@ public class CrowdProfilingTool
Result<FindNearestPolyResult> nearestPoly = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter);
if (nearestPoly.Succeeded())
{
Result<FindRandomPointResult> result = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(),
crowAgentData.home, zoneRadius * 2f, filter, rnd);
if (result.Succeeded())
var status = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(), crowAgentData.home, zoneRadius * 2f, filter, rnd,
out var randomRef, out var randomPt);
if (status.Succeeded())
{
crowd.RequestMoveTarget(ag, result.result.GetRandomRef(), result.result.GetRandomPt());
crowd.RequestMoveTarget(ag, randomRef, randomPt);
}
}
}
@ -297,11 +297,11 @@ public class CrowdProfilingTool
Result<FindNearestPolyResult> nearestPoly = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter);
if (nearestPoly.Succeeded())
{
Result<FindRandomPointResult> result = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(),
crowAgentData.home, zoneRadius * 0.2f, filter, rnd);
if (result.Succeeded())
var status = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(), crowAgentData.home, zoneRadius * 0.2f, filter, rnd,
out var randomRef, out var randomPt);
if (status.Succeeded())
{
crowd.RequestMoveTarget(ag, result.result.GetRandomRef(), result.result.GetRandomPt());
crowd.RequestMoveTarget(ag, randomRef, randomPt);
}
}
}

View File

@ -64,12 +64,14 @@ public class RandomPointTest : AbstractDetourTest
query.FindRandomPoint(filter, f, out var randomRef, out var randomPt);
for (int i = 0; i < 1000; i++)
{
Result<FindRandomPointResult> result = query.FindRandomPointAroundCircle(randomRef, randomPt, 5f, filter, f);
Assert.That(result.Failed(), Is.False);
var status = query.FindRandomPointAroundCircle(randomRef, randomPt, 5f, filter, f, out var nextRandomRef, out var nextRandomPt);
Assert.That(status.Failed(), Is.False);
randomRef = result.result.GetRandomRef();
randomPt = result.result.GetRandomPt();
randomRef = nextRandomRef;
randomPt = nextRandomPt;
Tuple<DtMeshTile, DtPoly> tileAndPoly = navmesh.GetTileAndPolyByRef(randomRef).result;
float[] bmin = new float[2];
float[] bmax = new float[2];
for (int j = 0; j < tileAndPoly.Item2.vertCount; j++)
@ -97,14 +99,14 @@ public class RandomPointTest : AbstractDetourTest
float radius = 5f;
for (int i = 0; i < 1000; i++)
{
Result<FindRandomPointResult> result = query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f);
Assert.That(result.Failed(), Is.False);
var status = query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f, out var nextRandomRef, out var nextRandomPt);
Assert.That(status.Failed(), Is.False);
float distance = RcVec3f.Dist2D(randomPt, result.result.GetRandomPt());
float distance = RcVec3f.Dist2D(randomPt, nextRandomPt);
Assert.That(distance <= radius, Is.True);
randomRef = result.result.GetRandomRef();
randomPt = result.result.GetRandomPt();
randomRef = nextRandomRef;
randomPt = nextRandomPt;
}
}
@ -114,29 +116,29 @@ public class RandomPointTest : AbstractDetourTest
FRand f = new FRand(1);
IDtQueryFilter filter = new DtQueryDefaultFilter();
query.FindRandomPoint(filter, f, out var randomRef, out var randomPt);
float radius = 5f;
// jvm warmup
for (int i = 0; i < 1000; i++)
{
query.FindRandomPointAroundCircle(randomRef, randomPt, radius, filter, f);
query.FindRandomPointAroundCircle(randomRef, randomPt, radius, filter, f, out var _, out var _);
}
for (int i = 0; i < 1000; i++)
{
query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f);
query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f, out var _, out var _);
}
long t1 = RcFrequency.Ticks;
for (int i = 0; i < 10000; i++)
{
query.FindRandomPointAroundCircle(randomRef, randomPt, radius, filter, f);
query.FindRandomPointAroundCircle(randomRef, randomPt, radius, filter, f, out var _, out var _);
}
long t2 = RcFrequency.Ticks;
for (int i = 0; i < 10000; i++)
{
query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f);
query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f, out var _, out var _);
}
long t3 = RcFrequency.Ticks;