From 0368afea23011ade9729c7eda97e949b05bedcf0 Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 18 Oct 2023 23:52:47 +0900 Subject: [PATCH] refactor: preparing for switching build with System.Numerics.Vector3 --- src/DotRecast.Core/Numerics/RcVec3f.cs | 58 ------------------- src/DotRecast.Detour.Crowd/DtCrowd.cs | 6 +- src/DotRecast.Detour.Crowd/DtPathCorridor.cs | 2 +- .../Jumplink/EdgeSampler.cs | 4 +- 4 files changed, 6 insertions(+), 64 deletions(-) diff --git a/src/DotRecast.Core/Numerics/RcVec3f.cs b/src/DotRecast.Core/Numerics/RcVec3f.cs index 86bc87e..230ad8e 100644 --- a/src/DotRecast.Core/Numerics/RcVec3f.cs +++ b/src/DotRecast.Core/Numerics/RcVec3f.cs @@ -95,20 +95,6 @@ namespace DotRecast.Core.Numerics } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Set(float a, float b, float c) - { - X = a; - 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) { @@ -432,24 +418,6 @@ namespace DotRecast.Core.Numerics return dx * dx + dy * dy + dz * dz; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float DistSqr(float[] v, int i, int j) - { - float dx = v[i] - v[j]; - float dy = v[i + 1] - v[j + 1]; - float dz = v[i + 2] - v[j + 2]; - return dx * dx + dy * dy + dz * dz; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float DistSqr(float[] v1, float[] v2) - { - float dx = v2[0] - v1[0]; - float dy = v2[1] - v1[1]; - float dz = v2[2] - v1[2]; - return dx * dx + dy * dy + dz * dz; - } - /// Derives the distance between the specified points on the xz-plane. /// @param[in] v1 A point. [(x, y, z)] /// @param[in] v2 A point. [(x, y, z)] @@ -457,14 +425,6 @@ namespace DotRecast.Core.Numerics /// /// The vectors are projected onto the xz-plane, so the y-values are /// ignored. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dist2D(float[] v1, float[] v2) - { - float dx = v2[0] - v1[0]; - float dz = v2[2] - v1[2]; - return (float)Math.Sqrt(dx * dx + dz * dz); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Dist2D(RcVec3f v1, RcVec3f v2) { @@ -473,15 +433,6 @@ namespace DotRecast.Core.Numerics return (float)Math.Sqrt(dx * dx + dz * dz); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dist2DSqr(float[] v1, float[] v2) - { - float dx = v2[0] - v1[0]; - float dz = v2[2] - v1[2]; - return dx * dx + dz * dz; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Dist2DSqr(RcVec3f v1, RcVec3f v2) { @@ -605,14 +556,6 @@ namespace DotRecast.Core.Numerics 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) { @@ -621,7 +564,6 @@ namespace DotRecast.Core.Numerics dest.Z = v1.X * v2.Y - v1.Y * v2.X; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Normalize(ref RcVec3f v) { diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index e5231bd..a0912a6 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -161,7 +161,7 @@ namespace DotRecast.Detour.Crowd public DtCrowd(DtCrowdConfig config, DtNavMesh nav, Func queryFilterFactory) { _config = config; - _ext.Set(config.maxAgentRadius * 2.0f, config.maxAgentRadius * 1.5f, config.maxAgentRadius * 2.0f); + _ext = new RcVec3f(config.maxAgentRadius * 2.0f, config.maxAgentRadius * 1.5f, config.maxAgentRadius * 2.0f); _obstacleQuery = new DtObstacleAvoidanceQuery(config.maxObstacleAvoidanceCircles, config.maxObstacleAvoidanceSegments); @@ -1240,11 +1240,11 @@ namespace DotRecast.Detour.Crowd // Agents on top of each other, try to choose diverging separation directions. if (idx0 > idx1) { - diff.Set(-ag.dvel.Z, 0, ag.dvel.X); + diff = new RcVec3f(-ag.dvel.Z, 0, ag.dvel.X); } else { - diff.Set(ag.dvel.Z, 0, -ag.dvel.X); + diff = new RcVec3f(ag.dvel.Z, 0, -ag.dvel.X); } pen = 0.01f; diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 5b27d5d..62b009a 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.Set(safePos); + m_pos = new RcVec3f(safePos); m_path.Clear(); m_path.Add(safeRef); } diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs index f97ec55..69662d5 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs @@ -18,9 +18,9 @@ namespace DotRecast.Detour.Extras.Jumplink this.trajectory = trajectory; ax = RcVec3f.Subtract(edge.sq, edge.sp); ax.Normalize(); - az.Set(ax.Z, 0, -ax.X); + az = new RcVec3f(ax.Z, 0, -ax.X); az.Normalize(); - ay.Set(0, 1, 0); + ay = new RcVec3f(0, 1, 0); } } } \ No newline at end of file