Skip to content

Commit

Permalink
SOH
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed May 2, 2024
1 parent daf552b commit 9e9a3f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/DotRecast.Core/Numerics/RcVecUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static RcVec3f Create(float[] values)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcVec3f Create(float[] values, int n)
public static RcVec3f Create(Span<float> values, int n)
{
return new RcVec3f(values[n + 0], values[n + 1], values[n + 2]);
}
Expand Down Expand Up @@ -63,7 +63,7 @@ public static float Dot2D(this RcVec3f @this, RcVec3f v)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot2D(this RcVec3f @this, float[] v, int vi)
public static float Dot2D(this RcVec3f @this, Span<float> v, int vi)
{
return @this.X * v[vi] +
@this.Z * v[vi + 2];
Expand Down Expand Up @@ -262,7 +262,7 @@ public static float PerpXZ(RcVec3f a, RcVec3f b)
/// @param[in] v2 The destination vector.
/// @param[in] t The interpolation factor. [Limits: 0 <= value <= 1.0]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcVec3f Lerp(float[] verts, int v1, int v2, float t)
public static RcVec3f Lerp(Span<float> verts, int v1, int v2, float t)
{
return new RcVec3f(
verts[v1 + 0] + (verts[v2 + 0] - verts[v1 + 0]) * t,
Expand Down
20 changes: 10 additions & 10 deletions src/DotRecast.Detour/DtNavMeshQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,13 @@ public DtStatus ClosestPointOnPolyBoundary(long refs, RcVec3f pos, out RcVec3f c
}

// Collect vertices.
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
float[] edged = new float[m_nav.GetMaxVertsPerPoly()];
float[] edget = new float[m_nav.GetMaxVertsPerPoly()];
Span<float> verts = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];
Span<float> edged = stackalloc float[m_nav.GetMaxVertsPerPoly()];
Span<float> edget = stackalloc float[m_nav.GetMaxVertsPerPoly()];
int nv = poly.vertCount;
for (int i = 0; i < nv; ++i)
{
RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3);
RcSpans.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3);
}

if (DtUtils.DistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
Expand Down Expand Up @@ -1822,7 +1822,7 @@ public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos
var searchPos = RcVec3f.Lerp(startPos, endPos, 0.5f);
float searchRadSqr = RcMath.Sqr(RcVec3f.Distance(startPos, endPos) / 2.0f + 0.001f);

float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
Span<float> verts = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];

const int MAX_NEIS = 8;
Span<long> neis = stackalloc long[MAX_NEIS];
Expand All @@ -1842,7 +1842,7 @@ public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos
int nverts = curPoly.vertCount;
for (int i = 0; i < nverts; ++i)
{
RcArrays.Copy(curTile.data.verts, curPoly.verts[i] * 3, verts, i * 3, 3);
RcSpans.Copy(curTile.data.verts, curPoly.verts[i] * 3, verts, i * 3, 3);
}

// If target is inside the poly, stop search.
Expand Down Expand Up @@ -2874,8 +2874,8 @@ public DtStatus FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float r

float radiusSqr = RcMath.Sqr(radius);

float[] pa = new float[m_nav.GetMaxVertsPerPoly() * 3];
float[] pb = new float[m_nav.GetMaxVertsPerPoly() * 3];
Span<float> pa = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];
Span<float> pb = stackalloc float[m_nav.GetMaxVertsPerPoly() * 3];

while (0 < stack.Count)
{
Expand Down Expand Up @@ -2946,7 +2946,7 @@ public DtStatus FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float r
int npa = neighbourPoly.vertCount;
for (int k = 0; k < npa; ++k)
{
RcArrays.Copy(neighbourTile.data.verts, neighbourPoly.verts[k] * 3, pa, k * 3, 3);
RcSpans.Copy(neighbourTile.data.verts, neighbourPoly.verts[k] * 3, pa, k * 3, 3);
}

bool overlap = false;
Expand Down Expand Up @@ -2977,7 +2977,7 @@ public DtStatus FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float r
int npb = pastPoly.vertCount;
for (int k = 0; k < npb; ++k)
{
RcArrays.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb, k * 3, 3);
RcSpans.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb, k * 3, 3);
}

if (DtUtils.OverlapPolyPoly2D(pa, npa, pb, npb))
Expand Down
8 changes: 4 additions & 4 deletions src/DotRecast.Detour/DtUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static bool OverlapRange(float amin, float amax, float bmin, float bmax,
/// @par
///
/// All vertices are projected onto the xz-plane, so the y-values are ignored.
public static bool OverlapPolyPoly2D(float[] polya, int npolya, float[] polyb, int npolyb)
public static bool OverlapPolyPoly2D(Span<float> polya, int npolya, Span<float> polyb, int npolyb)
{
const float eps = 1e-4f;
for (int i = 0, j = npolya - 1; i < npolya; j = i++)
Expand Down Expand Up @@ -246,7 +246,7 @@ public static bool ClosestHeightPointTriangle(RcVec3f p, RcVec3f a, RcVec3f b, R
return false;
}

public static RcVec2f ProjectPoly(RcVec3f axis, float[] poly, int npoly)
public static RcVec2f ProjectPoly(RcVec3f axis, Span<float> poly, int npoly)
{
float rmin, rmax;
rmin = rmax = axis.Dot2D(poly, 0);
Expand Down Expand Up @@ -286,7 +286,7 @@ public static bool PointInPolygon(RcVec3f pt, Span<float> verts, int nverts)
return c;
}

public static bool DistancePtPolyEdgesSqr(RcVec3f pt, float[] verts, int nverts, float[] ed, float[] et)
public static bool DistancePtPolyEdgesSqr(RcVec3f pt, Span<float> verts, int nverts, Span<float> ed, Span<float> et)
{
// TODO: Replace pnpoly with triArea2D tests?
int i, j;
Expand All @@ -307,7 +307,7 @@ public static bool DistancePtPolyEdgesSqr(RcVec3f pt, float[] verts, int nverts,
return c;
}

public static float DistancePtSegSqr2D(RcVec3f pt, float[] verts, int p, int q, out float t)
public static float DistancePtSegSqr2D(RcVec3f pt, Span<float> verts, int p, int q, out float t)
{
var vp = RcVecUtils.Create(verts, p);
var vq = RcVecUtils.Create(verts, q);
Expand Down

0 comments on commit 9e9a3f0

Please sign in to comment.