remove new int[2] in CalcTileCount()

This commit is contained in:
ikpil 2023-06-01 22:25:15 +09:00
parent a96f582a54
commit e87d1f9635
5 changed files with 12 additions and 21 deletions

View File

@ -53,12 +53,11 @@ namespace DotRecast.Recast
} }
public static int[] CalcTileCount(Vector3f bmin, Vector3f bmax, float cs, int tileSizeX, int tileSizeZ) public static void CalcTileCount(Vector3f bmin, Vector3f bmax, float cs, int tileSizeX, int tileSizeZ, out int tw, out int td)
{ {
CalcGridSize(bmin, bmax, cs, out var gw, out var gd); CalcGridSize(bmin, bmax, cs, out var gw, out var gd);
int tw = (gw + tileSizeX - 1) / tileSizeX; tw = (gw + tileSizeX - 1) / tileSizeX;
int td = (gd + tileSizeZ - 1) / tileSizeZ; td = (gd + tileSizeZ - 1) / tileSizeZ;
return new int[] { tw, td };
} }
/// @par /// @par

View File

@ -45,9 +45,7 @@ namespace DotRecast.Recast
{ {
Vector3f bmin = geom.GetMeshBoundsMin(); Vector3f bmin = geom.GetMeshBoundsMin();
Vector3f bmax = geom.GetMeshBoundsMax(); Vector3f bmax = geom.GetMeshBoundsMax();
int[] twh = Recast.CalcTileCount(bmin, bmax, cfg.cs, cfg.tileSizeX, cfg.tileSizeZ); Recast.CalcTileCount(bmin, bmax, cfg.cs, cfg.tileSizeX, cfg.tileSizeZ, out var tw, out var th);
int tw = twh[0];
int th = twh[1];
List<RecastBuilderResult> results = new List<RecastBuilderResult>(); List<RecastBuilderResult> results = new List<RecastBuilderResult>();
if (null != taskFactory) if (null != taskFactory)
{ {
@ -66,9 +64,7 @@ namespace DotRecast.Recast
{ {
Vector3f bmin = geom.GetMeshBoundsMin(); Vector3f bmin = geom.GetMeshBoundsMin();
Vector3f bmax = geom.GetMeshBoundsMax(); Vector3f bmax = geom.GetMeshBoundsMax();
int[] twh = Recast.CalcTileCount(bmin, bmax, cfg.cs, cfg.tileSizeX, cfg.tileSizeZ); Recast.CalcTileCount(bmin, bmax, cfg.cs, cfg.tileSizeX, cfg.tileSizeZ, out var tw, out var th);
int tw = twh[0];
int th = twh[1];
Task task; Task task;
if (1 < threads) if (1 < threads)
{ {

View File

@ -69,9 +69,7 @@ public class MeshSetReaderWriterTest
Vector3f bmin = geom.GetMeshBoundsMin(); Vector3f bmin = geom.GetMeshBoundsMin();
Vector3f bmax = geom.GetMeshBoundsMax(); Vector3f bmax = geom.GetMeshBoundsMax();
int[] twh = Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize); Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out var tw, out var th);
int tw = twh[0];
int th = twh[1];
for (int y = 0; y < th; ++y) for (int y = 0; y < th; ++y)
{ {
for (int x = 0; x < tw; ++x) for (int x = 0; x < tw; ++x)
@ -119,4 +117,4 @@ public class MeshSetReaderWriterTest
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(5)); Assert.That(tiles[0].data.polys.Length, Is.EqualTo(5));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(17 * 3)); Assert.That(tiles[0].data.verts.Length, Is.EqualTo(17 * 3));
} }
} }

View File

@ -53,7 +53,7 @@ public class AbstractTileCacheTest
public TileCache GetTileCache(IInputGeomProvider geom, RcByteOrder order, bool cCompatibility) public TileCache GetTileCache(IInputGeomProvider geom, RcByteOrder order, bool cCompatibility)
{ {
TileCacheParams option = new TileCacheParams(); TileCacheParams option = new TileCacheParams();
int[] twh = Recast.Recast.CalcTileCount(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), m_cellSize, m_tileSize, m_tileSize); Recast.Recast.CalcTileCount(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), m_cellSize, m_tileSize, m_tileSize, out var tw, out var th);
option.ch = m_cellHeight; option.ch = m_cellHeight;
option.cs = m_cellSize; option.cs = m_cellSize;
option.orig = geom.GetMeshBoundsMin(); option.orig = geom.GetMeshBoundsMin();
@ -63,7 +63,7 @@ public class AbstractTileCacheTest
option.walkableRadius = m_agentRadius; option.walkableRadius = m_agentRadius;
option.walkableClimb = m_agentMaxClimb; option.walkableClimb = m_agentMaxClimb;
option.maxSimplificationError = m_edgeMaxError; option.maxSimplificationError = m_edgeMaxError;
option.maxTiles = twh[0] * twh[1] * EXPECTED_LAYERS_PER_TILE; option.maxTiles = tw * th * EXPECTED_LAYERS_PER_TILE;
option.maxObstacles = 128; option.maxObstacles = 128;
NavMeshParams navMeshParams = new NavMeshParams(); NavMeshParams navMeshParams = new NavMeshParams();
navMeshParams.orig = geom.GetMeshBoundsMin(); navMeshParams.orig = geom.GetMeshBoundsMin();
@ -76,4 +76,4 @@ public class AbstractTileCacheTest
TileCacheCompressorFactory.Get(cCompatibility), new TestTileCacheMeshProcess()); TileCacheCompressorFactory.Get(cCompatibility), new TestTileCacheMeshProcess());
return tc; return tc;
} }
} }

View File

@ -57,9 +57,7 @@ public class TestTileLayerBuilder : AbstractTileLayersBuilder
true, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND); true, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
Vector3f bmin = geom.GetMeshBoundsMin(); Vector3f bmin = geom.GetMeshBoundsMin();
Vector3f bmax = geom.GetMeshBoundsMax(); Vector3f bmax = geom.GetMeshBoundsMax();
int[] twh = Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize); Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out tw, out th);
tw = twh[0];
th = twh[1];
} }
public List<byte[]> Build(RcByteOrder order, bool cCompatibility, int threads) public List<byte[]> Build(RcByteOrder order, bool cCompatibility, int threads)
@ -125,4 +123,4 @@ public class TestTileLayerBuilder : AbstractTileLayersBuilder
HeightfieldLayerSet lset = rcBuilder.BuildLayers(geom, cfg); HeightfieldLayerSet lset = rcBuilder.BuildLayers(geom, cfg);
return lset; return lset;
} }
} }