From 59849e1dacb6c40746bf2d8fe81a79bc9527704f Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 9 May 2024 00:00:53 +0900 Subject: [PATCH] add `int nvisited` in DtPathUtils.functions --- src/DotRecast.Detour.Crowd/DtPathCorridor.cs | 8 ++++---- src/DotRecast.Detour/DtPathUtils.cs | 17 ++++++++--------- .../Tools/RcTestNavMeshTool.cs | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 67f9d27..f2e9700 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -218,7 +218,7 @@ namespace DotRecast.Detour.Crowd { if (res.Count > 1 && t > 0.99f) { - m_npath = DtPathUtils.MergeCorridorStartShortcut(ref m_path, m_npath, m_maxPath, res); + m_npath = DtPathUtils.MergeCorridorStartShortcut(ref m_path, m_npath, m_maxPath, res, res.Count); } } } @@ -250,7 +250,7 @@ namespace DotRecast.Detour.Crowd if (status.Succeeded() && res.Count > 0) { - m_npath = DtPathUtils.MergeCorridorStartShortcut(ref m_path, m_npath, m_maxPath, res); + m_npath = DtPathUtils.MergeCorridorStartShortcut(ref m_path, m_npath, m_maxPath, res, res.Count); return true; } @@ -321,7 +321,7 @@ namespace DotRecast.Detour.Crowd var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, ref visited); if (status.Succeeded()) { - m_npath = DtPathUtils.MergeCorridorStartMoved(ref m_path, m_npath, m_maxPath, visited); + m_npath = DtPathUtils.MergeCorridorStartMoved(ref m_path, m_npath, m_maxPath, visited, visited.Count); // Adjust the position to stay on top of the navmesh. m_pos = result; @@ -363,7 +363,7 @@ namespace DotRecast.Detour.Crowd var status = navquery.MoveAlongSurface(m_path[^1], m_target, npos, filter, out var result, ref visited); if (status.Succeeded()) { - m_npath = DtPathUtils.MergeCorridorEndMoved(ref m_path, m_npath, m_maxPath, visited); + m_npath = DtPathUtils.MergeCorridorEndMoved(ref m_path, m_npath, m_maxPath, visited, visited.Count); // TODO: should we do that? // Adjust the position to stay on top of the navmesh. diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index 72d7043..9fb31a2 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -20,7 +20,6 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; -using System.Linq; using DotRecast.Core.Numerics; namespace DotRecast.Detour @@ -147,7 +146,7 @@ namespace DotRecast.Detour return npath; } - public static int MergeCorridorStartMoved(ref List path, int npath, int maxPath, List visited) + public static int MergeCorridorStartMoved(ref List path, int npath, int maxPath, List visited, int nvisited) { int furthestPath = -1; int furthestVisited = -1; @@ -156,7 +155,7 @@ namespace DotRecast.Detour for (int i = npath - 1; i >= 0; --i) { bool found = false; - for (int j = visited.Count - 1; j >= 0; --j) + for (int j = nvisited - 1; j >= 0; --j) { if (path[i] == visited[j]) { @@ -183,7 +182,7 @@ namespace DotRecast.Detour // Adjust beginning of the buffer to include the visited. List result = new List(); // Store visited - for (int i = visited.Count - 1; i > furthestVisited; --i) + for (int i = nvisited - 1; i > furthestVisited; --i) { result.Add(visited[i]); } @@ -194,7 +193,7 @@ namespace DotRecast.Detour return result.Count; } - public static int MergeCorridorEndMoved(ref List path, int npath, int maxPath, List visited) + public static int MergeCorridorEndMoved(ref List path, int npath, int maxPath, List visited, int nvisited) { int furthestPath = -1; int furthestVisited = -1; @@ -203,7 +202,7 @@ namespace DotRecast.Detour for (int i = 0; i < npath; ++i) { bool found = false; - for (int j = visited.Count - 1; j >= 0; --j) + for (int j = nvisited - 1; j >= 0; --j) { if (path[i] == visited[j]) { @@ -227,13 +226,13 @@ namespace DotRecast.Detour // Concatenate paths. List result = path.GetRange(0, furthestPath); - result.AddRange(visited.GetRange(furthestVisited, visited.Count - furthestVisited)); + result.AddRange(visited.GetRange(furthestVisited, nvisited - furthestVisited)); path = result; return result.Count; } - public static int MergeCorridorStartShortcut(ref List path, int npath, int maxPath, List visited) + public static int MergeCorridorStartShortcut(ref List path, int npath, int maxPath, List visited, int nvisited) { int furthestPath = -1; int furthestVisited = -1; @@ -242,7 +241,7 @@ namespace DotRecast.Detour for (int i = npath - 1; i >= 0; --i) { bool found = false; - for (int j = visited.Count - 1; j >= 0; --j) + for (int j = nvisited - 1; j >= 0; --j) { if (path[i] == visited[j]) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 197d6a5..0b226fe 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -97,7 +97,7 @@ namespace DotRecast.Recast.Toolset.Tools iterPos = result; - pathIterPolyCount = DtPathUtils.MergeCorridorStartMoved(ref pathIterPolys, pathIterPolyCount, MAX_POLYS, visited); + pathIterPolyCount = DtPathUtils.MergeCorridorStartMoved(ref pathIterPolys, pathIterPolyCount, MAX_POLYS, visited, visited.Count); pathIterPolyCount = DtPathUtils.FixupShortcuts(ref pathIterPolys, pathIterPolyCount, navQuery); var status = navQuery.GetPolyHeight(pathIterPolys[0], result, out var h);