From 89eb8554d97433fe7186176f990bfff9f49f55bf Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 27 Apr 2023 22:36:05 +0900 Subject: [PATCH] move frand --- src/DotRecast.Core/FRand.cs | 24 +++++++++++++++++++ src/DotRecast.Detour/NavMeshQuery.cs | 20 ---------------- .../Tools/CrowdProfilingTool.cs | 4 ++-- .../Tools/TestNavmeshTool.cs | 2 +- test/DotRecast.Detour.Test/RandomPointTest.cs | 8 +++---- 5 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 src/DotRecast.Core/FRand.cs diff --git a/src/DotRecast.Core/FRand.cs b/src/DotRecast.Core/FRand.cs new file mode 100644 index 0000000..a75f4ee --- /dev/null +++ b/src/DotRecast.Core/FRand.cs @@ -0,0 +1,24 @@ +using System; + +namespace DotRecast.Core +{ + public class FRand + { + private readonly Random r; + + public FRand() + { + r = new Random(); + } + + public FRand(long seed) + { + r = new Random((int)seed); // TODO : 랜덤 시드 확인 필요 + } + + public float frand() + { + return (float)r.NextDouble(); + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Detour/NavMeshQuery.cs b/src/DotRecast.Detour/NavMeshQuery.cs index 1aae52e..518aeb3 100644 --- a/src/DotRecast.Detour/NavMeshQuery.cs +++ b/src/DotRecast.Detour/NavMeshQuery.cs @@ -73,26 +73,6 @@ namespace DotRecast.Detour m_openList = new NodeQueue(); } - public class FRand - { - private readonly Random r; - - public FRand() - { - r = new Random(); - } - - public FRand(long seed) - { - r = new Random((int)seed); // TODO : 랜덤 시드 확인 필요 - } - - public float frand() - { - return (float)r.NextDouble(); - } - } - /** * Returns random location on navmesh. Polygons are chosen weighted by area. The search runs in linear related to * number of polygon. diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs index 45b3016..33694d6 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs @@ -48,7 +48,7 @@ public class CrowdProfilingTool private Crowd crowd; private NavMesh navMesh; private CrowdConfig config; - private NavMeshQuery.FRand rnd; + private FRand rnd; private readonly List zones = new(); private long crowdUpdateTime; @@ -79,7 +79,7 @@ public class CrowdProfilingTool { if (navMesh != null) { - rnd = new NavMeshQuery.FRand(randomSeed); + rnd = new FRand(randomSeed); createCrowd(); createZones(); NavMeshQuery navquery = new NavMeshQuery(navMesh); diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index f18cb2f..0587bb0 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -495,7 +495,7 @@ public class TestNavmeshTool : Tool for (int i = 0; i < 200; i++) { Result result = m_navQuery.findRandomPointAroundCircle(m_startRef, m_spos, dist, - m_filter, new NavMeshQuery.FRand(), constraint); + m_filter, new FRand(), constraint); if (result.succeeded()) { randomPoints.Add(result.result.getRandomPt()); diff --git a/test/DotRecast.Detour.Test/RandomPointTest.cs b/test/DotRecast.Detour.Test/RandomPointTest.cs index a09cb24..e7aa59e 100644 --- a/test/DotRecast.Detour.Test/RandomPointTest.cs +++ b/test/DotRecast.Detour.Test/RandomPointTest.cs @@ -31,7 +31,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void testRandom() { - NavMeshQuery.FRand f = new NavMeshQuery.FRand(1); + FRand f = new FRand(1); QueryFilter filter = new DefaultQueryFilter(); for (int i = 0; i < 1000; i++) { @@ -59,7 +59,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void testRandomAroundCircle() { - NavMeshQuery.FRand f = new NavMeshQuery.FRand(1); + FRand f = new FRand(1); QueryFilter filter = new DefaultQueryFilter(); FindRandomPointResult point = query.findRandomPoint(filter, f).result; for (int i = 0; i < 1000; i++) @@ -90,7 +90,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void testRandomWithinCircle() { - NavMeshQuery.FRand f = new NavMeshQuery.FRand(1); + FRand f = new FRand(1); QueryFilter filter = new DefaultQueryFilter(); FindRandomPointResult point = query.findRandomPoint(filter, f).result; float radius = 5f; @@ -108,7 +108,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void testPerformance() { - NavMeshQuery.FRand f = new NavMeshQuery.FRand(1); + FRand f = new FRand(1); QueryFilter filter = new DefaultQueryFilter(); FindRandomPointResult point = query.findRandomPoint(filter, f).result; float radius = 5f;