forked from mirror/DotRecast
Compare commits
No commits in common. "418a39a576737373fbf463c1c2146ec8012404ee" and "fba594724cf7ed84eff672c5b82b4c4a1027eb5b" have entirely different histories.
418a39a576
...
fba594724c
|
@ -43,11 +43,6 @@ namespace DotRecast.Core.Buffers
|
||||||
return _array;
|
return _array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span<T> AsSpan()
|
|
||||||
{
|
|
||||||
return new Span<T>(_array, 0, Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,11 +45,5 @@ namespace DotRecast.Core.Collections
|
||||||
(list[k], list[n]) = (list[n], list[k]);
|
(list[k], list[n]) = (list[n], list[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this IList<T> list, Span<T> span)
|
|
||||||
{
|
|
||||||
foreach (var i in span)
|
|
||||||
list.Add(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,7 +33,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
private RcVec3f m_pos;
|
private RcVec3f m_pos;
|
||||||
private RcVec3f m_target;
|
private RcVec3f m_target;
|
||||||
|
|
||||||
private List<long> m_path = new List<long>();
|
private List<long> m_path;
|
||||||
private int m_npath;
|
private int m_npath;
|
||||||
private int m_maxPath;
|
private int m_maxPath;
|
||||||
|
|
||||||
|
@ -89,8 +89,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
/// @return True if the initialization succeeded.
|
/// @return True if the initialization succeeded.
|
||||||
public bool Init(int maxPath)
|
public bool Init(int maxPath)
|
||||||
{
|
{
|
||||||
if (m_path.Capacity < maxPath)
|
m_path = new List<long>(maxPath);
|
||||||
m_path.Capacity = maxPath;
|
|
||||||
m_npath = 0;
|
m_npath = 0;
|
||||||
m_maxPath = maxPath;
|
m_maxPath = maxPath;
|
||||||
return true;
|
return true;
|
||||||
|
@ -219,7 +218,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
if (res.Count > 1 && t > 0.99f)
|
if (res.Count > 1 && t > 0.99f)
|
||||||
{
|
{
|
||||||
m_npath = DtPathUtils.MergeCorridorStartShortcut(m_path, m_npath, m_maxPath, res, res.Count);
|
m_npath = DtPathUtils.MergeCorridorStartShortcut(ref m_path, m_npath, m_maxPath, res, res.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +250,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
|
|
||||||
if (status.Succeeded() && res.Count > 0)
|
if (status.Succeeded() && res.Count > 0)
|
||||||
{
|
{
|
||||||
m_npath = DtPathUtils.MergeCorridorStartShortcut(m_path, m_npath, m_maxPath, res, res.Count);
|
m_npath = DtPathUtils.MergeCorridorStartShortcut(ref m_path, m_npath, m_maxPath, res, res.Count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +276,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune path
|
// Prune path
|
||||||
m_path.RemoveRange(0, npos);
|
m_path = m_path.GetRange(npos, m_npath - npos);
|
||||||
m_npath -= npos;
|
m_npath -= npos;
|
||||||
|
|
||||||
refs[0] = prevRef;
|
refs[0] = prevRef;
|
||||||
|
@ -323,7 +322,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, visited, out var nvisited, MAX_VISITED);
|
var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, visited, out var nvisited, MAX_VISITED);
|
||||||
if (status.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
m_npath = DtPathUtils.MergeCorridorStartMoved(m_path, m_npath, m_maxPath, visited, nvisited);
|
m_npath = DtPathUtils.MergeCorridorStartMoved(ref m_path, m_npath, m_maxPath, visited, nvisited);
|
||||||
|
|
||||||
// Adjust the position to stay on top of the navmesh.
|
// Adjust the position to stay on top of the navmesh.
|
||||||
m_pos = result;
|
m_pos = result;
|
||||||
|
@ -367,7 +366,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
var status = navquery.MoveAlongSurface(m_path[^1], m_target, npos, filter, out var result, visited, out nvisited, MAX_VISITED);
|
var status = navquery.MoveAlongSurface(m_path[^1], m_target, npos, filter, out var result, visited, out nvisited, MAX_VISITED);
|
||||||
if (status.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
m_npath = DtPathUtils.MergeCorridorEndMoved(m_path, m_npath, m_maxPath, visited, nvisited);
|
m_npath = DtPathUtils.MergeCorridorEndMoved(ref m_path, m_npath, m_maxPath, visited, nvisited);
|
||||||
|
|
||||||
// TODO: should we do that?
|
// TODO: should we do that?
|
||||||
// Adjust the position to stay on top of the navmesh.
|
// Adjust the position to stay on top of the navmesh.
|
||||||
|
@ -395,11 +394,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
public void SetCorridor(RcVec3f target, List<long> path)
|
public void SetCorridor(RcVec3f target, List<long> path)
|
||||||
{
|
{
|
||||||
m_target = target;
|
m_target = target;
|
||||||
if(path != m_path)
|
m_path = new List<long>(path);
|
||||||
{
|
|
||||||
m_path.Clear();
|
|
||||||
m_path.AddRange(path);
|
|
||||||
}
|
|
||||||
m_npath = path.Count;
|
m_npath = path.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +444,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
else if (n < m_npath)
|
else if (n < m_npath)
|
||||||
{
|
{
|
||||||
// The path is partially usable.
|
// The path is partially usable.
|
||||||
m_path.RemoveRange(n, m_path.Count - n);
|
m_path = m_path.GetRange(0, n);
|
||||||
m_npath = n;
|
m_npath = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,7 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
using DotRecast.Core.Collections;
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
using CollectionExtensions = DotRecast.Core.Collections.CollectionExtensions;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
|
@ -151,7 +148,7 @@ namespace DotRecast.Detour
|
||||||
return npath;
|
return npath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MergeCorridorStartMoved(List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
public static int MergeCorridorStartMoved(ref List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
||||||
{
|
{
|
||||||
int furthestPath = -1;
|
int furthestPath = -1;
|
||||||
int furthestVisited = -1;
|
int furthestVisited = -1;
|
||||||
|
@ -183,23 +180,22 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concatenate paths.
|
// Concatenate paths.
|
||||||
var endIndex = nvisited - 1;
|
|
||||||
var length1 = endIndex - furthestVisited;
|
|
||||||
var length2 = npath - furthestPath;
|
|
||||||
using var result = RcRentedArray.Rent<long>(length1 + length2);
|
|
||||||
// Adjust beginning of the buffer to include the visited.
|
// Adjust beginning of the buffer to include the visited.
|
||||||
|
List<long> result = new List<long>();
|
||||||
// Store visited
|
// Store visited
|
||||||
for (int i = 0; i < length1; ++i)
|
for (int i = nvisited - 1; i > furthestVisited; --i)
|
||||||
result[i] = visited[endIndex - i];
|
{
|
||||||
|
result.Add(visited[i]);
|
||||||
path.CopyTo(furthestPath, result.AsArray(), length1, length2);
|
|
||||||
|
|
||||||
path.Clear();
|
|
||||||
CollectionExtensions.AddRange(path, result.AsSpan());
|
|
||||||
return result.Length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MergeCorridorEndMoved(List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
result.AddRange(path.GetRange(furthestPath, npath - furthestPath));
|
||||||
|
|
||||||
|
path = result;
|
||||||
|
return result.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int MergeCorridorEndMoved(ref List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
||||||
{
|
{
|
||||||
int furthestPath = -1;
|
int furthestPath = -1;
|
||||||
int furthestVisited = -1;
|
int furthestVisited = -1;
|
||||||
|
@ -231,18 +227,17 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concatenate paths.
|
// Concatenate paths.
|
||||||
var length1 = furthestPath;
|
List<long> result = path.GetRange(0, furthestPath);
|
||||||
var length2 = nvisited - furthestVisited;
|
foreach (var v in visited.Slice(furthestVisited, nvisited - furthestVisited))
|
||||||
using var result = RcRentedArray.Rent<long>(length1 + length2);
|
{
|
||||||
path.CopyTo(0, result.AsArray(), 0, length1);
|
result.Add(v);
|
||||||
visited.Slice(furthestVisited, nvisited - furthestVisited).CopyTo(result.AsSpan().Slice(length1, length2));
|
|
||||||
|
|
||||||
path.Clear();
|
|
||||||
CollectionExtensions.AddRange(path, result.AsSpan());
|
|
||||||
return path.Count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MergeCorridorStartShortcut(List<long> path, int npath, int maxPath, List<long> visited, int nvisited)
|
path = result;
|
||||||
|
return result.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int MergeCorridorStartShortcut(ref List<long> path, int npath, int maxPath, List<long> visited, int nvisited)
|
||||||
{
|
{
|
||||||
int furthestPath = -1;
|
int furthestPath = -1;
|
||||||
int furthestVisited = -1;
|
int furthestVisited = -1;
|
||||||
|
@ -276,15 +271,11 @@ namespace DotRecast.Detour
|
||||||
// Concatenate paths.
|
// Concatenate paths.
|
||||||
|
|
||||||
// Adjust beginning of the buffer to include the visited.
|
// Adjust beginning of the buffer to include the visited.
|
||||||
var length1 = furthestVisited;
|
List<long> result = visited.GetRange(0, furthestVisited);
|
||||||
var length2 = npath - furthestPath;
|
result.AddRange(path.GetRange(furthestPath, npath - furthestPath));
|
||||||
using var result = RcRentedArray.Rent<long>(length1 + length2);
|
|
||||||
visited.CopyTo(0, result.AsArray(), 0, length1);
|
|
||||||
path.CopyTo(furthestPath, result.AsArray(), length1, length2);
|
|
||||||
|
|
||||||
path.Clear();
|
path = result;
|
||||||
CollectionExtensions.AddRange(path, result.AsSpan());
|
return result.Count;
|
||||||
return path.Count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -98,7 +98,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
|
|
||||||
iterPos = result;
|
iterPos = result;
|
||||||
|
|
||||||
pathIterPolyCount = DtPathUtils.MergeCorridorStartMoved(pathIterPolys, pathIterPolyCount, MAX_POLYS, visited, nvisited);
|
pathIterPolyCount = DtPathUtils.MergeCorridorStartMoved(ref pathIterPolys, pathIterPolyCount, MAX_POLYS, visited, nvisited);
|
||||||
pathIterPolyCount = DtPathUtils.FixupShortcuts(ref pathIterPolys, pathIterPolyCount, navQuery);
|
pathIterPolyCount = DtPathUtils.FixupShortcuts(ref pathIterPolys, pathIterPolyCount, navQuery);
|
||||||
|
|
||||||
var status = navQuery.GetPolyHeight(pathIterPolys[0], result, out var h);
|
var status = navQuery.GetPolyHeight(pathIterPolys[0], result, out var h);
|
||||||
|
|
Loading…
Reference in New Issue