From d84f78352dce3e1a1750c37200a0bc824ee05e1e Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 5 Apr 2023 17:30:18 +0900 Subject: [PATCH] upgrade tile build performacne --- src/DotRecast.Core/Vector2f.cs | 11 --- .../Jumplink/EdgeSamplerFactory.cs | 6 +- .../Geom/ChunkyTriMesh.cs | 55 ++++--------- src/DotRecast.Recast/Geom/ChunkyTriMesh.cs | 79 ++++++++++--------- 4 files changed, 59 insertions(+), 92 deletions(-) diff --git a/src/DotRecast.Core/Vector2f.cs b/src/DotRecast.Core/Vector2f.cs index 80e5cc3..e743569 100644 --- a/src/DotRecast.Core/Vector2f.cs +++ b/src/DotRecast.Core/Vector2f.cs @@ -9,20 +9,9 @@ namespace DotRecast.Core public float this[int index] { - get => GetElement(index); set => SetElement(index, value); } - public float GetElement(int index) - { - switch (index) - { - case 0: return x; - case 1: return y; - default: throw new IndexOutOfRangeException($"{index}"); - } - } - public void SetElement(int index, float value) { switch (index) diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs index 78735f8..d83ba6d 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs @@ -95,9 +95,9 @@ namespace DotRecast.Detour.Extras.Jumplink private void trans2d(ref Vector3f dst, Vector3f ax, Vector3f ay, Vector2f pt) { - dst[0] = ax[0] * pt[0] + ay[0] * pt[1]; - dst[1] = ax[1] * pt[0] + ay[1] * pt[1]; - dst[2] = ax[2] * pt[0] + ay[2] * pt[1]; + dst[0] = ax[0] * pt.x + ay[0] * pt.y; + dst[1] = ax[1] * pt.x + ay[1] * pt.y; + dst[2] = ax[2] * pt.x + ay[2] * pt.y; } } diff --git a/src/DotRecast.Recast.Demo/Geom/ChunkyTriMesh.cs b/src/DotRecast.Recast.Demo/Geom/ChunkyTriMesh.cs index c8b9778..c39fe57 100644 --- a/src/DotRecast.Recast.Demo/Geom/ChunkyTriMesh.cs +++ b/src/DotRecast.Recast.Demo/Geom/ChunkyTriMesh.cs @@ -26,62 +26,39 @@ namespace DotRecast.Recast.Demo.Geom; public class ChunkyTriMesh { - private class BoundsItem - { - public readonly float[] bmin = new float[2]; - public readonly float[] bmax = new float[2]; - public int i; - } - - private class CompareItemX : IComparer - { - public int Compare(BoundsItem a, BoundsItem b) - { - return a.bmin[0].CompareTo(b.bmin[0]); - } - } - - private class CompareItemY : IComparer - { - public int Compare(BoundsItem a, BoundsItem b) - { - return a.bmin[1].CompareTo(b.bmin[1]); - } - } - List nodes; int ntris; int maxTrisPerChunk; private void calcExtends(BoundsItem[] items, int imin, int imax, float[] bmin, float[] bmax) { - bmin[0] = items[imin].bmin[0]; - bmin[1] = items[imin].bmin[1]; + bmin[0] = items[imin].bmin.x; + bmin[1] = items[imin].bmin.y; - bmax[0] = items[imin].bmax[0]; - bmax[1] = items[imin].bmax[1]; + bmax[0] = items[imin].bmax.x; + bmax[1] = items[imin].bmax.y; for (int i = imin + 1; i < imax; ++i) { BoundsItem it = items[i]; - if (it.bmin[0] < bmin[0]) + if (it.bmin.x < bmin[0]) { - bmin[0] = it.bmin[0]; + bmin[0] = it.bmin.x; } - if (it.bmin[1] < bmin[1]) + if (it.bmin.y < bmin[1]) { - bmin[1] = it.bmin[1]; + bmin[1] = it.bmin.y; } - if (it.bmax[0] > bmax[0]) + if (it.bmax.x > bmax[0]) { - bmax[0] = it.bmax[0]; + bmax[0] = it.bmax.x; } - if (it.bmax[1] > bmax[1]) + if (it.bmax.y > bmax[1]) { - bmax[1] = it.bmax[1]; + bmax[1] = it.bmax.y; } } } @@ -168,22 +145,22 @@ public class ChunkyTriMesh for (int j = 1; j < 3; ++j) { int v = tris[t + j] * 3; - if (verts[v] < it.bmin[0]) + if (verts[v] < it.bmin.x) { it.bmin[0] = verts[v]; } - if (verts[v + 2] < it.bmin[1]) + if (verts[v + 2] < it.bmin.y) { it.bmin[1] = verts[v + 2]; } - if (verts[v] > it.bmax[0]) + if (verts[v] > it.bmax.x) { it.bmax[0] = verts[v]; } - if (verts[v + 2] > it.bmax[1]) + if (verts[v + 2] > it.bmax.y) { it.bmax[1] = verts[v + 2]; } diff --git a/src/DotRecast.Recast/Geom/ChunkyTriMesh.cs b/src/DotRecast.Recast/Geom/ChunkyTriMesh.cs index 3b9e130..ed432c5 100644 --- a/src/DotRecast.Recast/Geom/ChunkyTriMesh.cs +++ b/src/DotRecast.Recast/Geom/ChunkyTriMesh.cs @@ -20,67 +20,68 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; +using DotRecast.Core; namespace DotRecast.Recast.Geom { + public class BoundsItem + { + public Vector2f bmin; + public Vector2f bmax; + public int i; + } + + public class CompareItemX : IComparer + { + public int Compare(BoundsItem a, BoundsItem b) + { + return a.bmin.x.CompareTo(b.bmin.x); + } + } + + public class CompareItemY : IComparer + { + public int Compare(BoundsItem a, BoundsItem b) + { + return a.bmin.y.CompareTo(b.bmin.y); + } + } + public class ChunkyTriMesh { - private class BoundsItem - { - public readonly float[] bmin = new float[2]; - public readonly float[] bmax = new float[2]; - public int i; - } - - private class CompareItemX : IComparer - { - public int Compare(BoundsItem a, BoundsItem b) - { - return a.bmin[0].CompareTo(b.bmin[0]); - } - } - - private class CompareItemY : IComparer - { - public int Compare(BoundsItem a, BoundsItem b) - { - return a.bmin[1].CompareTo(b.bmin[1]); - } - } - List nodes; int ntris; int maxTrisPerChunk; private void calcExtends(BoundsItem[] items, int imin, int imax, float[] bmin, float[] bmax) { - bmin[0] = items[imin].bmin[0]; - bmin[1] = items[imin].bmin[1]; + bmin[0] = items[imin].bmin.x; + bmin[1] = items[imin].bmin.y; - bmax[0] = items[imin].bmax[0]; - bmax[1] = items[imin].bmax[1]; + bmax[0] = items[imin].bmax.x; + bmax[1] = items[imin].bmax.y; for (int i = imin + 1; i < imax; ++i) { BoundsItem it = items[i]; - if (it.bmin[0] < bmin[0]) + if (it.bmin.x < bmin[0]) { - bmin[0] = it.bmin[0]; + bmin[0] = it.bmin.x; } - if (it.bmin[1] < bmin[1]) + if (it.bmin.y < bmin[1]) { - bmin[1] = it.bmin[1]; + bmin[1] = it.bmin.y; } - if (it.bmax[0] > bmax[0]) + if (it.bmax.x > bmax[0]) { - bmax[0] = it.bmax[0]; + bmax[0] = it.bmax.x; } - if (it.bmax[1] > bmax[1]) + if (it.bmax.y > bmax[1]) { - bmax[1] = it.bmax[1]; + bmax[1] = it.bmax.y; } } } @@ -167,22 +168,22 @@ namespace DotRecast.Recast.Geom for (int j = 1; j < 3; ++j) { int v = tris[t + j] * 3; - if (verts[v] < it.bmin[0]) + if (verts[v] < it.bmin.x) { it.bmin[0] = verts[v]; } - if (verts[v + 2] < it.bmin[1]) + if (verts[v + 2] < it.bmin.y) { it.bmin[1] = verts[v + 2]; } - if (verts[v] > it.bmax[0]) + if (verts[v] > it.bmax.x) { it.bmax[0] = verts[v]; } - if (verts[v + 2] > it.bmax[1]) + if (verts[v + 2] > it.bmax.y) { it.bmax[1] = verts[v + 2]; }