From a0877d3dc6269b90543e67c17ada9bca8ddc4902 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 10 Jun 2023 23:18:21 +0900 Subject: [PATCH] remove class FindRandomPointResult --- src/DotRecast.Detour/DtPolyPoint.cs | 16 ++++++ .../QueryResults/FindRandomPointResult.cs | 49 ------------------- .../Tools/CrowdProfilingTool.cs | 24 ++++----- 3 files changed, 28 insertions(+), 61 deletions(-) create mode 100644 src/DotRecast.Detour/DtPolyPoint.cs delete mode 100644 src/DotRecast.Detour/QueryResults/FindRandomPointResult.cs diff --git a/src/DotRecast.Detour/DtPolyPoint.cs b/src/DotRecast.Detour/DtPolyPoint.cs new file mode 100644 index 0000000..1704884 --- /dev/null +++ b/src/DotRecast.Detour/DtPolyPoint.cs @@ -0,0 +1,16 @@ +using DotRecast.Core; + +namespace DotRecast.Detour +{ + public readonly struct DtPolyPoint + { + public readonly long refs; + public readonly RcVec3f pt; + + public DtPolyPoint(long polyRefs, RcVec3f polyPt) + { + refs = polyRefs; + pt = polyPt; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Detour/QueryResults/FindRandomPointResult.cs b/src/DotRecast.Detour/QueryResults/FindRandomPointResult.cs deleted file mode 100644 index 3e401e2..0000000 --- a/src/DotRecast.Detour/QueryResults/FindRandomPointResult.cs +++ /dev/null @@ -1,49 +0,0 @@ -/* -Copyright (c) 2009-2010 Mikko Mononen memon@inside.org -recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org -DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -using DotRecast.Core; - -namespace DotRecast.Detour.QueryResults -{ - //TODO: (PP) Add comments - public class FindRandomPointResult - { - private readonly long randomRef; - private readonly RcVec3f randomPt; - - public FindRandomPointResult(long randomRef, RcVec3f randomPt) - { - this.randomRef = randomRef; - this.randomPt = randomPt; - } - - /// @param[out] randomRef The reference id of the random location. - public long GetRandomRef() - { - return randomRef; - } - - /// @param[out] randomPt The random location. - public RcVec3f GetRandomPt() - { - return randomPt; - } - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs index 4c53b0d..d86c038 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 DtNavMesh navMesh; private DtCrowdConfig config; private FRand rnd; - private readonly List zones = new(); + private readonly List _polyPoints = new(); private long crowdUpdateTime; public CrowdProfilingTool(Func agentParamsSupplier) @@ -158,10 +158,10 @@ public class CrowdProfilingTool private RcVec3f? GetVillagerPosition(DtNavMeshQuery navquery, IDtQueryFilter filter) { - if (0 < zones.Count) + if (0 < _polyPoints.Count) { - int zone = (int)(rnd.Next() * zones.Count); - var status = navquery.FindRandomPointWithinCircle(zones[zone].GetRandomRef(), zones[zone].GetRandomPt(), zoneRadius, filter, rnd, + int zone = (int)(rnd.Next() * _polyPoints.Count); + var status = navquery.FindRandomPointWithinCircle(_polyPoints[zone].refs, _polyPoints[zone].pt, zoneRadius, filter, rnd, out var randomRef, out var randomPt); if (status.Succeeded()) { @@ -174,7 +174,7 @@ public class CrowdProfilingTool private void CreateZones() { - zones.Clear(); + _polyPoints.Clear(); IDtQueryFilter filter = new DtQueryDefaultFilter(); DtNavMeshQuery navquery = new DtNavMeshQuery(navMesh); for (int i = 0; i < numberOfZones; i++) @@ -186,9 +186,9 @@ public class CrowdProfilingTool if (status.Succeeded()) { bool valid = true; - foreach (var zone in zones) + foreach (var zone in _polyPoints) { - if (RcVec3f.DistSqr(zone.GetRandomPt(), randomPt) < zoneSeparation) + if (RcVec3f.DistSqr(zone.pt, randomPt) < zoneSeparation) { valid = false; break; @@ -197,7 +197,7 @@ public class CrowdProfilingTool if (valid) { - zones.Add(new FindRandomPointResult(randomRef, randomPt)); + _polyPoints.Add(new DtPolyPoint(randomRef, randomPt)); break; } } @@ -309,10 +309,10 @@ public class CrowdProfilingTool private void MoveTraveller(DtNavMeshQuery navquery, IDtQueryFilter filter, DtCrowdAgent ag, CrowdAgentData crowAgentData) { // Move to another zone - List potentialTargets = new(); - foreach (FindRandomPointResult zone in zones) + List potentialTargets = new(); + foreach (var zone in _polyPoints) { - if (RcVec3f.DistSqr(zone.GetRandomPt(), ag.npos) > zoneRadius * zoneRadius) + if (RcVec3f.DistSqr(zone.pt, ag.npos) > zoneRadius * zoneRadius) { potentialTargets.Add(zone); } @@ -321,7 +321,7 @@ public class CrowdProfilingTool if (0 < potentialTargets.Count) { potentialTargets.Shuffle(); - crowd.RequestMoveTarget(ag, potentialTargets[0].GetRandomRef(), potentialTargets[0].GetRandomPt()); + crowd.RequestMoveTarget(ag, potentialTargets[0].refs, potentialTargets[0].pt); } }