From 0af084afb8a3b5b945793fd1997f942d42b9be2d Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 20 May 2023 12:33:51 +0900 Subject: [PATCH] remove VCopy --- src/DotRecast.Core/RcMath.cs | 18 +----------------- src/DotRecast.Core/Vector3f.cs | 15 +++++++++++++++ src/DotRecast.Detour.Crowd/PathCorridor.cs | 4 ++-- src/DotRecast.Detour.Extras/BVTreeBuilder.cs | 6 +++--- .../ConvexConvexIntersection.cs | 8 ++++---- src/DotRecast.Detour/NavMesh.cs | 10 +++++----- src/DotRecast.Detour/NavMeshBuilder.cs | 4 ++-- src/DotRecast.Detour/NavMeshQuery.cs | 8 ++++---- src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 2 +- 9 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/DotRecast.Core/RcMath.cs b/src/DotRecast.Core/RcMath.cs index 4472f3c..f02987c 100644 --- a/src/DotRecast.Core/RcMath.cs +++ b/src/DotRecast.Core/RcMath.cs @@ -119,23 +119,7 @@ namespace DotRecast.Core verts[v1 + 2] + (verts[v2 + 2] - verts[v1 + 2]) * t ); } - - - - public static void VCopy(ref Vector3f @out, float[] @in) - { - @out.x = @in[0]; - @out.y = @in[1]; - @out.z = @in[2]; - } - - public static void VCopy(ref Vector3f @out, float[] @in, int i) - { - @out.x = @in[i]; - @out.y = @in[i + 1]; - @out.z = @in[i + 2]; - } - + public static void VMin(ref Vector3f @out, float[] @in, int i) { @out.x = Math.Min(@out.x, @in[i]); diff --git a/src/DotRecast.Core/Vector3f.cs b/src/DotRecast.Core/Vector3f.cs index a092047..6261448 100644 --- a/src/DotRecast.Core/Vector3f.cs +++ b/src/DotRecast.Core/Vector3f.cs @@ -110,6 +110,21 @@ namespace DotRecast.Core y = b; z = c; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Set(float[] @in) + { + Set(@in, 0); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Set(float[] @in, int i) + { + x = @in[i]; + y = @in[i + 1]; + z = @in[i + 2]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly float Length() diff --git a/src/DotRecast.Detour.Crowd/PathCorridor.cs b/src/DotRecast.Detour.Crowd/PathCorridor.cs index fdada17..d3f72ee 100644 --- a/src/DotRecast.Detour.Crowd/PathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/PathCorridor.cs @@ -528,7 +528,7 @@ namespace DotRecast.Detour.Crowd if (n == 0) { // The first polyref is bad, use current safe values. - VCopy(ref m_pos, safePos); + m_pos.Set(safePos); m_path.Clear(); m_path.Add(safeRef); } @@ -632,4 +632,4 @@ namespace DotRecast.Detour.Crowd return m_path.Count; } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs index a56486d..9e1172f 100644 --- a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs +++ b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs @@ -41,8 +41,8 @@ namespace DotRecast.Detour.Extras it.i = i; Vector3f bmin = new Vector3f(); Vector3f bmax = new Vector3f(); - VCopy(ref bmin, data.verts, data.polys[i].verts[0] * 3); - VCopy(ref bmax, data.verts, data.polys[i].verts[0] * 3); + bmin.Set(data.verts, data.polys[i].verts[0] * 3); + bmax.Set(data.verts, data.polys[i].verts[0] * 3); for (int j = 1; j < data.polys[i].vertCount; j++) { VMin(ref bmin, data.verts, data.polys[i].verts[j] * 3); @@ -60,4 +60,4 @@ namespace DotRecast.Detour.Extras return NavMeshBuilder.Subdivide(items, data.header.polyCount, 0, data.header.polyCount, 0, nodes); } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour/ConvexConvexIntersection.cs b/src/DotRecast.Detour/ConvexConvexIntersection.cs index d41925c..5352bb0 100644 --- a/src/DotRecast.Detour/ConvexConvexIntersection.cs +++ b/src/DotRecast.Detour/ConvexConvexIntersection.cs @@ -54,10 +54,10 @@ namespace DotRecast.Detour do { - VCopy(ref a, p, 3 * (ai % n)); - VCopy(ref b, q, 3 * (bi % m)); - VCopy(ref a1, p, 3 * ((ai + n - 1) % n)); // prev a - VCopy(ref b1, q, 3 * ((bi + m - 1) % m)); // prev b + a.Set(p, 3 * (ai % n)); + b.Set(q, 3 * (bi % m)); + a1.Set(p, 3 * ((ai + n - 1) % n)); // prev a + b1.Set(q, 3 * ((bi + m - 1) % m)); // prev b Vector3f A = a.Subtract(a1); Vector3f B = b.Subtract(b1); diff --git a/src/DotRecast.Detour/NavMesh.cs b/src/DotRecast.Detour/NavMesh.cs index 313ec8a..c36c1a9 100644 --- a/src/DotRecast.Detour/NavMesh.cs +++ b/src/DotRecast.Detour/NavMesh.cs @@ -407,8 +407,8 @@ namespace DotRecast.Detour // Calc polygon bounds. int v = p.verts[0] * 3; - VCopy(ref bmin, tile.data.verts, v); - VCopy(ref bmax, tile.data.verts, v); + bmin.Set(tile.data.verts, v); + bmax.Set(tile.data.verts, v); for (int j = 1; j < p.vertCount; ++j) { v = p.verts[j] * 3; @@ -1575,8 +1575,8 @@ namespace DotRecast.Detour Vector3f startPos = new Vector3f(); Vector3f endPos = new Vector3f(); - VCopy(ref startPos, tile.data.verts, poly.verts[idx0] * 3); - VCopy(ref endPos, tile.data.verts, poly.verts[idx1] * 3); + startPos.Set(tile.data.verts, poly.verts[idx0] * 3); + endPos.Set(tile.data.verts, poly.verts[idx1] * 3); return Results.Success(Tuple.Create(startPos, endPos)); } @@ -1748,4 +1748,4 @@ namespace DotRecast.Detour return tiles; } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour/NavMeshBuilder.cs b/src/DotRecast.Detour/NavMeshBuilder.cs index 0cc24aa..5eeb219 100644 --- a/src/DotRecast.Detour/NavMeshBuilder.cs +++ b/src/DotRecast.Detour/NavMeshBuilder.cs @@ -162,8 +162,8 @@ namespace DotRecast.Detour Vector3f bmin = new Vector3f(); Vector3f bmax = new Vector3f(); int dv = vb * 3; - VCopy(ref bmin, option.detailVerts, dv); - VCopy(ref bmax, option.detailVerts, dv); + bmin.Set(option.detailVerts, dv); + bmax.Set(option.detailVerts, dv); for (int j = 1; j < ndv; j++) { VMin(ref bmin, option.detailVerts, dv + j * 3); diff --git a/src/DotRecast.Detour/NavMeshQuery.cs b/src/DotRecast.Detour/NavMeshQuery.cs index 7682795..452bdd0 100644 --- a/src/DotRecast.Detour/NavMeshQuery.cs +++ b/src/DotRecast.Detour/NavMeshQuery.cs @@ -651,8 +651,8 @@ namespace DotRecast.Detour // Calc polygon bounds. int v = p.verts[0] * 3; - VCopy(ref bmin, tile.data.verts, v); - VCopy(ref bmax, tile.data.verts, v); + bmin.Set(tile.data.verts, v); + bmax.Set(tile.data.verts, v); for (int j = 1; j < p.vertCount; ++j) { v = p.verts[j] * 3; @@ -3099,8 +3099,8 @@ namespace DotRecast.Detour int ivj = poly.verts[j] * 3; int ivi = poly.verts[i] * 3; var seg = new SegmentVert(); - VCopy(ref seg.vmin, tile.data.verts, ivj); - VCopy(ref seg.vmax, tile.data.verts, ivi); + seg.vmin.Set(tile.data.verts, ivj); + seg.vmax.Set(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); diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index 73ed834..e86876d 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -410,7 +410,7 @@ public class CrowdTool : Tool 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; - VCopy(ref prev, trail.trail, v); + prev.Set(trail.trail, v); } dd.End();