forked from mirror/DotRecast
Compare commits
No commits in common. "master" and "risky_optimizations" have entirely different histories.
master
...
risky_opti
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"name": "rnd/dotrecastnetsim",
|
|
||||||
"description": "DotRecast",
|
|
||||||
"homepage": "https://git.bit5.ru/rnd/DotRecastNetSim.git",
|
|
||||||
"require": {
|
|
||||||
"php": ">=7.4"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace DotRecast.Core.Buffers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct RcRentedArray<T> : IDisposable
|
public class RcRentedArray<T> : IDisposable
|
||||||
{
|
{
|
||||||
private ArrayPool<T> _owner;
|
private ArrayPool<T> _owner;
|
||||||
private T[] _array;
|
private T[] _array;
|
||||||
|
|
|
@ -27,12 +27,12 @@ namespace DotRecast.Core.Collections
|
||||||
{
|
{
|
||||||
private bool _dirty;
|
private bool _dirty;
|
||||||
private readonly List<T> _items;
|
private readonly List<T> _items;
|
||||||
private readonly Comparison<T> _comparison;
|
private readonly Comparer<T> _comparer;
|
||||||
|
|
||||||
public RcSortedQueue(Comparison<T> comp)
|
public RcSortedQueue(Comparison<T> comp)
|
||||||
{
|
{
|
||||||
_items = new List<T>();
|
_items = new List<T>();
|
||||||
_comparison = (x, y) => comp(x, y) * -1;
|
_comparer = Comparer<T>.Create((x, y) => comp.Invoke(x, y) * -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count()
|
public int Count()
|
||||||
|
@ -55,7 +55,7 @@ namespace DotRecast.Core.Collections
|
||||||
{
|
{
|
||||||
if (_dirty)
|
if (_dirty)
|
||||||
{
|
{
|
||||||
_items.Sort(_comparison); // reverse
|
_items.Sort(_comparer); // reverse
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Core",
|
|
||||||
"rootNamespace": "DotRecast.Core",
|
|
||||||
"references": [],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Detour.Crowd",
|
|
||||||
"rootNamespace": "DotRecast.Detour.Crowd",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core",
|
|
||||||
"DotRecast.Detour"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -22,7 +22,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -1057,7 +1056,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check
|
// Check
|
||||||
float triggerRadius = ag.option.radius * 0.25f;//todo make parameterizable
|
float triggerRadius = ag.option.radius * 2.25f;
|
||||||
if (ag.OverOffmeshConnection(triggerRadius))
|
if (ag.OverOffmeshConnection(triggerRadius))
|
||||||
{
|
{
|
||||||
// Prepare to off-mesh connection.
|
// Prepare to off-mesh connection.
|
||||||
|
@ -1206,9 +1205,6 @@ namespace DotRecast.Detour.Crowd
|
||||||
for (int j = 0; j < ag.nneis; ++j)
|
for (int j = 0; j < ag.nneis; ++j)
|
||||||
{
|
{
|
||||||
DtCrowdAgent nei = ag.neis[j].agent;
|
DtCrowdAgent nei = ag.neis[j].agent;
|
||||||
if(!nei.option.contributeObstacleAvoidance || nei.option.obstacleAvoidanceWeight < ag.option.obstacleAvoidanceWeight)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
_obstacleQuery.AddCircle(nei.npos, nei.option.radius, nei.vel, nei.dvel);
|
_obstacleQuery.AddCircle(nei.npos, nei.option.radius, nei.vel, nei.dvel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,6 @@ namespace DotRecast.Detour.Crowd
|
||||||
/// [Limits: 0 <= value < #DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS]
|
/// [Limits: 0 <= value < #DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS]
|
||||||
public int obstacleAvoidanceType;
|
public int obstacleAvoidanceType;
|
||||||
|
|
||||||
public bool contributeObstacleAvoidance;
|
|
||||||
public float obstacleAvoidanceWeight;
|
|
||||||
|
|
||||||
/// The index of the query filter used by this agent.
|
/// The index of the query filter used by this agent.
|
||||||
public int queryFilterType;
|
public int queryFilterType;
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Detour.Dynamic",
|
|
||||||
"rootNamespace": "DotRecast.Detour.Dynamic",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Detour",
|
|
||||||
"DotRecast.Recast",
|
|
||||||
"DotRecast.Core"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Detour.Extras",
|
|
||||||
"rootNamespace": "DotRecast.Detour.Extras",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core",
|
|
||||||
"DotRecast.Detour",
|
|
||||||
"DotRecast.Recast"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -52,12 +52,25 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
|
|
||||||
RcVec3f halfExtents = new RcVec3f { X = cs, Y = heightRange, Z = cs };
|
RcVec3f halfExtents = new RcVec3f { X = cs, Y = heightRange, Z = cs };
|
||||||
float maxHeight = pt.Y + heightRange;
|
float maxHeight = pt.Y + heightRange;
|
||||||
var query = new DtHeightSamplePolyQuery(navMeshQuery, pt, pt.Y, maxHeight);
|
RcAtomicBoolean found = new RcAtomicBoolean();
|
||||||
navMeshQuery.QueryPolygons(pt, halfExtents, DtQueryNoOpFilter.Shared, ref query);
|
RcAtomicFloat minHeight = new RcAtomicFloat(pt.Y);
|
||||||
|
|
||||||
if (query.Found)
|
navMeshQuery.QueryPolygons(pt, halfExtents, DtQueryNoOpFilter.Shared, new DtCallbackPolyQuery((tile, poly, refs) =>
|
||||||
{
|
{
|
||||||
height = query.MinHeight;
|
var status = navMeshQuery.GetPolyHeight(refs, pt, out var h);
|
||||||
|
if (status.Succeeded())
|
||||||
|
{
|
||||||
|
if (h > minHeight.Get() && h < maxHeight)
|
||||||
|
{
|
||||||
|
minHeight.Exchange(h);
|
||||||
|
found.Set(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (found.Get())
|
||||||
|
{
|
||||||
|
height = minHeight.Get();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Detour.TileCache",
|
|
||||||
"rootNamespace": "DotRecast.Detour.TileCache",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core",
|
|
||||||
"DotRecast.Detour",
|
|
||||||
"DotRecast.Recast"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Detour",
|
|
||||||
"rootNamespace": "DotRecast.Detour",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
public struct DtCallbackPolyQuery : IDtPolyQuery
|
public class DtCallbackPolyQuery : IDtPolyQuery
|
||||||
{
|
{
|
||||||
private readonly Action<DtMeshTile, DtPoly, long> _callback;
|
private readonly Action<DtMeshTile, DtPoly, long> _callback;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace DotRecast.Detour
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(DtMeshTile tile, Span<DtPoly> poly, Span<long> refs, int count)
|
public void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace DotRecast.Detour
|
||||||
return m_overflow;
|
return m_overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(DtMeshTile tile, Span<DtPoly> poly, Span<long> refs, int count)
|
public void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count)
|
||||||
{
|
{
|
||||||
int numLeft = m_maxPolys - m_numCollected;
|
int numLeft = m_maxPolys - m_numCollected;
|
||||||
int toCopy = count;
|
int toCopy = count;
|
||||||
|
|
|
@ -3,7 +3,7 @@ using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
public struct DtFindNearestPolyQuery : IDtPolyQuery
|
public class DtFindNearestPolyQuery : IDtPolyQuery
|
||||||
{
|
{
|
||||||
private readonly DtNavMeshQuery _query;
|
private readonly DtNavMeshQuery _query;
|
||||||
private readonly RcVec3f _center;
|
private readonly RcVec3f _center;
|
||||||
|
@ -18,12 +18,9 @@ namespace DotRecast.Detour
|
||||||
_center = center;
|
_center = center;
|
||||||
_nearestDistanceSqr = float.MaxValue;
|
_nearestDistanceSqr = float.MaxValue;
|
||||||
_nearestPoint = center;
|
_nearestPoint = center;
|
||||||
|
|
||||||
_nearestRef = default;
|
|
||||||
_overPoly = default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(DtMeshTile tile, Span<DtPoly> poly, Span<long> refs, int count)
|
public void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
using System;
|
|
||||||
using DotRecast.Core;
|
|
||||||
using DotRecast.Core.Numerics;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
|
||||||
{
|
|
||||||
public struct DtHeightSamplePolyQuery : IDtPolyQuery
|
|
||||||
{
|
|
||||||
private readonly DtNavMeshQuery _navMeshQuery;
|
|
||||||
private readonly RcVec3f _pt;
|
|
||||||
private readonly float _maxHeight;
|
|
||||||
public float MinHeight { get; private set; }
|
|
||||||
public bool Found { get; private set; }
|
|
||||||
|
|
||||||
public DtHeightSamplePolyQuery(DtNavMeshQuery navMeshQuery, RcVec3f pt, float minHeight, float maxHeight)
|
|
||||||
{
|
|
||||||
_navMeshQuery = navMeshQuery;
|
|
||||||
_pt = pt;
|
|
||||||
MinHeight = minHeight;
|
|
||||||
_maxHeight = maxHeight;
|
|
||||||
Found = default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Process(DtMeshTile tile, Span<DtPoly> poly, Span<long> refs, int count)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
ProcessSingle(refs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProcessSingle(long refs)
|
|
||||||
{
|
|
||||||
var status = _navMeshQuery.GetPolyHeight(refs, _pt, out var h);
|
|
||||||
if (!status.Succeeded())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(h > MinHeight) || !(h < _maxHeight))
|
|
||||||
return;
|
|
||||||
|
|
||||||
MinHeight = h;
|
|
||||||
Found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,11 +18,8 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
[Serializable]
|
|
||||||
public class DtMeshData
|
public class DtMeshData
|
||||||
{
|
{
|
||||||
public DtMeshHeader header; //< The tile header.
|
public DtMeshHeader header; //< The tile header.
|
||||||
|
|
|
@ -18,13 +18,11 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
/** Provides high level information related to a dtMeshTile object. */
|
/** Provides high level information related to a dtMeshTile object. */
|
||||||
[Serializable]
|
|
||||||
public class DtMeshHeader
|
public class DtMeshHeader
|
||||||
{
|
{
|
||||||
/** Tile magic number. (Used to identify the data format.) */
|
/** Tile magic number. (Used to identify the data format.) */
|
||||||
|
|
|
@ -1365,11 +1365,6 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetTilesAt(int x, int y, DtMeshTile[] tiles, int maxTiles)
|
public int GetTilesAt(int x, int y, DtMeshTile[] tiles, int maxTiles)
|
||||||
{
|
|
||||||
return GetTilesAt(x, y, (Span<DtMeshTile>)tiles, maxTiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetTilesAt(int x, int y, Span<DtMeshTile> tiles, int maxTiles)
|
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
|
|
|
@ -589,7 +589,7 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
// Get nearby polygons from proximity grid.
|
// Get nearby polygons from proximity grid.
|
||||||
DtFindNearestPolyQuery query = new DtFindNearestPolyQuery(this, center);
|
DtFindNearestPolyQuery query = new DtFindNearestPolyQuery(this, center);
|
||||||
DtStatus status = QueryPolygons(center, halfExtents, filter, ref query);
|
DtStatus status = QueryPolygons(center, halfExtents, filter, query);
|
||||||
if (status.Failed())
|
if (status.Failed())
|
||||||
{
|
{
|
||||||
return status;
|
return status;
|
||||||
|
@ -603,13 +603,11 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queries polygons within a tile.
|
/// Queries polygons within a tile.
|
||||||
protected void QueryPolygonsInTile<TQuery>(DtMeshTile tile, RcVec3f qmin, RcVec3f qmax, IDtQueryFilter filter, ref TQuery query)
|
protected void QueryPolygonsInTile(DtMeshTile tile, RcVec3f qmin, RcVec3f qmax, IDtQueryFilter filter, IDtPolyQuery query)
|
||||||
where TQuery : IDtPolyQuery
|
|
||||||
{
|
{
|
||||||
const int batchSize = 32;
|
const int batchSize = 32;
|
||||||
Span<long> polyRefs = stackalloc long[batchSize];
|
Span<long> polyRefs = stackalloc long[batchSize];
|
||||||
using RcRentedArray<DtPoly> polysRent = RcRentedArray.Rent<DtPoly>(batchSize);
|
DtPoly[] polys = new DtPoly[batchSize];
|
||||||
Span<DtPoly> polys = polysRent.AsSpan();
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
if (tile.data.bvTree != null)
|
if (tile.data.bvTree != null)
|
||||||
|
@ -760,7 +758,7 @@ namespace DotRecast.Detour
|
||||||
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
|
|
||||||
DtCollectPolysQuery collector = new DtCollectPolysQuery(polys, maxPolys);
|
DtCollectPolysQuery collector = new DtCollectPolysQuery(polys, maxPolys);
|
||||||
DtStatus status = QueryPolygons(center, halfExtents, filter, ref collector);
|
DtStatus status = QueryPolygons(center, halfExtents, filter, collector);
|
||||||
if (status.Failed())
|
if (status.Failed())
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
@ -782,8 +780,7 @@ namespace DotRecast.Detour
|
||||||
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
|
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
|
||||||
/// @param[in] filter The polygon filter to apply to the query.
|
/// @param[in] filter The polygon filter to apply to the query.
|
||||||
/// @param[in] query The query. Polygons found will be batched together and passed to this query.
|
/// @param[in] query The query. Polygons found will be batched together and passed to this query.
|
||||||
public DtStatus QueryPolygons<TQuery>(RcVec3f center, RcVec3f halfExtents, IDtQueryFilter filter, ref TQuery query)
|
public DtStatus QueryPolygons(RcVec3f center, RcVec3f halfExtents, IDtQueryFilter filter, IDtPolyQuery query)
|
||||||
where TQuery : IDtPolyQuery
|
|
||||||
{
|
{
|
||||||
if (!center.IsFinite() || !halfExtents.IsFinite() || null == filter)
|
if (!center.IsFinite() || !halfExtents.IsFinite() || null == filter)
|
||||||
{
|
{
|
||||||
|
@ -799,8 +796,7 @@ namespace DotRecast.Detour
|
||||||
m_nav.CalcTileLoc(bmax, out var maxx, out var maxy);
|
m_nav.CalcTileLoc(bmax, out var maxx, out var maxy);
|
||||||
|
|
||||||
const int MAX_NEIS = 32;
|
const int MAX_NEIS = 32;
|
||||||
using RcRentedArray<DtMeshTile> neisRent = RcRentedArray.Rent<DtMeshTile>(MAX_NEIS);
|
DtMeshTile[] neis = new DtMeshTile[MAX_NEIS];
|
||||||
Span<DtMeshTile> neis = neisRent.AsSpan();
|
|
||||||
|
|
||||||
for (int y = miny; y <= maxy; ++y)
|
for (int y = miny; y <= maxy; ++y)
|
||||||
{
|
{
|
||||||
|
@ -809,7 +805,7 @@ namespace DotRecast.Detour
|
||||||
int nneis = m_nav.GetTilesAt(x, y, neis, MAX_NEIS);
|
int nneis = m_nav.GetTilesAt(x, y, neis, MAX_NEIS);
|
||||||
for (int j = 0; j < nneis; ++j)
|
for (int j = 0; j < nneis; ++j)
|
||||||
{
|
{
|
||||||
QueryPolygonsInTile(neis[j], bmin, bmax, filter, ref query);
|
QueryPolygonsInTile(neis[j], bmin, bmax, filter, query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2541,7 +2537,7 @@ namespace DotRecast.Detour
|
||||||
// int va = a * 3;
|
// int va = a * 3;
|
||||||
// int vb = b * 3;
|
// int vb = b * 3;
|
||||||
float dx = verts[b].X - verts[a].X;
|
float dx = verts[b].X - verts[a].X;
|
||||||
float dz = verts[b].Z - verts[a].Z;
|
float dz = verts[b].Z - verts[a].X;
|
||||||
hit.hitNormal = RcVec3f.Normalize(new RcVec3f(dz, 0, -dx));
|
hit.hitNormal = RcVec3f.Normalize(new RcVec3f(dz, 0, -dx));
|
||||||
return DtStatus.DT_SUCCESS;
|
return DtStatus.DT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,8 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DotRecast.Core.Buffers;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
|
@ -29,68 +27,24 @@ namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
private readonly Dictionary<long, List<DtNode>> m_map;
|
private readonly Dictionary<long, List<DtNode>> m_map;
|
||||||
|
|
||||||
private int m_usedNodesCount;
|
private int m_nodeCount;
|
||||||
private List<DtNode[]> m_buckets;
|
private readonly List<DtNode> m_nodes;
|
||||||
private readonly int m_initialBufferCapacityBase;
|
|
||||||
private readonly RcObjectPool<List<DtNode>> m_listPool;
|
|
||||||
|
|
||||||
public DtNodePool(int initialBufferCapacityBase = 6) // initial size 64
|
public DtNodePool()
|
||||||
{
|
{
|
||||||
m_map = new Dictionary<long, List<DtNode>>();
|
m_map = new Dictionary<long, List<DtNode>>();
|
||||||
m_listPool = new RcObjectPool<List<DtNode>>(() => new List<DtNode>());
|
m_nodes = new List<DtNode>();
|
||||||
m_buckets = new List<DtNode[]>();
|
|
||||||
m_initialBufferCapacityBase = initialBufferCapacityBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddNewBucket()
|
|
||||||
{
|
|
||||||
var bucketIndex = m_buckets.Count;
|
|
||||||
var bucket = new DtNode[1 << (bucketIndex + m_initialBufferCapacityBase)];
|
|
||||||
m_buckets.Add(bucket);
|
|
||||||
FillBucket(bucketIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FillBucket(int bucketIndex)
|
|
||||||
{
|
|
||||||
var bucket = m_buckets[bucketIndex];
|
|
||||||
var startIndex = GetBucketStartIndex(bucketIndex);
|
|
||||||
for (int i = 0; i < bucket.Length; i++)
|
|
||||||
{
|
|
||||||
bucket[i] = new DtNode(startIndex + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetBucketStartIndex(int bucketIndex)
|
|
||||||
{
|
|
||||||
return ((1 << (bucketIndex + m_initialBufferCapacityBase)) - 1) ^ ((1 << m_initialBufferCapacityBase) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DtNode[] EnsureBucket(int bucketIndex)
|
|
||||||
{
|
|
||||||
if (m_buckets.Count == bucketIndex)
|
|
||||||
AddNewBucket();
|
|
||||||
else if (m_buckets.Count < bucketIndex)
|
|
||||||
throw new Exception();
|
|
||||||
return m_buckets[bucketIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetBucketIndexByElementIndex(int elementIndex)
|
|
||||||
{
|
|
||||||
return DtUtils.Ilog2((elementIndex >> m_initialBufferCapacityBase) + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
foreach (var pair in m_map)
|
|
||||||
m_listPool.Return(pair.Value);
|
|
||||||
|
|
||||||
m_map.Clear();
|
m_map.Clear();
|
||||||
m_usedNodesCount = 0;
|
m_nodeCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetNodeCount()
|
public int GetNodeCount()
|
||||||
{
|
{
|
||||||
return m_usedNodesCount;
|
return m_nodeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int FindNodes(long id, out List<DtNode> nodes)
|
public int FindNodes(long id, out List<DtNode> nodes)
|
||||||
|
@ -130,8 +84,7 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nodes = m_listPool.Get();
|
nodes = new List<DtNode>();
|
||||||
nodes.Clear();
|
|
||||||
m_map.Add(id, nodes);
|
m_map.Add(id, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,10 +93,15 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
private DtNode Create(long id, int state, List<DtNode> nodes)
|
private DtNode Create(long id, int state, List<DtNode> nodes)
|
||||||
{
|
{
|
||||||
int i = m_usedNodesCount++;
|
if (m_nodes.Count <= m_nodeCount)
|
||||||
int bucketIndex = GetBucketIndexByElementIndex(i);
|
{
|
||||||
int bucketStartIndex = GetBucketStartIndex(bucketIndex);
|
var newNode = new DtNode(m_nodeCount);
|
||||||
var node = EnsureBucket(bucketIndex)[i - bucketStartIndex];
|
m_nodes.Add(newNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = m_nodeCount;
|
||||||
|
m_nodeCount++;
|
||||||
|
var node = m_nodes[i];
|
||||||
node.pidx = 0;
|
node.pidx = 0;
|
||||||
node.cost = 0;
|
node.cost = 0;
|
||||||
node.total = 0;
|
node.total = 0;
|
||||||
|
@ -165,16 +123,9 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
public DtNode GetNodeAtIdx(int idx)
|
public DtNode GetNodeAtIdx(int idx)
|
||||||
{
|
{
|
||||||
if (idx == 0)
|
return idx != 0
|
||||||
return null;
|
? m_nodes[idx - 1]
|
||||||
|
: null;
|
||||||
int bucketIndex = GetBucketIndexByElementIndex(idx - 1);
|
|
||||||
if (m_buckets.Count <= bucketIndex)
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
|
|
||||||
int bucketStartIndex = GetBucketStartIndex(bucketIndex);
|
|
||||||
var node = EnsureBucket(bucketIndex)[idx - bucketStartIndex - 1];
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DtNode GetNode(long refs)
|
public DtNode GetNode(long refs)
|
||||||
|
@ -184,7 +135,7 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
public IEnumerable<DtNode> AsEnumerable()
|
public IEnumerable<DtNode> AsEnumerable()
|
||||||
{
|
{
|
||||||
return m_buckets.SelectMany(x => x);
|
return m_nodes.Take(m_nodeCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,14 +18,12 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
/// Defines an navigation mesh off-mesh connection within a dtMeshTile object.
|
/// Defines an navigation mesh off-mesh connection within a dtMeshTile object.
|
||||||
/// An off-mesh connection is a user defined traversable connection made up to two vertices.
|
/// An off-mesh connection is a user defined traversable connection made up to two vertices.
|
||||||
[Serializable]
|
|
||||||
public class DtOffMeshConnection
|
public class DtOffMeshConnection
|
||||||
{
|
{
|
||||||
/// The endpoints of the connection. [(ax, ay, az, bx, by, bz)]
|
/// The endpoints of the connection. [(ax, ay, az, bx, by, bz)]
|
||||||
|
|
|
@ -9,6 +9,6 @@ namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
/// Called for each batch of unique polygons touched by the search area in dtNavMeshQuery::queryPolygons.
|
/// Called for each batch of unique polygons touched by the search area in dtNavMeshQuery::queryPolygons.
|
||||||
/// This can be called multiple times for a single query.
|
/// This can be called multiple times for a single query.
|
||||||
void Process(DtMeshTile tile, Span<DtPoly> poly, Span<long> refs, int count);
|
void Process(DtMeshTile tile, DtPoly[] poly, Span<long> refs, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Recast.Demo",
|
|
||||||
"rootNamespace": "DotRecast.Recast.Demo",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [
|
|
||||||
"Android",
|
|
||||||
"Editor",
|
|
||||||
"EmbeddedLinux",
|
|
||||||
"GameCoreScarlett",
|
|
||||||
"GameCoreXboxOne",
|
|
||||||
"iOS",
|
|
||||||
"LinuxStandalone64",
|
|
||||||
"CloudRendering",
|
|
||||||
"macOSStandalone",
|
|
||||||
"PS4",
|
|
||||||
"PS5",
|
|
||||||
"QNX",
|
|
||||||
"Stadia",
|
|
||||||
"Switch",
|
|
||||||
"tvOS",
|
|
||||||
"WSA",
|
|
||||||
"VisionOS",
|
|
||||||
"WebGL",
|
|
||||||
"WindowsStandalone32",
|
|
||||||
"WindowsStandalone64",
|
|
||||||
"XboxOne"
|
|
||||||
],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [
|
|
||||||
{
|
|
||||||
"name": "Select...",
|
|
||||||
"expression": "",
|
|
||||||
"define": "USE_RECAST_DEMO"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Recast.Toolset",
|
|
||||||
"rootNamespace": "DotRecast.Recast.Toolset",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core",
|
|
||||||
"DotRecast.Recast",
|
|
||||||
"DotRecast.Detour",
|
|
||||||
"DotRecast.Detour.Crowd",
|
|
||||||
"DotRecast.Detour.Dynamic",
|
|
||||||
"DotRecast.Detour.Extras",
|
|
||||||
"DotRecast.Detour.TileCache"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -46,13 +46,13 @@ namespace DotRecast.Recast.Toolset.Geom
|
||||||
if (null != _geom)
|
if (null != _geom)
|
||||||
{
|
{
|
||||||
var offMeshConnections = _geom.GetOffMeshConnections();
|
var offMeshConnections = _geom.GetOffMeshConnections();
|
||||||
option.offMeshConCount = offMeshConnections.Count;
|
|
||||||
option.offMeshConVerts = new float[option.offMeshConCount * 6];
|
option.offMeshConVerts = new float[option.offMeshConCount * 6];
|
||||||
option.offMeshConRad = new float[option.offMeshConCount];
|
option.offMeshConRad = new float[option.offMeshConCount];
|
||||||
option.offMeshConDir = new int[option.offMeshConCount];
|
option.offMeshConDir = new int[option.offMeshConCount];
|
||||||
option.offMeshConAreas = new int[option.offMeshConCount];
|
option.offMeshConAreas = new int[option.offMeshConCount];
|
||||||
option.offMeshConFlags = new int[option.offMeshConCount];
|
option.offMeshConFlags = new int[option.offMeshConCount];
|
||||||
option.offMeshConUserID = new int[option.offMeshConCount];
|
option.offMeshConUserID = new int[option.offMeshConCount];
|
||||||
|
option.offMeshConCount = offMeshConnections.Count;
|
||||||
for (int i = 0; i < option.offMeshConCount; i++)
|
for (int i = 0; i < option.offMeshConCount; i++)
|
||||||
{
|
{
|
||||||
RcOffMeshConnection offMeshCon = offMeshConnections[i];
|
RcOffMeshConnection offMeshCon = offMeshConnections[i];
|
||||||
|
@ -65,7 +65,7 @@ namespace DotRecast.Recast.Toolset.Geom
|
||||||
option.offMeshConDir[i] = offMeshCon.bidir ? 1 : 0;
|
option.offMeshConDir[i] = offMeshCon.bidir ? 1 : 0;
|
||||||
option.offMeshConAreas[i] = offMeshCon.area;
|
option.offMeshConAreas[i] = offMeshCon.area;
|
||||||
option.offMeshConFlags[i] = offMeshCon.flags;
|
option.offMeshConFlags[i] = offMeshCon.flags;
|
||||||
option.offMeshConUserID[i] = offMeshCon.userId;
|
// option.offMeshConUserID[i] = offMeshCon.userId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"name": "DotRecast.Recast",
|
|
||||||
"rootNamespace": "DotRecast.Recast",
|
|
||||||
"references": [
|
|
||||||
"DotRecast.Core"
|
|
||||||
],
|
|
||||||
"includePlatforms": [],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": true
|
|
||||||
}
|
|
|
@ -33,7 +33,7 @@ namespace DotRecast.Recast.Geom
|
||||||
public readonly int flags;
|
public readonly int flags;
|
||||||
public readonly int userId;
|
public readonly int userId;
|
||||||
|
|
||||||
public RcOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags, int userId = 0)
|
public RcOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags)
|
||||||
{
|
{
|
||||||
verts = new float[6];
|
verts = new float[6];
|
||||||
verts[0] = start.X;
|
verts[0] = start.X;
|
||||||
|
@ -46,7 +46,6 @@ namespace DotRecast.Recast.Geom
|
||||||
this.bidir = bidir;
|
this.bidir = bidir;
|
||||||
this.area = area;
|
this.area = area;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
this.userId = userId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"name": "com.rnd.dotrecast",
|
|
||||||
"displayName": "DotRecast",
|
|
||||||
"version": "0.4.1"
|
|
||||||
}
|
|
Loading…
Reference in New Issue