From 34f38fc8742399bd5f27e35fd1d5aa82c2d4324e Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 5 Oct 2023 23:35:18 +0900 Subject: [PATCH] refactoring: typo --- .../{Intersections.cs => RcIntersections.cs} | 2 +- src/DotRecast.Core/RcMatrix4x4f.cs | 4 ++++ src/DotRecast.Core/{FRand.cs => RcRand.cs} | 6 +++--- src/DotRecast.Core/RcVec3f.cs | 19 +++++++++++-------- src/DotRecast.Detour.Crowd/DtPathCorridor.cs | 8 ++++---- .../{PolyUtils.cs => DtPolyUtils.cs} | 10 +++------- .../Unity/Astar/LinkBuilder.cs | 10 +++++----- src/DotRecast.Detour/DtNavMeshRaycast.cs | 2 +- .../{PathUtils.cs => DtPathUtils.cs} | 2 +- .../Geom/DemoInputGeomProvider.cs | 4 ++-- .../Tools/RcCrowdAgentProfilingTool.cs | 4 ++-- .../Tools/RcCrowdTool.cs | 2 +- .../Tools/RcObstacleTool.cs | 2 +- .../Tools/RcTestNavMeshTool.cs | 12 ++++++------ src/DotRecast.Recast/RcPolyMeshRaycast.cs | 2 +- test/DotRecast.Detour.Test/RandomPointTest.cs | 8 ++++---- 16 files changed, 50 insertions(+), 47 deletions(-) rename src/DotRecast.Core/{Intersections.cs => RcIntersections.cs} (99%) rename src/DotRecast.Core/{FRand.cs => RcRand.cs} (78%) rename src/DotRecast.Detour.Extras/{PolyUtils.cs => DtPolyUtils.cs} (95%) rename src/DotRecast.Detour/{PathUtils.cs => DtPathUtils.cs} (99%) diff --git a/src/DotRecast.Core/Intersections.cs b/src/DotRecast.Core/RcIntersections.cs similarity index 99% rename from src/DotRecast.Core/Intersections.cs rename to src/DotRecast.Core/RcIntersections.cs index 27536a8..bfe0b59 100644 --- a/src/DotRecast.Core/Intersections.cs +++ b/src/DotRecast.Core/RcIntersections.cs @@ -22,7 +22,7 @@ using System; 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) { diff --git a/src/DotRecast.Core/RcMatrix4x4f.cs b/src/DotRecast.Core/RcMatrix4x4f.cs index 65f90f0..a6287a9 100644 --- a/src/DotRecast.Core/RcMatrix4x4f.cs +++ b/src/DotRecast.Core/RcMatrix4x4f.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace DotRecast.Core { @@ -107,6 +108,7 @@ namespace DotRecast.Core 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; @@ -147,6 +149,7 @@ namespace DotRecast.Core 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]; @@ -174,6 +177,7 @@ namespace DotRecast.Core ); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RcMatrix4x4f CreateFromRotate(float a, float x, float y, float z) { var matrix = new RcMatrix4x4f(); diff --git a/src/DotRecast.Core/FRand.cs b/src/DotRecast.Core/RcRand.cs similarity index 78% rename from src/DotRecast.Core/FRand.cs rename to src/DotRecast.Core/RcRand.cs index c57c563..c1fc36b 100644 --- a/src/DotRecast.Core/FRand.cs +++ b/src/DotRecast.Core/RcRand.cs @@ -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 : 랜덤 시드 확인 필요 } diff --git a/src/DotRecast.Core/RcVec3f.cs b/src/DotRecast.Core/RcVec3f.cs index 9092892..1c1d4f0 100644 --- a/src/DotRecast.Core/RcVec3f.cs +++ b/src/DotRecast.Core/RcVec3f.cs @@ -554,11 +554,13 @@ namespace DotRecast.Core } + [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]; @@ -566,6 +568,7 @@ namespace DotRecast.Core @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]; @@ -573,6 +576,7 @@ namespace DotRecast.Core @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]; @@ -580,6 +584,7 @@ namespace DotRecast.Core @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]; @@ -588,6 +593,7 @@ namespace DotRecast.Core } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Sub(ref RcVec3f e0, float[] verts, int i, int j) { e0.x = verts[i] - verts[j]; @@ -596,6 +602,7 @@ namespace DotRecast.Core } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Sub(ref RcVec3f e0, RcVec3f i, float[] verts, int j) { e0.x = i.x - verts[j]; @@ -604,6 +611,7 @@ namespace DotRecast.Core } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Cross(float[] dest, float[] v1, float[] v2) { dest[0] = v1[1] * v2[2] - v1[2] * v2[1]; @@ -611,6 +619,7 @@ namespace DotRecast.Core 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; @@ -618,6 +627,7 @@ namespace DotRecast.Core 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; @@ -626,14 +636,7 @@ namespace DotRecast.Core } - 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)); diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 3816862..9166541 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -201,7 +201,7 @@ namespace DotRecast.Detour.Crowd { 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); } } } @@ -236,7 +236,7 @@ namespace DotRecast.Detour.Crowd if (status.Succeeded() && res.Count > 0) { - m_path = PathUtils.MergeCorridorStartShortcut(m_path, res); + m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, res); return true; } @@ -307,7 +307,7 @@ namespace DotRecast.Detour.Crowd 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; @@ -347,7 +347,7 @@ namespace DotRecast.Detour.Crowd 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. /* diff --git a/src/DotRecast.Detour.Extras/PolyUtils.cs b/src/DotRecast.Detour.Extras/DtPolyUtils.cs similarity index 95% rename from src/DotRecast.Detour.Extras/PolyUtils.cs rename to src/DotRecast.Detour.Extras/DtPolyUtils.cs index 37f18a5..53b581b 100644 --- a/src/DotRecast.Detour.Extras/PolyUtils.cs +++ b/src/DotRecast.Detour.Extras/DtPolyUtils.cs @@ -18,11 +18,9 @@ freely, subject to the following restrictions: 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 @@ -73,9 +71,7 @@ namespace DotRecast.Detour.Extras 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; diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs b/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs index 8dad5eb..1107dc6 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs @@ -49,7 +49,7 @@ namespace DotRecast.Detour.Extras.Unity.Astar 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; @@ -65,19 +65,19 @@ namespace DotRecast.Detour.Extras.Unity.Astar { 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; } } } diff --git a/src/DotRecast.Detour/DtNavMeshRaycast.cs b/src/DotRecast.Detour/DtNavMeshRaycast.cs index f46a76c..869efdb 100644 --- a/src/DotRecast.Detour/DtNavMeshRaycast.cs +++ b/src/DotRecast.Detour/DtNavMeshRaycast.cs @@ -80,7 +80,7 @@ namespace DotRecast.Detour } } - if (Intersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out hitTime)) + if (RcIntersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out hitTime)) { return true; } diff --git a/src/DotRecast.Detour/PathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs similarity index 99% rename from src/DotRecast.Detour/PathUtils.cs rename to src/DotRecast.Detour/DtPathUtils.cs index c819947..5243135 100644 --- a/src/DotRecast.Detour/PathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -24,7 +24,7 @@ using DotRecast.Core; namespace DotRecast.Detour { - public static class PathUtils + public static class DtPathUtils { private const int MAX_STEER_POINTS = 3; diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 56ae2f2..d9e3313 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -143,7 +143,7 @@ namespace DotRecast.Recast.Toolset.Geom tmin = 1.0f; // Prune hit ray. - if (!Intersections.IsectSegAABB(src, dst, bmin, bmax, out var btmin, out var btmax)) + if (!RcIntersections.IsectSegAABB(src, dst, bmin, bmax, out var btmin, out var btmax)) { return false; } @@ -183,7 +183,7 @@ namespace DotRecast.Recast.Toolset.Geom vertices[tris[j + 2] * 3 + 1], vertices[tris[j + 2] * 3 + 2] ); - if (Intersections.IntersectSegmentTriangle(src, dst, v1, v2, v3, out var t)) + if (RcIntersections.IntersectSegmentTriangle(src, dst, v1, v2, v3, out var t)) { if (t < tmin) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs index 556e3b5..a975e4c 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs @@ -17,7 +17,7 @@ namespace DotRecast.Recast.Toolset.Tools private DtNavMesh navMesh; - private FRand rnd; + private RcRand rnd; private readonly List _polyPoints; private long crowdUpdateTime; @@ -162,7 +162,7 @@ namespace DotRecast.Recast.Toolset.Tools if (null == navMesh) return; - rnd = new FRand(_cfg.randomSeed); + rnd = new RcRand(_cfg.randomSeed); CreateCrowd(); CreateZones(); DtNavMeshQuery navquery = new DtNavMeshQuery(navMesh); diff --git a/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs index ee48eff..9124726 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs @@ -222,7 +222,7 @@ namespace DotRecast.Recast.Toolset.Tools RcVec3f bmin = new RcVec3f(); RcVec3f bmax = new RcVec3f(); GetAgentBounds(ag, ref bmin, ref bmax); - if (Intersections.IsectSegAABB(s, p, bmin, bmax, out var tmin, out var tmax)) + if (RcIntersections.IsectSegAABB(s, p, bmin, bmax, out var tmin, out var tmax)) { if (tmin > 0 && tmin < tsel) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs index 592db77..39df464 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs @@ -162,7 +162,7 @@ namespace DotRecast.Recast.Toolset.Tools RcVec3f bmax = RcVec3f.Zero; _tc.GetObstacleBounds(ob, ref bmin, ref bmax); - if (Intersections.IsectSegAABB(sp, sq, bmin, bmax, out var t0, out var t1)) + if (RcIntersections.IsectSegAABB(sp, sq, bmin, bmax, out var t0, out var t1)) { if (t0 < tmin) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 2131e66..f08511c 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -58,7 +58,7 @@ namespace DotRecast.Recast.Toolset.Tools while (0 < polys.Count && smoothPath.Count < MAX_SMOOTH) { // Find location to steer towards. - if (!PathUtils.GetSteerTarget(navQuery, iterPos, targetPos, SLOP, + if (!DtPathUtils.GetSteerTarget(navQuery, iterPos, targetPos, SLOP, polys, out var steerPos, out var steerPosFlag, out var steerPosRef)) { break; @@ -91,8 +91,8 @@ namespace DotRecast.Recast.Toolset.Tools iterPos = result; - polys = PathUtils.MergeCorridorStartMoved(polys, visited); - polys = PathUtils.FixupShortcuts(polys, navQuery); + polys = DtPathUtils.MergeCorridorStartMoved(polys, visited); + polys = DtPathUtils.FixupShortcuts(polys, navQuery); var status = navQuery.GetPolyHeight(polys[0], result, out var h); if (status.Succeeded()) @@ -101,7 +101,7 @@ namespace DotRecast.Recast.Toolset.Tools } // Handle end of path and off-mesh links when close enough. - if (endOfPath && PathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) + if (endOfPath && DtPathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached end of path. iterPos = targetPos; @@ -112,7 +112,7 @@ namespace DotRecast.Recast.Toolset.Tools break; } - else if (offMeshConnection && PathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) + else if (offMeshConnection && DtPathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached off-mesh connection. RcVec3f startPos = RcVec3f.Zero; @@ -422,7 +422,7 @@ namespace DotRecast.Recast.Toolset.Tools ? DtStrictDtPolygonByCircleConstraint.Shared : DtNoOpDtPolygonByCircleConstraint.Shared; - var frand = new FRand(); + var frand = new RcRand(); int prevCnt = points.Count; points = new List(); diff --git a/src/DotRecast.Recast/RcPolyMeshRaycast.cs b/src/DotRecast.Recast/RcPolyMeshRaycast.cs index f959029..fdab28e 100644 --- a/src/DotRecast.Recast/RcPolyMeshRaycast.cs +++ b/src/DotRecast.Recast/RcPolyMeshRaycast.cs @@ -64,7 +64,7 @@ namespace DotRecast.Recast vs[k].z = meshDetail.verts[verts + meshDetail.tris[tris + j * 4 + k] * 3 + 2]; } - if (Intersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out hitTime)) + if (RcIntersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out hitTime)) { return true; } diff --git a/test/DotRecast.Detour.Test/RandomPointTest.cs b/test/DotRecast.Detour.Test/RandomPointTest.cs index 862b799..3f61c90 100644 --- a/test/DotRecast.Detour.Test/RandomPointTest.cs +++ b/test/DotRecast.Detour.Test/RandomPointTest.cs @@ -31,7 +31,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void TestRandom() { - FRand f = new FRand(1); + RcRand f = new RcRand(1); IDtQueryFilter filter = new DtQueryDefaultFilter(); for (int i = 0; i < 1000; i++) { @@ -60,7 +60,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void TestRandomAroundCircle() { - FRand f = new FRand(1); + RcRand f = new RcRand(1); IDtQueryFilter filter = new DtQueryDefaultFilter(); query.FindRandomPoint(filter, f, out var randomRef, out var randomPt); for (int i = 0; i < 1000; i++) @@ -94,7 +94,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void TestRandomWithinCircle() { - FRand f = new FRand(1); + RcRand f = new RcRand(1); IDtQueryFilter filter = new DtQueryDefaultFilter(); query.FindRandomPoint(filter, f, out var randomRef, out var randomPt); float radius = 5f; @@ -114,7 +114,7 @@ public class RandomPointTest : AbstractDetourTest [Test] public void TestPerformance() { - FRand f = new FRand(1); + RcRand f = new RcRand(1); IDtQueryFilter filter = new DtQueryDefaultFilter(); query.FindRandomPoint(filter, f, out var randomRef, out var randomPt);