forked from bit/DotRecastNetSim
Compare commits
No commits in common. "pr/fix-small-object-heap-issue" and "main" have entirely different histories.
pr/fix-sma
...
main
|
@ -22,7 +22,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
using DotRecast.Core.Collections;
|
using DotRecast.Core.Collections;
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
|
|
||||||
|
@ -403,7 +402,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
debug.Reset();
|
debug.Reset();
|
||||||
|
|
||||||
// Build sampling pattern aligned to desired velocity.
|
// Build sampling pattern aligned to desired velocity.
|
||||||
using var pat = RcRentedArray.Rent<float>((DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2);
|
float[] pat = new float[(DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2];
|
||||||
int npat = 0;
|
int npat = 0;
|
||||||
|
|
||||||
int ndivs = m_params.adaptiveDivs;
|
int ndivs = m_params.adaptiveDivs;
|
||||||
|
|
|
@ -21,7 +21,6 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
|
@ -1247,14 +1246,14 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
int ip = poly.index;
|
int ip = poly.index;
|
||||||
|
|
||||||
using var verts = RcRentedArray.Rent<float>(m_maxVertPerPoly * 3);
|
float[] verts = new float[m_maxVertPerPoly * 3];
|
||||||
int nv = poly.vertCount;
|
int nv = poly.vertCount;
|
||||||
for (int i = 0; i < nv; ++i)
|
for (int i = 0; i < nv; ++i)
|
||||||
{
|
{
|
||||||
RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts.AsArray(), i * 3, 3);
|
RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DtUtils.PointInPolygon(pos, verts.AsArray(), nv))
|
if (!DtUtils.PointInPolygon(pos, verts, nv))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
using DotRecast.Core.Collections;
|
using DotRecast.Core.Collections;
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
|
@ -42,9 +41,9 @@ namespace DotRecast.Detour
|
||||||
public DtNavMeshQuery(DtNavMesh nav)
|
public DtNavMeshQuery(DtNavMesh nav)
|
||||||
{
|
{
|
||||||
m_nav = nav;
|
m_nav = nav;
|
||||||
|
m_tinyNodePool = new DtNodePool();
|
||||||
m_nodePool = new DtNodePool();
|
m_nodePool = new DtNodePool();
|
||||||
m_openList = new DtNodeQueue();
|
m_openList = new DtNodeQueue();
|
||||||
m_tinyNodePool = new DtNodePool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns random location on navmesh.
|
/// Returns random location on navmesh.
|
||||||
|
@ -138,18 +137,18 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
// Randomly pick point on polygon.
|
// Randomly pick point on polygon.
|
||||||
using var verts = RcRentedArray.Rent<float>(3 * m_nav.GetMaxVertsPerPoly());
|
float[] verts = new float[3 * m_nav.GetMaxVertsPerPoly()];
|
||||||
using var areas = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly());
|
float[] areas = new float[m_nav.GetMaxVertsPerPoly()];
|
||||||
RcArrays.Copy(tile.data.verts, poly.verts[0] * 3, verts.AsArray(), 0, 3);
|
RcArrays.Copy(tile.data.verts, poly.verts[0] * 3, verts, 0, 3);
|
||||||
for (int j = 1; j < poly.vertCount; ++j)
|
for (int j = 1; j < poly.vertCount; ++j)
|
||||||
{
|
{
|
||||||
RcArrays.Copy(tile.data.verts, poly.verts[j] * 3, verts.AsArray(), j * 3, 3);
|
RcArrays.Copy(tile.data.verts, poly.verts[j] * 3, verts, j * 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
float s = frand.Next();
|
float s = frand.Next();
|
||||||
float t = frand.Next();
|
float t = frand.Next();
|
||||||
|
|
||||||
var pt = DtUtils.RandomPointInConvexPoly(verts.AsArray(), poly.vertCount, areas.AsArray(), s, t);
|
var pt = DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t);
|
||||||
ClosestPointOnPoly(polyRef, pt, out var closest, out var _);
|
ClosestPointOnPoly(polyRef, pt, out var closest, out var _);
|
||||||
|
|
||||||
randomRef = polyRef;
|
randomRef = polyRef;
|
||||||
|
@ -387,8 +386,8 @@ namespace DotRecast.Detour
|
||||||
float s = frand.Next();
|
float s = frand.Next();
|
||||||
float t = frand.Next();
|
float t = frand.Next();
|
||||||
|
|
||||||
using var areas = RcRentedArray.Rent<float>(randomPolyVerts.Length / 3);
|
float[] areas = new float[randomPolyVerts.Length / 3];
|
||||||
RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas.AsArray(), s, t);
|
RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);
|
||||||
ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _);
|
ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _);
|
||||||
|
|
||||||
randomRef = randomPolyRef;
|
randomRef = randomPolyRef;
|
||||||
|
@ -458,16 +457,16 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect vertices.
|
// Collect vertices.
|
||||||
using var verts = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly() * 3);
|
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
using var edged = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly());
|
float[] edged = new float[m_nav.GetMaxVertsPerPoly()];
|
||||||
using var edget = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly());
|
float[] edget = new float[m_nav.GetMaxVertsPerPoly()];
|
||||||
int nv = poly.vertCount;
|
int nv = poly.vertCount;
|
||||||
for (int i = 0; i < nv; ++i)
|
for (int i = 0; i < nv; ++i)
|
||||||
{
|
{
|
||||||
RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts.AsArray(), i * 3, 3);
|
RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DtUtils.DistancePtPolyEdgesSqr(pos, verts.AsArray(), nv, edged.AsArray(), edget.AsArray()))
|
if (DtUtils.DistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
|
||||||
{
|
{
|
||||||
closest = pos;
|
closest = pos;
|
||||||
}
|
}
|
||||||
|
@ -487,7 +486,7 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
int va = imin * 3;
|
int va = imin * 3;
|
||||||
int vb = ((imin + 1) % nv) * 3;
|
int vb = ((imin + 1) % nv) * 3;
|
||||||
closest = RcVecUtils.Lerp(verts.AsArray(), va, vb, edget[imin]);
|
closest = RcVecUtils.Lerp(verts, va, vb, edget[imin]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DtStatus.DT_SUCCESS;
|
return DtStatus.DT_SUCCESS;
|
||||||
|
@ -1794,9 +1793,7 @@ namespace DotRecast.Detour
|
||||||
resultPos = RcVec3f.Zero;
|
resultPos = RcVec3f.Zero;
|
||||||
|
|
||||||
if (null != visited)
|
if (null != visited)
|
||||||
{
|
|
||||||
visited.Clear();
|
visited.Clear();
|
||||||
}
|
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite()
|
if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite()
|
||||||
|
@ -1825,7 +1822,7 @@ namespace DotRecast.Detour
|
||||||
var searchPos = RcVec3f.Lerp(startPos, endPos, 0.5f);
|
var searchPos = RcVec3f.Lerp(startPos, endPos, 0.5f);
|
||||||
float searchRadSqr = RcMath.Sqr(RcVec3f.Distance(startPos, endPos) / 2.0f + 0.001f);
|
float searchRadSqr = RcMath.Sqr(RcVec3f.Distance(startPos, endPos) / 2.0f + 0.001f);
|
||||||
|
|
||||||
using var verts = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly() * 3);
|
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
|
|
||||||
while (0 < stack.Count)
|
while (0 < stack.Count)
|
||||||
{
|
{
|
||||||
|
@ -1842,11 +1839,11 @@ namespace DotRecast.Detour
|
||||||
int nverts = curPoly.vertCount;
|
int nverts = curPoly.vertCount;
|
||||||
for (int i = 0; i < nverts; ++i)
|
for (int i = 0; i < nverts; ++i)
|
||||||
{
|
{
|
||||||
RcArrays.Copy(curTile.data.verts, curPoly.verts[i] * 3, verts.AsArray(), i * 3, 3);
|
RcArrays.Copy(curTile.data.verts, curPoly.verts[i] * 3, verts, i * 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If target is inside the poly, stop search.
|
// If target is inside the poly, stop search.
|
||||||
if (DtUtils.PointInPolygon(endPos, verts.AsArray(), nverts))
|
if (DtUtils.PointInPolygon(endPos, verts, nverts))
|
||||||
{
|
{
|
||||||
bestNode = curNode;
|
bestNode = curNode;
|
||||||
bestPos = endPos;
|
bestPos = endPos;
|
||||||
|
@ -1859,7 +1856,7 @@ namespace DotRecast.Detour
|
||||||
// Find links to neighbours.
|
// Find links to neighbours.
|
||||||
int MAX_NEIS = 8;
|
int MAX_NEIS = 8;
|
||||||
int nneis = 0;
|
int nneis = 0;
|
||||||
using var neis = RcRentedArray.Rent<long>(MAX_NEIS);
|
long[] neis = new long[MAX_NEIS];
|
||||||
|
|
||||||
if ((curPoly.neis[j] & DtNavMesh.DT_EXT_LINK) != 0)
|
if ((curPoly.neis[j] & DtNavMesh.DT_EXT_LINK) != 0)
|
||||||
{
|
{
|
||||||
|
@ -1899,11 +1896,11 @@ namespace DotRecast.Detour
|
||||||
// Wall edge, calc distance.
|
// Wall edge, calc distance.
|
||||||
int vj = j * 3;
|
int vj = j * 3;
|
||||||
int vi = i * 3;
|
int vi = i * 3;
|
||||||
var distSqr = DtUtils.DistancePtSegSqr2D(endPos, verts.AsArray(), vj, vi, out var tseg);
|
var distSqr = DtUtils.DistancePtSegSqr2D(endPos, verts, vj, vi, out var tseg);
|
||||||
if (distSqr < bestDist)
|
if (distSqr < bestDist)
|
||||||
{
|
{
|
||||||
// Update nearest distance.
|
// Update nearest distance.
|
||||||
bestPos = RcVecUtils.Lerp(verts.AsArray(), vj, vi, tseg);
|
bestPos = RcVecUtils.Lerp(verts, vj, vi, tseg);
|
||||||
bestDist = distSqr;
|
bestDist = distSqr;
|
||||||
bestNode = curNode;
|
bestNode = curNode;
|
||||||
}
|
}
|
||||||
|
@ -1923,7 +1920,7 @@ namespace DotRecast.Detour
|
||||||
// TODO: Maybe should use GetPortalPoints(), but this one is way faster.
|
// TODO: Maybe should use GetPortalPoints(), but this one is way faster.
|
||||||
int vj = j * 3;
|
int vj = j * 3;
|
||||||
int vi = i * 3;
|
int vi = i * 3;
|
||||||
var distSqr = DtUtils.DistancePtSegSqr2D(searchPos, verts.AsArray(), vj, vi, out var _);
|
var distSqr = DtUtils.DistancePtSegSqr2D(searchPos, verts, vj, vi, out var _);
|
||||||
if (distSqr > searchRadSqr)
|
if (distSqr > searchRadSqr)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -2247,7 +2244,7 @@ namespace DotRecast.Detour
|
||||||
hit.path.Clear();
|
hit.path.Clear();
|
||||||
hit.pathCost = 0;
|
hit.pathCost = 0;
|
||||||
|
|
||||||
using var verts = RcRentedArray.Rent<RcVec3f>(m_nav.GetMaxVertsPerPoly() + 1);
|
RcVec3f[] verts = new RcVec3f[m_nav.GetMaxVertsPerPoly() + 1];
|
||||||
|
|
||||||
RcVec3f curPos = RcVec3f.Zero;
|
RcVec3f curPos = RcVec3f.Zero;
|
||||||
RcVec3f lastPos = RcVec3f.Zero;
|
RcVec3f lastPos = RcVec3f.Zero;
|
||||||
|
@ -2281,7 +2278,7 @@ namespace DotRecast.Detour
|
||||||
nv++;
|
nv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool intersects = DtUtils.IntersectSegmentPoly2D(startPos, endPos, verts.AsArray(), nv, out var tmin, out var tmax, out var segMin, out var segMax);
|
bool intersects = DtUtils.IntersectSegmentPoly2D(startPos, endPos, verts, nv, out var tmin, out var tmax, out var segMin, out var segMax);
|
||||||
if (!intersects)
|
if (!intersects)
|
||||||
{
|
{
|
||||||
// Could not hit the polygon, keep the old t and report hit.
|
// Could not hit the polygon, keep the old t and report hit.
|
||||||
|
@ -2876,8 +2873,8 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
float radiusSqr = RcMath.Sqr(radius);
|
float radiusSqr = RcMath.Sqr(radius);
|
||||||
|
|
||||||
using var pa = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly() * 3);
|
float[] pa = new float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
using var pb = RcRentedArray.Rent<float>(m_nav.GetMaxVertsPerPoly() * 3);
|
float[] pb = new float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
|
|
||||||
while (0 < stack.Count)
|
while (0 < stack.Count)
|
||||||
{
|
{
|
||||||
|
@ -2948,7 +2945,7 @@ namespace DotRecast.Detour
|
||||||
int npa = neighbourPoly.vertCount;
|
int npa = neighbourPoly.vertCount;
|
||||||
for (int k = 0; k < npa; ++k)
|
for (int k = 0; k < npa; ++k)
|
||||||
{
|
{
|
||||||
RcArrays.Copy(neighbourTile.data.verts, neighbourPoly.verts[k] * 3, pa.AsArray(), k * 3, 3);
|
RcArrays.Copy(neighbourTile.data.verts, neighbourPoly.verts[k] * 3, pa, k * 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool overlap = false;
|
bool overlap = false;
|
||||||
|
@ -2979,10 +2976,10 @@ namespace DotRecast.Detour
|
||||||
int npb = pastPoly.vertCount;
|
int npb = pastPoly.vertCount;
|
||||||
for (int k = 0; k < npb; ++k)
|
for (int k = 0; k < npb; ++k)
|
||||||
{
|
{
|
||||||
RcArrays.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb.AsArray(), k * 3, 3);
|
RcArrays.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb, k * 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DtUtils.OverlapPolyPoly2D(pa.AsArray(), npa, pb.AsArray(), npb))
|
if (DtUtils.OverlapPolyPoly2D(pa, npa, pb, npb))
|
||||||
{
|
{
|
||||||
overlap = true;
|
overlap = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Xml;
|
|
||||||
using DotRecast.Core.Buffers;
|
using DotRecast.Core.Buffers;
|
||||||
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Serialization;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Core.Test;
|
namespace DotRecast.Core.Test;
|
||||||
|
@ -59,50 +56,4 @@ public class RcRentedArrayTest
|
||||||
Assert.Throws<NullReferenceException>(() => rentedArray[^1] = 0);
|
Assert.Throws<NullReferenceException>(() => rentedArray[^1] = 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestSame()
|
|
||||||
{
|
|
||||||
// not same
|
|
||||||
{
|
|
||||||
using var r1 = RcRentedArray.Rent<float>(1024);
|
|
||||||
using var r2 = RcRentedArray.Rent<float>(1024);
|
|
||||||
|
|
||||||
Assert.That(r2.AsArray() != r1.AsArray(), Is.EqualTo(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
// same
|
|
||||||
{
|
|
||||||
// error case
|
|
||||||
float[] r1Array;
|
|
||||||
using (var r1 = RcRentedArray.Rent<float>(1024))
|
|
||||||
{
|
|
||||||
r1Array = r1.AsArray();
|
|
||||||
for (int i = 0; i < r1.Length; ++i)
|
|
||||||
{
|
|
||||||
r1[i] = 123;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using var r2 = RcRentedArray.Rent<float>(1024);
|
|
||||||
|
|
||||||
Assert.That(r2.AsArray() == r1Array, Is.EqualTo(true));
|
|
||||||
Assert.That(r2.AsArray().Sum(), Is.EqualTo(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestDispose()
|
|
||||||
{
|
|
||||||
var r1 = RcRentedArray.Rent<float>(1024);
|
|
||||||
for (int i = 0; i < r1.Length; ++i)
|
|
||||||
{
|
|
||||||
r1[i] = 123;
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.That(r1.IsDisposed, Is.EqualTo(false));
|
|
||||||
r1.Dispose();
|
|
||||||
Assert.That(r1.IsDisposed, Is.EqualTo(true));
|
|
||||||
Assert.That(r1.AsArray(), Is.Null);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue