forked from bit/DotRecastNetSim
remove FindRandomPointResult 2st
This commit is contained in:
parent
6271dc71d9
commit
e775e7ad83
|
@ -199,10 +199,14 @@ namespace DotRecast.Detour
|
||||||
* Function returning a random number [0..1).
|
* Function returning a random number [0..1).
|
||||||
* @return Random location
|
* @return Random location
|
||||||
*/
|
*/
|
||||||
public Result<FindRandomPointResult> FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
||||||
IDtQueryFilter filter, FRand frand)
|
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).
|
* Function returning a random number [0..1).
|
||||||
* @return Random location
|
* @return Random location
|
||||||
*/
|
*/
|
||||||
public Result<FindRandomPointResult> FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
||||||
IDtQueryFilter filter, FRand frand)
|
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,
|
public Result<FindRandomPointResult> FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
||||||
IDtQueryFilter filter, FRand frand, IPolygonByCircleConstraint constraint)
|
IDtQueryFilter filter, FRand frand,
|
||||||
|
IPolygonByCircleConstraint constraint)
|
||||||
{
|
{
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0
|
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0
|
||||||
|
|
|
@ -161,11 +161,11 @@ public class CrowdProfilingTool
|
||||||
if (0 < zones.Count)
|
if (0 < zones.Count)
|
||||||
{
|
{
|
||||||
int zone = (int)(rnd.Next() * zones.Count);
|
int zone = (int)(rnd.Next() * zones.Count);
|
||||||
Result<FindRandomPointResult> result = navquery.FindRandomPointWithinCircle(zones[zone].GetRandomRef(),
|
var status = navquery.FindRandomPointWithinCircle(zones[zone].GetRandomRef(), zones[zone].GetRandomPt(), zoneRadius, filter, rnd,
|
||||||
zones[zone].GetRandomPt(), zoneRadius, filter, rnd);
|
out var randomRef, out var randomPt);
|
||||||
if (result.Succeeded())
|
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);
|
Result<FindNearestPolyResult> nearestPoly = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter);
|
||||||
if (nearestPoly.Succeeded())
|
if (nearestPoly.Succeeded())
|
||||||
{
|
{
|
||||||
Result<FindRandomPointResult> result = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(),
|
var status = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(), crowAgentData.home, zoneRadius * 2f, filter, rnd,
|
||||||
crowAgentData.home, zoneRadius * 2f, filter, rnd);
|
out var randomRef, out var randomPt);
|
||||||
if (result.Succeeded())
|
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);
|
Result<FindNearestPolyResult> nearestPoly = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter);
|
||||||
if (nearestPoly.Succeeded())
|
if (nearestPoly.Succeeded())
|
||||||
{
|
{
|
||||||
Result<FindRandomPointResult> result = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(),
|
var status = navquery.FindRandomPointAroundCircle(nearestPoly.result.GetNearestRef(), crowAgentData.home, zoneRadius * 0.2f, filter, rnd,
|
||||||
crowAgentData.home, zoneRadius * 0.2f, filter, rnd);
|
out var randomRef, out var randomPt);
|
||||||
if (result.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
crowd.RequestMoveTarget(ag, result.result.GetRandomRef(), result.result.GetRandomPt());
|
crowd.RequestMoveTarget(ag, randomRef, randomPt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,12 +64,14 @@ public class RandomPointTest : AbstractDetourTest
|
||||||
query.FindRandomPoint(filter, f, out var randomRef, out var randomPt);
|
query.FindRandomPoint(filter, f, out var randomRef, out var randomPt);
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
Result<FindRandomPointResult> result = query.FindRandomPointAroundCircle(randomRef, randomPt, 5f, filter, f);
|
var status = query.FindRandomPointAroundCircle(randomRef, randomPt, 5f, filter, f, out var nextRandomRef, out var nextRandomPt);
|
||||||
Assert.That(result.Failed(), Is.False);
|
Assert.That(status.Failed(), Is.False);
|
||||||
|
|
||||||
|
randomRef = nextRandomRef;
|
||||||
|
randomPt = nextRandomPt;
|
||||||
|
|
||||||
randomRef = result.result.GetRandomRef();
|
|
||||||
randomPt = result.result.GetRandomPt();
|
|
||||||
Tuple<DtMeshTile, DtPoly> tileAndPoly = navmesh.GetTileAndPolyByRef(randomRef).result;
|
Tuple<DtMeshTile, DtPoly> tileAndPoly = navmesh.GetTileAndPolyByRef(randomRef).result;
|
||||||
|
|
||||||
float[] bmin = new float[2];
|
float[] bmin = new float[2];
|
||||||
float[] bmax = new float[2];
|
float[] bmax = new float[2];
|
||||||
for (int j = 0; j < tileAndPoly.Item2.vertCount; j++)
|
for (int j = 0; j < tileAndPoly.Item2.vertCount; j++)
|
||||||
|
@ -97,14 +99,14 @@ public class RandomPointTest : AbstractDetourTest
|
||||||
float radius = 5f;
|
float radius = 5f;
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
Result<FindRandomPointResult> result = query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f);
|
var status = query.FindRandomPointWithinCircle(randomRef, randomPt, radius, filter, f, out var nextRandomRef, out var nextRandomPt);
|
||||||
Assert.That(result.Failed(), Is.False);
|
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);
|
Assert.That(distance <= radius, Is.True);
|
||||||
|
|
||||||
randomRef = result.result.GetRandomRef();
|
randomRef = nextRandomRef;
|
||||||
randomPt = result.result.GetRandomPt();
|
randomPt = nextRandomPt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,24 +121,24 @@ public class RandomPointTest : AbstractDetourTest
|
||||||
// jvm warmup
|
// jvm warmup
|
||||||
for (int i = 0; i < 1000; i++)
|
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++)
|
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;
|
long t1 = RcFrequency.Ticks;
|
||||||
for (int i = 0; i < 10000; i++)
|
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;
|
long t2 = RcFrequency.Ticks;
|
||||||
for (int i = 0; i < 10000; i++)
|
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;
|
long t3 = RcFrequency.Ticks;
|
||||||
|
|
Loading…
Reference in New Issue