diff --git a/src/DotRecast.Core/Numerics/RcVec3f.cs b/src/DotRecast.Core/Numerics/RcVec3f.cs index e449d5e..e3a05ee 100644 --- a/src/DotRecast.Core/Numerics/RcVec3f.cs +++ b/src/DotRecast.Core/Numerics/RcVec3f.cs @@ -50,13 +50,13 @@ namespace DotRecast.Core.Numerics } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RcVec3f(ReadOnlySpan values) - { - X = values[0]; - Y = values[1]; - Z = values[2]; - } + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public RcVec3f(ReadOnlySpan values) + // { + // X = values[0]; + // Y = values[1]; + // Z = values[2]; + // } public float this[int index] { diff --git a/src/DotRecast.Core/Numerics/RcVecUtils.cs b/src/DotRecast.Core/Numerics/RcVecUtils.cs index caddbc5..f63a92f 100644 --- a/src/DotRecast.Core/Numerics/RcVecUtils.cs +++ b/src/DotRecast.Core/Numerics/RcVecUtils.cs @@ -6,6 +6,18 @@ namespace DotRecast.Core.Numerics public static class RcVecUtils { public const float EPSILON = 1e-6f; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static RcVec3f Create(float[] values) + { + return Create(values, 0); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static RcVec3f Create(float[] values, int n) + { + return new RcVec3f(values[n + 0], values[n + 1], values[n + 2]); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Get(this RcVec2f v, int i) diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 1fcd3f2..866b373 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -412,7 +412,7 @@ namespace DotRecast.Detour.Crowd else if (n == 0) { // The first polyref is bad, use current safe values. - m_pos = new RcVec3f(safePos); + m_pos = RcVecUtils.Create(safePos); m_path.Clear(); m_path.Add(safeRef); } diff --git a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs index 9ca94fd..55aedf6 100644 --- a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs +++ b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs @@ -40,8 +40,8 @@ namespace DotRecast.Detour.Extras BVItem it = new BVItem(); items[i] = it; it.i = i; - RcVec3f bmin = new RcVec3f(data.verts.AsSpan(data.polys[i].verts[0] * 3)); - RcVec3f bmax = new RcVec3f(data.verts.AsSpan(data.polys[i].verts[0] * 3)); + RcVec3f bmin = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3); + RcVec3f bmax = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3); for (int j = 1; j < data.polys[i].vertCount; j++) { bmin = RcVecUtils.Min(bmin, data.verts, data.polys[i].verts[j] * 3); diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs index fb12265..8623520 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs @@ -56,7 +56,7 @@ namespace DotRecast.Detour.Extras.Unity.Astar connection.rad = 0.1f; connection.side = startTile == endTile ? 0xFF - : DtNavMeshBuilder.ClassifyOffMeshPoint(new RcVec3f(connection.pos.AsSpan(3)), startTile.header.bmin, startTile.header.bmax); + : DtNavMeshBuilder.ClassifyOffMeshPoint(RcVecUtils.Create(connection.pos, 3), startTile.header.bmin, startTile.header.bmax); connection.userId = (int)l.linkID; if (startTile.offMeshCons == null) { diff --git a/src/DotRecast.Detour/DtConvexConvexIntersections.cs b/src/DotRecast.Detour/DtConvexConvexIntersections.cs index 09ac8c1..7569411 100644 --- a/src/DotRecast.Detour/DtConvexConvexIntersections.cs +++ b/src/DotRecast.Detour/DtConvexConvexIntersections.cs @@ -53,10 +53,10 @@ namespace DotRecast.Detour do { - a = new RcVec3f(p.AsSpan(3 * (ai % n))); - b = new RcVec3f(q.AsSpan(3 * (bi % m))); - a1 = new RcVec3f(p.AsSpan(3 * ((ai + n - 1) % n))); // prev a - b1 = new RcVec3f(q.AsSpan(3 * ((bi + m - 1) % m))); // prev b + a = RcVecUtils.Create(p, 3 * (ai % n)); + b = RcVecUtils.Create(q, 3 * (bi % m)); + a1 = RcVecUtils.Create(p, 3 * ((ai + n - 1) % n)); // prev a + b1 = RcVecUtils.Create(q, 3 * ((bi + m - 1) % m)); // prev b RcVec3f A = RcVec3f.Subtract(a, a1); RcVec3f B = RcVec3f.Subtract(b, b1); diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 34c3d09..556a8e4 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -401,8 +401,8 @@ namespace DotRecast.Detour // Calc polygon bounds. int v = p.verts[0] * 3; - bmin = new RcVec3f(tile.data.verts.AsSpan(v)); - bmax = new RcVec3f(tile.data.verts.AsSpan(v)); + bmin = RcVecUtils.Create(tile.data.verts, v); + bmax = RcVecUtils.Create(tile.data.verts, v); for (int j = 1; j < p.vertCount; ++j) { v = p.verts[j] * 3; @@ -1569,8 +1569,8 @@ namespace DotRecast.Detour } } - startPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx0] * 3)); - endPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx1] * 3)); + startPos = RcVecUtils.Create(tile.data.verts, poly.verts[idx0] * 3); + endPos = RcVecUtils.Create(tile.data.verts, poly.verts[idx1] * 3); return DtStatus.DT_SUCCSESS; } diff --git a/src/DotRecast.Detour/DtNavMeshBuilder.cs b/src/DotRecast.Detour/DtNavMeshBuilder.cs index 9381b81..fef9a98 100644 --- a/src/DotRecast.Detour/DtNavMeshBuilder.cs +++ b/src/DotRecast.Detour/DtNavMeshBuilder.cs @@ -158,8 +158,8 @@ namespace DotRecast.Detour int vb = option.detailMeshes[i * 4 + 0]; int ndv = option.detailMeshes[i * 4 + 1]; int dv = vb * 3; - var bmin = new RcVec3f(option.detailVerts.AsSpan(dv)); - var bmax = new RcVec3f(option.detailVerts.AsSpan(dv)); + var bmin = RcVecUtils.Create(option.detailVerts, dv); + var bmax = RcVecUtils.Create(option.detailVerts, dv); for (int j = 1; j < ndv; j++) { bmin = RcVecUtils.Min(bmin, option.detailVerts, dv + j * 3); @@ -315,8 +315,8 @@ namespace DotRecast.Detour for (int i = 0; i < option.offMeshConCount; ++i) { - var p0 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 0) * 3)); - var p1 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 1) * 3)); + var p0 = RcVecUtils.Create(option.offMeshConVerts, (i * 2 + 0) * 3); + var p1 = RcVecUtils.Create(option.offMeshConVerts, (i * 2 + 1) * 3); offMeshConClass[i * 2 + 0] = ClassifyOffMeshPoint(p0, bmin, bmax); offMeshConClass[i * 2 + 1] = ClassifyOffMeshPoint(p1, bmin, bmax); diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 7bfa234..e5f26b6 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -641,8 +641,8 @@ namespace DotRecast.Detour // Calc polygon bounds. int v = p.verts[0] * 3; - bmin = new RcVec3f(tile.data.verts.AsSpan(v)); - bmax = new RcVec3f(tile.data.verts.AsSpan(v)); + bmin = RcVecUtils.Create(tile.data.verts, v); + bmax = RcVecUtils.Create(tile.data.verts, v); for (int j = 1; j < p.vertCount; ++j) { v = p.verts[j] * 3; @@ -2202,7 +2202,7 @@ namespace DotRecast.Detour int nv = 0; for (int i = 0; i < poly.vertCount; ++i) { - verts[nv] = new RcVec3f(tile.data.verts.AsSpan(poly.verts[i] * 3)); + verts[nv] = RcVecUtils.Create(tile.data.verts, poly.verts[i] * 3); nv++; } @@ -3031,8 +3031,8 @@ namespace DotRecast.Detour int ivj = poly.verts[j] * 3; int ivi = poly.verts[i] * 3; var seg = new RcSegmentVert(); - seg.vmin = new RcVec3f(tile.data.verts.AsSpan(ivj)); - seg.vmax = new RcVec3f(tile.data.verts.AsSpan(ivi)); + seg.vmin = RcVecUtils.Create(tile.data.verts, ivj); + seg.vmax = RcVecUtils.Create(tile.data.verts, ivi); // Array.Copy(tile.data.verts, ivj, seg, 0, 3); // Array.Copy(tile.data.verts, ivi, seg, 3, 3); segmentVerts.Add(seg); @@ -3212,8 +3212,8 @@ namespace DotRecast.Detour hitPos.Y = bestTile.data.verts[vj + 1] + (bestTile.data.verts[vi + 1] - bestTile.data.verts[vj + 1]) * tseg; hitPos.Z = bestTile.data.verts[vj + 2] + (bestTile.data.verts[vi + 2] - bestTile.data.verts[vj + 2]) * tseg; hasBestV = true; - bestvj = new RcVec3f(bestTile.data.verts.AsSpan(vj)); - bestvi = new RcVec3f(bestTile.data.verts.AsSpan(vi)); + bestvj = RcVecUtils.Create(bestTile.data.verts, vj); + bestvi = RcVecUtils.Create(bestTile.data.verts, vi); } for (int i = bestTile.polyLinks[bestPoly.index]; i != DtNavMesh.DT_NULL_LINK; i = bestTile.links[i].next) diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index 3fc81f3..894710b 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -309,8 +309,8 @@ namespace DotRecast.Detour public static float DistancePtSegSqr2D(RcVec3f pt, float[] verts, int p, int q, out float t) { - var vp = new RcVec3f(verts.AsSpan(p)); - var vq = new RcVec3f(verts.AsSpan(q)); + var vp = RcVecUtils.Create(verts, p); + var vq = RcVecUtils.Create(verts, q); return DistancePtSegSqr2D(pt, vp, vq, out t); } diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs index a6b7bef..e33ec2c 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs @@ -234,7 +234,7 @@ public class CrowdSampleTool : ISampleTool dd.Vertex(prev.X, prev.Y + 0.1f, prev.Z, DuRGBA(0, 0, 0, (int)(128 * preva))); dd.Vertex(trail.trail[v], trail.trail[v + 1] + 0.1f, trail.trail[v + 2], DuRGBA(0, 0, 0, (int)(128 * a))); preva = a; - prev = new RcVec3f(trail.trail.AsSpan(v)); + prev = RcVecUtils.Create(trail.trail, v); } dd.End(); diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 6eb11c7..a7f782c 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -57,8 +57,8 @@ namespace DotRecast.Recast.Toolset.Geom this.faces = faces; normals = new float[faces.Length]; CalculateNormals(); - bmin = new RcVec3f(vertices); - bmax = new RcVec3f(vertices); + bmin = RcVecUtils.Create(vertices); + bmax = RcVecUtils.Create(vertices); for (int i = 1; i < vertices.Length / 3; i++) { bmin = RcVecUtils.Min(bmin, vertices, i * 3); diff --git a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs index 33f04c4..ec08dd2 100644 --- a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs +++ b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs @@ -77,8 +77,8 @@ namespace DotRecast.Recast.Geom this.faces = faces; normals = new float[faces.Length]; CalculateNormals(); - bmin = new RcVec3f(vertices); - bmax = new RcVec3f(vertices); + bmin = RcVecUtils.Create(vertices); + bmax = RcVecUtils.Create(vertices); for (int i = 1; i < vertices.Length / 3; i++) { bmin = RcVecUtils.Min(bmin, vertices, i * 3); diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index c8cdc68..9991f60 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -457,8 +457,8 @@ namespace DotRecast.Recast int zStride = xSize; // For readability // Compute the bounding box of the polygon - RcVec3f bmin = new RcVec3f(verts); - RcVec3f bmax = new RcVec3f(verts); + RcVec3f bmin = RcVecUtils.Create(verts); + RcVec3f bmax = RcVecUtils.Create(verts); for (int i = 3; i < verts.Length; i += 3) { bmin = RcVecUtils.Min(bmin, verts, i); @@ -753,9 +753,9 @@ namespace DotRecast.Recast int vertIndexB = vertIndex; int vertIndexC = (vertIndex + 1) % numVerts; - RcVec3f vertA = new RcVec3f(verts.AsSpan(vertIndexA * 3)); - RcVec3f vertB = new RcVec3f(verts.AsSpan(vertIndexB * 3)); - RcVec3f vertC = new RcVec3f(verts.AsSpan(vertIndexC * 3)); + RcVec3f vertA = RcVecUtils.Create(verts, vertIndexA * 3); + RcVec3f vertB = RcVecUtils.Create(verts, vertIndexB * 3); + RcVec3f vertC = RcVecUtils.Create(verts, vertIndexC * 3); // From A to B on the x/z plane RcVec3f prevSegmentDir = RcVec3f.Subtract(vertB, vertA); diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index f772096..5ad3106 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -178,7 +178,7 @@ namespace DotRecast.Recast return true; } - c = new RcVec3f(verts.AsSpan(p1)); + c = RcVecUtils.Create(verts, p1); r.Exchange(0f); return false; } @@ -1000,8 +1000,8 @@ namespace DotRecast.Recast if (sampleDist > 0) { // Create sample locations in a grid. - RcVec3f bmin = new RcVec3f(@in); - RcVec3f bmax = new RcVec3f(@in); + RcVec3f bmin = RcVecUtils.Create(@in); + RcVec3f bmax = RcVecUtils.Create(@in); for (int i = 1; i < nin; ++i) { bmin = RcVecUtils.Min(bmin, @in, i * 3); diff --git a/src/DotRecast.Recast/RcRasterizations.cs b/src/DotRecast.Recast/RcRasterizations.cs index df5fb2f..8c2a864 100644 --- a/src/DotRecast.Recast/RcRasterizations.cs +++ b/src/DotRecast.Recast/RcRasterizations.cs @@ -237,8 +237,8 @@ namespace DotRecast.Recast float by = heightfieldBBMax.Y - heightfieldBBMin.Y; // Calculate the bounding box of the triangle. - RcVec3f tmin = new RcVec3f(verts.AsSpan(v0 * 3)); - RcVec3f tmax = new RcVec3f(verts.AsSpan(v0 * 3)); + RcVec3f tmin = RcVecUtils.Create(verts, v0 * 3); + RcVec3f tmax = RcVecUtils.Create(verts, v0 * 3); tmin = RcVecUtils.Min(tmin, verts, v1 * 3); tmin = RcVecUtils.Min(tmin, verts, v2 * 3); tmax = RcVecUtils.Max(tmax, verts, v1 * 3);