Skip to content

Commit

Permalink
[Upstream] update DotRecast
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Oct 5, 2023
1 parent e9433a4 commit 6ebfb73
Show file tree
Hide file tree
Showing 31 changed files with 637 additions and 678 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static T[] CopyOf<T>(T[] source, int startIdx, int length)
return deatArr;
}

public static T[] CopyOf<T>(T[] source, int length)
public static T[] CopyOf<T>(T[] source, long length)
{
var deatArr = new T[length];
var count = Math.Max(0, Math.Min(source.Length, length));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
Copyright (c) 2009-2010 Mikko Mononen [email protected]
recast4j copyright (c) 2021 Piotr Piastucki [email protected]
DotRecast Copyright (c) 2023 Choi Ikpil [email protected]
Expand All @@ -21,7 +22,7 @@ 3. This notice may not be removed or altered from any source distribution.

namespace DotRecast.Core
{
public static class Intersections
public static class RcIntersections
{
public static bool IntersectSegmentTriangle(RcVec3f sp, RcVec3f sq, RcVec3f a, RcVec3f b, RcVec3f c, out float t)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;

namespace DotRecast.Core
{
Expand Down Expand Up @@ -107,6 +108,7 @@ public void CopyTo(float[] m)
M31 == 0f && M32 == 0f && M34 == 0f &&
M41 == 0f && M42 == 0f && M43 == 0f;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcMatrix4x4f Mul(ref RcMatrix4x4f left, ref RcMatrix4x4f right)
{
float m11 = left.M11 * right.M11 + left.M21 * right.M12 + left.M31 * right.M13 + left.M41 * right.M14;
Expand Down Expand Up @@ -147,6 +149,7 @@ public static RcMatrix4x4f Mul(ref RcMatrix4x4f left, ref RcMatrix4x4f right)
return dest;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcMatrix4x4f Mul(float[] left, float[] right)
{
float m00 = left[0] * right[0] + left[4] * right[1] + left[8] * right[2] + left[12] * right[3];
Expand Down Expand Up @@ -174,6 +177,7 @@ public static RcMatrix4x4f Mul(float[] left, float[] right)
);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcMatrix4x4f CreateFromRotate(float a, float x, float y, float z)
{
var matrix = new RcMatrix4x4f();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace DotRecast.Core
{
public class FRand : IRcRand
public class RcRand : IRcRand
{
private readonly Random _r;

public FRand()
public RcRand()
{
_r = new Random();
}

public FRand(long seed)
public RcRand(long seed)
{
_r = new Random((int)seed); // TODO : 랜덤 시드 확인 필요
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,32 +554,37 @@ public static bool IsFinite2D(RcVec3f v)
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy(ref RcVec3f @out, float[] @in, int i)
{
Copy(ref @out, 0, @in, i);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy(float[] @out, int n, float[] @in, int m)
{
@out[n] = @in[m];
@out[n + 1] = @in[m + 1];
@out[n + 2] = @in[m + 2];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy(float[] @out, int n, RcVec3f @in, int m)
{
@out[n] = @in[m];
@out[n + 1] = @in[m + 1];
@out[n + 2] = @in[m + 2];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy(ref RcVec3f @out, int n, float[] @in, int m)
{
@out[n] = @in[m];
@out[n + 1] = @in[m + 1];
@out[n + 2] = @in[m + 2];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Add(ref RcVec3f e0, RcVec3f a, float[] verts, int i)
{
e0.x = a.x + verts[i];
Expand All @@ -588,6 +593,7 @@ public static void Add(ref RcVec3f e0, RcVec3f a, float[] verts, int i)
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Sub(ref RcVec3f e0, float[] verts, int i, int j)
{
e0.x = verts[i] - verts[j];
Expand All @@ -596,6 +602,7 @@ public static void Sub(ref RcVec3f e0, float[] verts, int i, int j)
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Sub(ref RcVec3f e0, RcVec3f i, float[] verts, int j)
{
e0.x = i.x - verts[j];
Expand All @@ -604,20 +611,23 @@ public static void Sub(ref RcVec3f e0, RcVec3f i, float[] verts, int j)
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Cross(float[] dest, float[] v1, float[] v2)
{
dest[0] = v1[1] * v2[2] - v1[2] * v2[1];
dest[1] = v1[2] * v2[0] - v1[0] * v2[2];
dest[2] = v1[0] * v2[1] - v1[1] * v2[0];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Cross(float[] dest, RcVec3f v1, RcVec3f v2)
{
dest[0] = v1.y * v2.z - v1.z * v2.y;
dest[1] = v1.z * v2.x - v1.x * v2.z;
dest[2] = v1.x * v2.y - v1.y * v2.x;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Cross(ref RcVec3f dest, RcVec3f v1, RcVec3f v2)
{
dest.x = v1.y * v2.z - v1.z * v2.y;
Expand All @@ -626,14 +636,7 @@ public static void Cross(ref RcVec3f dest, RcVec3f v1, RcVec3f v2)
}


public static void Normalize(float[] v)
{
float d = (float)(1.0f / Math.Sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]));
v[0] *= d;
v[1] *= d;
v[2] *= d;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Normalize(ref RcVec3f v)
{
float d = (float)(1.0f / Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class DtCrowdAgent
public DtCrowdAgentParams option;

/// The local path corridor corners for the agent.
public List<StraightPathItem> corners = new List<StraightPathItem>();
public List<DtStraightPath> corners = new List<DtStraightPath>();

public DtMoveRequestState targetState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ public void Reset(long refs, RcVec3f pos)
* @param[in] navquery The query object used to build the corridor.
* @return Corners
*/
public int FindCorners(ref List<StraightPathItem> corners, int maxCorners, DtNavMeshQuery navquery, IDtQueryFilter filter)
public int FindCorners(ref List<DtStraightPath> corners, int maxCorners, DtNavMeshQuery navquery, IDtQueryFilter filter)
{
var result = navquery.FindStraightPath(m_pos, m_target, m_path, ref corners, maxCorners, 0);
if (result.Succeeded())
{
// Prune points in the beginning of the path which are too close.
int start = 0;
foreach (StraightPathItem spi in corners)
foreach (DtStraightPath spi in corners)
{
if ((spi.flags & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0
|| RcVec3f.Dist2DSqr(spi.pos, m_pos) > MIN_TARGET_DIST)
Expand All @@ -136,7 +136,7 @@ public int FindCorners(ref List<StraightPathItem> corners, int maxCorners, DtNav
// Prune points after an off-mesh connection.
for (int i = start; i < corners.Count; i++)
{
StraightPathItem spi = corners[i];
DtStraightPath spi = corners[i];
if ((spi.flags & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0)
{
end = i + 1;
Expand Down Expand Up @@ -201,7 +201,7 @@ public void OptimizePathVisibility(RcVec3f next, float pathOptimizationRange, Dt
{
if (rayHit.path.Count > 1 && rayHit.t > 0.99f)
{
m_path = PathUtils.MergeCorridorStartShortcut(m_path, rayHit.path);
m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, rayHit.path);
}
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public bool OptimizePathTopology(DtNavMeshQuery navquery, IDtQueryFilter filter,

if (status.Succeeded() && res.Count > 0)
{
m_path = PathUtils.MergeCorridorStartShortcut(m_path, res);
m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, res);
return true;
}

Expand Down Expand Up @@ -307,7 +307,7 @@ public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter f
var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, ref visited);
if (status.Succeeded())
{
m_path = PathUtils.MergeCorridorStartMoved(m_path, visited);
m_path = DtPathUtils.MergeCorridorStartMoved(m_path, visited);

// Adjust the position to stay on top of the navmesh.
m_pos = result;
Expand Down Expand Up @@ -347,7 +347,7 @@ public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFi
var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, ref visited);
if (status.Succeeded())
{
m_path = PathUtils.MergeCorridorEndMoved(m_path, visited);
m_path = DtPathUtils.MergeCorridorEndMoved(m_path, visited);
// TODO: should we do that?
// Adjust the position to stay on top of the navmesh.
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

using System;

namespace DotRecast.Detour.Extras
{
public static class PolyUtils
public static class DtPolyUtils
{
/**
* Find edge shared by 2 polygons within the same tile
*/
// Find edge shared by 2 polygons within the same tile
public static int FindEdge(DtPoly node, DtPoly neighbour, DtMeshData tile, DtMeshData neighbourTile)
{
// Compare indices first assuming there are no duplicate vertices
Expand Down Expand Up @@ -64,7 +64,7 @@ private static bool SamePosition(float[] verts, int v, float[] verts2, int v2)
{
for (int i = 0; i < 3; i++)
{
if (verts[3 * v + i] != verts2[3 * v2 + 1])
if (Math.Abs(verts[3 * v + i] - verts2[3 * v2 + 1]) > float.Epsilon)
{
return false;
}
Expand All @@ -73,9 +73,7 @@ private static bool SamePosition(float[] verts, int v, float[] verts2, int v2)
return true;
}

/**
* Find edge closest to the given coordinate
*/
// Find edge closest to the given coordinate
public static int FindEdge(DtPoly node, DtMeshData tile, float value, int comp)
{
float error = float.MaxValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Build(int nodeOffset, GraphMeshData graphData, List<int[]> connectio

private void BuildInternalLink(DtMeshData tile, DtPoly node, DtMeshData neighbourTile, DtPoly neighbour)
{
int edge = PolyUtils.FindEdge(node, neighbour, tile, neighbourTile);
int edge = DtPolyUtils.FindEdge(node, neighbour, tile, neighbourTile);
if (edge >= 0)
{
node.neis[edge] = neighbour.index + 1;
Expand All @@ -65,19 +65,19 @@ private void BuildExternalLink(DtMeshData tile, DtPoly node, DtMeshData neighbou
{
if (neighbourTile.header.bmin.x > tile.header.bmin.x)
{
node.neis[PolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK;
node.neis[DtPolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK;
}
else if (neighbourTile.header.bmin.x < tile.header.bmin.x)
{
node.neis[PolyUtils.FindEdge(node, tile, tile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK | 4;
node.neis[DtPolyUtils.FindEdge(node, tile, tile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK | 4;
}
else if (neighbourTile.header.bmin.z > tile.header.bmin.z)
{
node.neis[PolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 2;
node.neis[DtPolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 2;
}
else
{
node.neis[PolyUtils.FindEdge(node, tile, tile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 6;
node.neis[DtPolyUtils.FindEdge(node, tile, tile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 6;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public byte[] Decompress(byte[] buf, int offset, int len, int outputlen)

public byte[] Compress(byte[] buf)
{
byte[] output = new byte[FastLZ.CalculateOutputBufferLength(buf.Length)];
int len = FastLZ.Compress(buf, 0, buf.Length, output, 0, output.Length);
byte[] output = new byte[FastLZ.EstimateCompressedSize(buf.Length)];
long len = FastLZ.CompressLevel(2, buf, 0, buf.Length, output);
return RcArrayUtils.CopyOf(output, len);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DotRecast.Detour
{
public enum InFlag
public enum DtConvexConvexInFlag
{
Pin,
Qin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace DotRecast.Detour
{
public enum Intersection
public enum DtConvexConvexIntersection
{
None,
Single,
Expand Down
Loading

0 comments on commit 6ebfb73

Please sign in to comment.