add `int nvisited` in DtPathUtils.functions

This commit is contained in:
ikpil 2024-05-09 00:00:53 +09:00
parent deb02778cc
commit 59849e1dac
3 changed files with 13 additions and 14 deletions

View File

@ -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.

View File

@ -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<long> path, int npath, int maxPath, List<long> visited)
public static int MergeCorridorStartMoved(ref List<long> path, int npath, int maxPath, List<long> 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<long> result = new List<long>();
// 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<long> path, int npath, int maxPath, List<long> visited)
public static int MergeCorridorEndMoved(ref List<long> path, int npath, int maxPath, List<long> 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<long> 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<long> path, int npath, int maxPath, List<long> visited)
public static int MergeCorridorStartShortcut(ref List<long> path, int npath, int maxPath, List<long> 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])
{

View File

@ -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);