upgrade tile build performacne

This commit is contained in:
ikpil 2023-04-05 17:30:18 +09:00
parent 62d23e34ab
commit d84f78352d
4 changed files with 59 additions and 92 deletions

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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<BoundsItem>
{
public int Compare(BoundsItem a, BoundsItem b)
{
return a.bmin[0].CompareTo(b.bmin[0]);
}
}
private class CompareItemY : IComparer<BoundsItem>
{
public int Compare(BoundsItem a, BoundsItem b)
{
return a.bmin[1].CompareTo(b.bmin[1]);
}
}
List<ChunkyTriMeshNode> 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];
}

View File

@ -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<BoundsItem>
{
public int Compare(BoundsItem a, BoundsItem b)
{
return a.bmin.x.CompareTo(b.bmin.x);
}
}
public class CompareItemY : IComparer<BoundsItem>
{
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<BoundsItem>
{
public int Compare(BoundsItem a, BoundsItem b)
{
return a.bmin[0].CompareTo(b.bmin[0]);
}
}
private class CompareItemY : IComparer<BoundsItem>
{
public int Compare(BoundsItem a, BoundsItem b)
{
return a.bmin[1].CompareTo(b.bmin[1]);
}
}
List<ChunkyTriMeshNode> 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];
}