2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
|
|
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
2023-03-15 17:00:29 +03:00
|
|
|
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using DotRecast.Core;
|
|
|
|
using DotRecast.Recast;
|
|
|
|
using DotRecast.Recast.Geom;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.TileCache.Test;
|
|
|
|
|
2023-04-25 17:22:44 +03:00
|
|
|
[Parallelizable]
|
2023-03-16 19:48:49 +03:00
|
|
|
public class TileCacheTest : AbstractTileCacheTest
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testFastLz()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
testDungeon(ByteOrder.LITTLE_ENDIAN, false);
|
|
|
|
testDungeon(ByteOrder.LITTLE_ENDIAN, true);
|
|
|
|
testDungeon(ByteOrder.BIG_ENDIAN, false);
|
|
|
|
testDungeon(ByteOrder.BIG_ENDIAN, true);
|
|
|
|
test(ByteOrder.LITTLE_ENDIAN, false);
|
|
|
|
test(ByteOrder.LITTLE_ENDIAN, true);
|
|
|
|
test(ByteOrder.BIG_ENDIAN, false);
|
|
|
|
test(ByteOrder.BIG_ENDIAN, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testLZ4()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
testDungeon(ByteOrder.LITTLE_ENDIAN, false);
|
|
|
|
testDungeon(ByteOrder.LITTLE_ENDIAN, true);
|
|
|
|
testDungeon(ByteOrder.BIG_ENDIAN, false);
|
|
|
|
testDungeon(ByteOrder.BIG_ENDIAN, true);
|
|
|
|
test(ByteOrder.LITTLE_ENDIAN, false);
|
|
|
|
test(ByteOrder.LITTLE_ENDIAN, true);
|
|
|
|
test(ByteOrder.BIG_ENDIAN, false);
|
|
|
|
test(ByteOrder.BIG_ENDIAN, true);
|
|
|
|
}
|
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
private void testDungeon(ByteOrder order, bool cCompatibility)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
InputGeomProvider geom = ObjImporter.load(Loader.ToBytes("dungeon.obj"));
|
|
|
|
TileCache tc = getTileCache(geom, order, cCompatibility);
|
|
|
|
TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom);
|
|
|
|
List<byte[]> layers = layerBuilder.build(order, cCompatibility, 1);
|
|
|
|
int cacheLayerCount = 0;
|
|
|
|
int cacheCompressedSize = 0;
|
|
|
|
int cacheRawSize = 0;
|
2023-03-16 19:48:49 +03:00
|
|
|
foreach (byte[] layer in layers)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long refs = tc.addTile(layer, 0);
|
|
|
|
tc.buildNavMeshTile(refs);
|
|
|
|
cacheLayerCount++;
|
|
|
|
cacheCompressedSize += layer.Length;
|
|
|
|
cacheRawSize += 4 * 48 * 48 + 56; // FIXME
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
Console.WriteLine("Compressor: " + tc.getCompressor().GetType().Name + " C Compatibility: " + cCompatibility
|
2023-03-16 19:48:49 +03:00
|
|
|
+ " Layers: " + cacheLayerCount + " Raw Size: " + cacheRawSize + " Compressed: " + cacheCompressedSize);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tc.getNavMesh().getMaxTiles(), Is.EqualTo(256));
|
|
|
|
Assert.That(tc.getNavMesh().getParams().maxPolys, Is.EqualTo(16384));
|
|
|
|
Assert.That(tc.getNavMesh().getParams().tileWidth, Is.EqualTo(14.4f).Within(0.001f));
|
|
|
|
Assert.That(tc.getNavMesh().getParams().tileHeight, Is.EqualTo(14.4f).Within(0.001f));
|
|
|
|
Assert.That(tc.getNavMesh().getMaxVertsPerPoly(), Is.EqualTo(6));
|
|
|
|
Assert.That(tc.getParams().cs, Is.EqualTo(0.3f));
|
|
|
|
Assert.That(tc.getParams().ch, Is.EqualTo(0.2f));
|
|
|
|
Assert.That(tc.getParams().walkableClimb, Is.EqualTo(0.9f));
|
|
|
|
Assert.That(tc.getParams().walkableHeight, Is.EqualTo(2f));
|
|
|
|
Assert.That(tc.getParams().walkableRadius, Is.EqualTo(0.6f));
|
|
|
|
Assert.That(tc.getParams().width, Is.EqualTo(48));
|
|
|
|
Assert.That(tc.getParams().maxTiles, Is.EqualTo(6 * 7 * 4));
|
|
|
|
Assert.That(tc.getParams().maxObstacles, Is.EqualTo(128));
|
|
|
|
Assert.That(tc.getTileCount(), Is.EqualTo(168));
|
|
|
|
|
|
|
|
// Tile0: Tris: 8, Verts: 18 Detail Meshed: 8 Detail Verts: 0 Detail Tris: 14
|
|
|
|
MeshTile tile = tc.getNavMesh().getTile(0);
|
|
|
|
MeshData data = tile.data;
|
|
|
|
MeshHeader header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(18));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(8));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(8));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(14));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(8));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 18));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(8));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 14));
|
|
|
|
Assert.That(data.verts[1], Is.EqualTo(14.997294f).Within(0.0001f));
|
|
|
|
Assert.That(data.verts[6], Is.EqualTo(15.484785f).Within(0.0001f));
|
|
|
|
Assert.That(data.verts[9], Is.EqualTo(15.484785f).Within(0.0001f));
|
|
|
|
// Tile8: Tris: 3, Verts: 8 Detail Meshed: 3 Detail Verts: 0 Detail Tris: 6
|
|
|
|
tile = tc.getNavMesh().getTile(8);
|
|
|
|
data = tile.data;
|
|
|
|
header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(8));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(3));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(3));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(6));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(3));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 8));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(3));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 6));
|
|
|
|
// Tile16: Tris: 10, Verts: 20 Detail Meshed: 10 Detail Verts: 0 Detail Tris: 18
|
|
|
|
tile = tc.getNavMesh().getTile(16);
|
|
|
|
data = tile.data;
|
|
|
|
header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(20));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(10));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(10));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(18));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(10));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 20));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(10));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 18));
|
|
|
|
// Tile29: Tris: 1, Verts: 5 Detail Meshed: 1 Detail Verts: 0 Detail Tris: 3
|
|
|
|
tile = tc.getNavMesh().getTile(29);
|
|
|
|
data = tile.data;
|
|
|
|
header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(5));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(1));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(1));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(3));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(1));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 5));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(1));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 3));
|
|
|
|
}
|
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
private void test(ByteOrder order, bool cCompatibility)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
InputGeomProvider geom = ObjImporter.load(Loader.ToBytes("nav_test.obj"));
|
|
|
|
TileCache tc = getTileCache(geom, order, cCompatibility);
|
|
|
|
TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom);
|
|
|
|
List<byte[]> layers = layerBuilder.build(order, cCompatibility, 1);
|
|
|
|
int cacheLayerCount = 0;
|
|
|
|
int cacheCompressedSize = 0;
|
|
|
|
int cacheRawSize = 0;
|
2023-03-16 19:48:49 +03:00
|
|
|
foreach (byte[] layer in layers)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long refs = tc.addTile(layer, 0);
|
|
|
|
tc.buildNavMeshTile(refs);
|
|
|
|
cacheLayerCount++;
|
|
|
|
cacheCompressedSize += layer.Length;
|
|
|
|
cacheRawSize += 4 * 48 * 48 + 56;
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
Console.WriteLine("Compressor: " + tc.getCompressor().GetType().Name + " C Compatibility: " + cCompatibility
|
2023-03-16 19:48:49 +03:00
|
|
|
+ " Layers: " + cacheLayerCount + " Raw Size: " + cacheRawSize + " Compressed: " + cacheCompressedSize);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testPerformance()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
int threads = 4;
|
|
|
|
ByteOrder order = ByteOrder.LITTLE_ENDIAN;
|
|
|
|
bool cCompatibility = false;
|
|
|
|
InputGeomProvider geom = ObjImporter.load(Loader.ToBytes("dungeon.obj"));
|
|
|
|
TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom);
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
layerBuilder.build(order, cCompatibility, 1);
|
|
|
|
layerBuilder.build(order, cCompatibility, threads);
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-04-14 16:41:29 +03:00
|
|
|
long t1 = FrequencyWatch.Ticks;
|
2023-03-14 08:02:43 +03:00
|
|
|
List<byte[]> layers = null;
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
layers = layerBuilder.build(order, cCompatibility, 1);
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-04-14 16:41:29 +03:00
|
|
|
long t2 = FrequencyWatch.Ticks;
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
layers = layerBuilder.build(order, cCompatibility, threads);
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-04-14 16:41:29 +03:00
|
|
|
long t3 = FrequencyWatch.Ticks;
|
2023-03-24 04:58:11 +03:00
|
|
|
Console.WriteLine(" Time ST : " + (t2 - t1) / TimeSpan.TicksPerMillisecond);
|
|
|
|
Console.WriteLine(" Time MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond);
|
2023-03-14 08:02:43 +03:00
|
|
|
TileCache tc = getTileCache(geom, order, cCompatibility);
|
2023-03-16 19:48:49 +03:00
|
|
|
foreach (byte[] layer in layers)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long refs = tc.addTile(layer, 0);
|
|
|
|
tc.buildNavMeshTile(refs);
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tc.getNavMesh().getMaxTiles(), Is.EqualTo(256));
|
|
|
|
Assert.That(tc.getNavMesh().getParams().maxPolys, Is.EqualTo(16384));
|
|
|
|
Assert.That(tc.getNavMesh().getParams().tileWidth, Is.EqualTo(14.4f).Within(0.001f));
|
|
|
|
Assert.That(tc.getNavMesh().getParams().tileHeight, Is.EqualTo(14.4f).Within(0.001f));
|
|
|
|
Assert.That(tc.getNavMesh().getMaxVertsPerPoly(), Is.EqualTo(6));
|
|
|
|
Assert.That(tc.getParams().cs, Is.EqualTo(0.3f));
|
|
|
|
Assert.That(tc.getParams().ch, Is.EqualTo(0.2f));
|
|
|
|
Assert.That(tc.getParams().walkableClimb, Is.EqualTo(0.9f));
|
|
|
|
Assert.That(tc.getParams().walkableHeight, Is.EqualTo(2f));
|
|
|
|
Assert.That(tc.getParams().walkableRadius, Is.EqualTo(0.6f));
|
|
|
|
Assert.That(tc.getParams().width, Is.EqualTo(48));
|
|
|
|
Assert.That(tc.getParams().maxTiles, Is.EqualTo(6 * 7 * 4));
|
|
|
|
Assert.That(tc.getParams().maxObstacles, Is.EqualTo(128));
|
|
|
|
Assert.That(tc.getTileCount(), Is.EqualTo(168));
|
|
|
|
// Tile0: Tris: 8, Verts: 18 Detail Meshed: 8 Detail Verts: 0 Detail Tris: 14
|
|
|
|
MeshTile tile = tc.getNavMesh().getTile(0);
|
|
|
|
MeshData data = tile.data;
|
|
|
|
MeshHeader header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(18));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(8));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(8));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(14));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(8));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 18));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(8));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 14));
|
|
|
|
Assert.That(data.verts[1], Is.EqualTo(14.997294f).Within(0.0001f));
|
|
|
|
Assert.That(data.verts[6], Is.EqualTo(15.484785f).Within(0.0001f));
|
|
|
|
Assert.That(data.verts[9], Is.EqualTo(15.484785f).Within(0.0001f));
|
|
|
|
// Tile8: Tris: 3, Verts: 8 Detail Meshed: 3 Detail Verts: 0 Detail Tris: 6
|
|
|
|
tile = tc.getNavMesh().getTile(8);
|
|
|
|
data = tile.data;
|
|
|
|
header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(8));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(3));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(3));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(6));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(3));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 8));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(3));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 6));
|
|
|
|
// Tile16: Tris: 10, Verts: 20 Detail Meshed: 10 Detail Verts: 0 Detail Tris: 18
|
|
|
|
tile = tc.getNavMesh().getTile(16);
|
|
|
|
data = tile.data;
|
|
|
|
header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(20));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(10));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(10));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(18));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(10));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 20));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(10));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 18));
|
|
|
|
// Tile29: Tris: 1, Verts: 5 Detail Meshed: 1 Detail Verts: 0 Detail Tris: 3
|
|
|
|
tile = tc.getNavMesh().getTile(29);
|
|
|
|
data = tile.data;
|
|
|
|
header = data.header;
|
|
|
|
Assert.That(header.vertCount, Is.EqualTo(5));
|
|
|
|
Assert.That(header.polyCount, Is.EqualTo(1));
|
|
|
|
Assert.That(header.detailMeshCount, Is.EqualTo(1));
|
|
|
|
Assert.That(header.detailVertCount, Is.EqualTo(0));
|
|
|
|
Assert.That(header.detailTriCount, Is.EqualTo(3));
|
|
|
|
Assert.That(data.polys.Length, Is.EqualTo(1));
|
|
|
|
Assert.That(data.verts.Length, Is.EqualTo(3 * 5));
|
|
|
|
Assert.That(data.detailMeshes.Length, Is.EqualTo(1));
|
|
|
|
Assert.That(data.detailVerts.Length, Is.EqualTo(0));
|
|
|
|
Assert.That(data.detailTris.Length, Is.EqualTo(4 * 3));
|
|
|
|
}
|
2023-04-29 07:29:40 +03:00
|
|
|
}
|