forked from bit/DotRecastNetSim
test
This commit is contained in:
parent
eb1aa49363
commit
a0800de245
|
@ -20,6 +20,7 @@ freely, subject to the following restrictions:
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Core.Numerics;
|
||||
|
||||
|
@ -316,7 +317,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_path = DtPathUtils.MergeCorridorStartMoved(m_path, m_path.Count, m_maxPath, visited);
|
||||
DtPathUtils.MergeCorridorStartMoved(m_path, m_path.Count, m_maxPath, visited);
|
||||
|
||||
// Adjust the position to stay on top of the navmesh.
|
||||
m_pos = result;
|
||||
|
|
|
@ -20,6 +20,7 @@ freely, subject to the following restrictions:
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotRecast.Core.Numerics;
|
||||
|
||||
namespace DotRecast.Detour
|
||||
|
@ -141,13 +142,13 @@ namespace DotRecast.Detour
|
|||
return path;
|
||||
}
|
||||
|
||||
public static List<long> MergeCorridorStartMoved(List<long> path, int npath, int maxPath, List<long> visited)
|
||||
public static int MergeCorridorStartMoved(List<long> path, int npath, int maxPath, List<long> visited)
|
||||
{
|
||||
int furthestPath = -1;
|
||||
int furthestVisited = -1;
|
||||
|
||||
// Find furthest common polygon.
|
||||
for (int i = path.Count - 1; i >= 0; --i)
|
||||
for (int i = npath - 1; i >= 0; --i)
|
||||
{
|
||||
bool found = false;
|
||||
for (int j = visited.Count - 1; j >= 0; --j)
|
||||
|
@ -169,22 +170,37 @@ namespace DotRecast.Detour
|
|||
// If no intersection found just return current path.
|
||||
if (furthestPath == -1 || furthestVisited == -1)
|
||||
{
|
||||
return path;
|
||||
return npath;
|
||||
}
|
||||
|
||||
// Concatenate paths.
|
||||
|
||||
// Adjust beginning of the buffer to include the visited.
|
||||
List<long> result = new List<long>();
|
||||
int req = visited.Count - furthestVisited;
|
||||
int orig = Math.Min(furthestPath + 1, npath);
|
||||
int size = Math.Max(0, npath - orig);
|
||||
if (req + size > maxPath)
|
||||
size = maxPath - req;
|
||||
|
||||
// Store visited
|
||||
for (int i = visited.Count - 1; i > furthestVisited; --i)
|
||||
if (size > 0)
|
||||
{
|
||||
result.Add(visited[i]);
|
||||
//memmove(path + req, path + orig, size * sizeof(dtPolyRef));
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
if (path.Count <= req + i)
|
||||
path.Add(0);
|
||||
|
||||
path[req + i] = path[orig + i];
|
||||
}
|
||||
}
|
||||
|
||||
result.AddRange(path.GetRange(furthestPath, path.Count - furthestPath));
|
||||
return result;
|
||||
// Store visited
|
||||
for (int i = 0, n = Math.Min(req, maxPath); i < n; ++i)
|
||||
{
|
||||
path[i] = visited[(visited.Count - 1) - i];
|
||||
}
|
||||
|
||||
return req + size;
|
||||
}
|
||||
|
||||
public static List<long> MergeCorridorEndMoved(List<long> path, int npath, int maxPath, List<long> visited)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Core.Numerics;
|
||||
using DotRecast.Detour;
|
||||
|
@ -92,7 +93,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
|
||||
iterPos = result;
|
||||
|
||||
pathIterPolys = DtPathUtils.MergeCorridorStartMoved(pathIterPolys, pathIterPolys.Count, MAX_POLYS, visited);
|
||||
DtPathUtils.MergeCorridorStartMoved(pathIterPolys, pathIterPolys.Count, MAX_POLYS, visited);
|
||||
pathIterPolys = DtPathUtils.FixupShortcuts(pathIterPolys, navQuery);
|
||||
|
||||
var status = navQuery.GetPolyHeight(pathIterPolys[0], result, out var h);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class DtPathCorridorTest
|
|||
const int maxPath = 0;
|
||||
var visited = new List<long>();
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(0));
|
||||
Assert.That(result, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test(Description = "dtMergeCorridorStartMoved")]
|
||||
|
@ -60,7 +60,7 @@ public class DtPathCorridorTest
|
|||
var visited = new List<long>();
|
||||
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(1));
|
||||
Assert.That(result, Is.EqualTo(1));
|
||||
|
||||
var expectedPath = new List<long> { 1 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
@ -76,7 +76,7 @@ public class DtPathCorridorTest
|
|||
var visited = new List<long> { 1 };
|
||||
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(0));
|
||||
Assert.That(result, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test(Description = "dtMergeCorridorStartMoved")]
|
||||
|
@ -89,7 +89,7 @@ public class DtPathCorridorTest
|
|||
var visited = new List<long> { 1, 2 };
|
||||
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(1));
|
||||
Assert.That(result, Is.EqualTo(1));
|
||||
|
||||
var expectedPath = new List<long> { 2, 2 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
@ -103,7 +103,7 @@ public class DtPathCorridorTest
|
|||
const int maxPath = 3;
|
||||
var visited = new List<long> { 1, 2, 3, 4 };
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
Assert.That(result, Is.EqualTo(3));
|
||||
|
||||
var expectedPath = new List<long> { 4, 3, 2 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
@ -117,7 +117,7 @@ public class DtPathCorridorTest
|
|||
const int maxPath = 3;
|
||||
var visited = new List<long>() { 1, 2, 3, 4, 5 };
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
Assert.That(result, Is.EqualTo(3));
|
||||
|
||||
var expectedPath = new List<long> { 5, 4, 3 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
@ -131,7 +131,7 @@ public class DtPathCorridorTest
|
|||
const int maxPath = 2;
|
||||
var visited = new List<long>() { 3, 4 };
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(2));
|
||||
Assert.That(result, Is.EqualTo(2));
|
||||
|
||||
var expectedPath = new List<long> { 1, 2 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
@ -145,7 +145,7 @@ public class DtPathCorridorTest
|
|||
const int maxPath = 3;
|
||||
var visited = new List<long>() { 1, 3 };
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(3));
|
||||
Assert.That(result, Is.EqualTo(3));
|
||||
|
||||
var expectedPath = new List<long> { 3, 1, 2 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
@ -159,7 +159,7 @@ public class DtPathCorridorTest
|
|||
const int maxPath = 2;
|
||||
var visited = new List<long>() { 1, 3 };
|
||||
var result = DtPathUtils.MergeCorridorStartMoved(path, npath, maxPath, visited);
|
||||
Assert.That(result.Count, Is.EqualTo(2));
|
||||
Assert.That(result, Is.EqualTo(2));
|
||||
|
||||
var expectedPath = new List<long> { 3, 1 };
|
||||
Assert.That(path, Is.EqualTo(expectedPath));
|
||||
|
|
Loading…
Reference in New Issue