diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/FastLz.cs b/src/DotRecast.Core/FastLz.cs similarity index 99% rename from src/DotRecast.Detour.TileCache/Io/Compress/FastLz.cs rename to src/DotRecast.Core/FastLz.cs index 697339c..b3ec9ed 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/FastLz.cs +++ b/src/DotRecast.Core/FastLz.cs @@ -16,7 +16,7 @@ using System; -namespace DotRecast.Detour.TileCache.Io.Compress +namespace DotRecast.Core { /** * Core of FastLZ compression algorithm. diff --git a/src/DotRecast.Detour.Dynamic/DotRecast.Detour.Dynamic.csproj b/src/DotRecast.Detour.Dynamic/DotRecast.Detour.Dynamic.csproj index 0919237..83d41b0 100644 --- a/src/DotRecast.Detour.Dynamic/DotRecast.Detour.Dynamic.csproj +++ b/src/DotRecast.Detour.Dynamic/DotRecast.Detour.Dynamic.csproj @@ -5,10 +5,6 @@ - - - - diff --git a/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs b/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs index 695b044..da66ae3 100644 --- a/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs +++ b/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs @@ -24,7 +24,12 @@ namespace DotRecast.Detour.Dynamic.Io { public class VoxelFileReader { - private readonly LZ4VoxelTileCompressor compressor = new LZ4VoxelTileCompressor(); + private readonly IRcCompressor _compressor; + + public VoxelFileReader(IRcCompressor compressor) + { + _compressor = compressor; + } public VoxelFile Read(BinaryReader stream) { @@ -127,7 +132,7 @@ namespace DotRecast.Detour.Dynamic.Io byte[] bytes = buf.ReadBytes(voxelSize).ToArray(); if (compression) { - bytes = compressor.Decompress(bytes); + bytes = _compressor.Decompress(bytes); } RcByteBuffer data = new RcByteBuffer(bytes); diff --git a/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs b/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs index 2d0b991..22787a6 100644 --- a/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs +++ b/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs @@ -24,7 +24,12 @@ namespace DotRecast.Detour.Dynamic.Io { public class VoxelFileWriter : DtWriter { - private readonly LZ4VoxelTileCompressor compressor = new LZ4VoxelTileCompressor(); + private readonly IRcCompressor _compressor; + + public VoxelFileWriter(IRcCompressor compressor) + { + _compressor = compressor; + } public void Write(BinaryWriter stream, VoxelFile f, bool compression) { @@ -85,7 +90,7 @@ namespace DotRecast.Detour.Dynamic.Io byte[] bytes = tile.spanData; if (compression) { - bytes = compressor.Compress(bytes); + bytes = _compressor.Compress(bytes); } Write(stream, bytes.Length, byteOrder); diff --git a/src/DotRecast.Detour.TileCache/DotRecast.Detour.TileCache.csproj b/src/DotRecast.Detour.TileCache/DotRecast.Detour.TileCache.csproj index 3dccb7f..61c8f1a 100644 --- a/src/DotRecast.Detour.TileCache/DotRecast.Detour.TileCache.csproj +++ b/src/DotRecast.Detour.TileCache/DotRecast.Detour.TileCache.csproj @@ -5,12 +5,8 @@ - - - - - + \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/DtTileCache.cs b/src/DotRecast.Detour.TileCache/DtTileCache.cs index 9ea6077..11abac4 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCache.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCache.cs @@ -111,8 +111,7 @@ namespace DotRecast.Detour.TileCache return (int)(refs & tileMask); } - public DtTileCache(DtTileCacheParams option, TileCacheStorageParams storageParams, DtNavMesh navmesh, - IRcCompressor tcomp, IDtTileCacheMeshProcess tmprocs) + public DtTileCache(DtTileCacheParams option, TileCacheStorageParams storageParams, DtNavMesh navmesh, IRcCompressor tcomp, IDtTileCacheMeshProcess tmprocs) { m_params = option; m_storageParams = storageParams; @@ -677,8 +676,7 @@ namespace DotRecast.Detour.TileCache public DtTileCacheLayer DecompressTile(DtCompressedTile tile) { - DtTileCacheLayer layer = builder.DecompressTileCacheLayer(m_tcomp, tile.data, m_storageParams.byteOrder, - m_storageParams.cCompatibility); + DtTileCacheLayer layer = builder.DecompressTileCacheLayer(m_tcomp, tile.data, m_storageParams.byteOrder, m_storageParams.cCompatibility); return layer; } @@ -746,4 +744,4 @@ namespace DotRecast.Detour.TileCache return m_navmesh; } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs index 990f299..6403f78 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs @@ -1905,7 +1905,7 @@ namespace DotRecast.Detour.TileCache } } - public byte[] CompressTileCacheLayer(DtTileCacheLayer layer, RcByteOrder order, bool cCompatibility) + public byte[] CompressTileCacheLayer(IRcCompressor comp, DtTileCacheLayer layer, RcByteOrder order, bool cCompatibility) { using var ms = new MemoryStream(); using var baos = new BinaryWriter(ms); @@ -1922,7 +1922,8 @@ namespace DotRecast.Detour.TileCache buffer[gridSize * 2 + i] = (byte)layer.cons[i]; } - baos.Write(DtTileCacheCompressorFactory.Get(cCompatibility).Compress(buffer)); + var compressed = comp.Compress(buffer); + baos.Write(compressed); return ms.ToArray(); } catch (IOException e) @@ -1931,8 +1932,7 @@ namespace DotRecast.Detour.TileCache } } - public byte[] CompressTileCacheLayer(DtTileCacheLayerHeader header, int[] heights, int[] areas, int[] cons, - RcByteOrder order, bool cCompatibility) + public byte[] CompressTileCacheLayer(DtTileCacheLayerHeader header, int[] heights, int[] areas, int[] cons, RcByteOrder order, bool cCompatibility, IRcCompressor comp) { using var ms = new MemoryStream(); using var baos = new BinaryWriter(ms); @@ -1949,7 +1949,8 @@ namespace DotRecast.Detour.TileCache buffer[gridSize * 2 + i] = (byte)cons[i]; } - baos.Write(DtTileCacheCompressorFactory.Get(cCompatibility).Compress(buffer)); + var compressed = comp.Compress(buffer); + baos.Write(compressed); return ms.ToArray(); } catch (IOException e) @@ -1958,8 +1959,7 @@ namespace DotRecast.Detour.TileCache } } - public DtTileCacheLayer DecompressTileCacheLayer(IRcCompressor comp, byte[] compressed, RcByteOrder order, - bool cCompatibility) + public DtTileCacheLayer DecompressTileCacheLayer(IRcCompressor comp, byte[] compressed, RcByteOrder order, bool cCompatibility) { RcByteBuffer buf = new RcByteBuffer(compressed); buf.Order(order); diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/DtFastLzCompressor.cs b/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs similarity index 84% rename from src/DotRecast.Detour.TileCache/Io/Compress/DtFastLzCompressor.cs rename to src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs index 8b079e8..42e42a3 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/DtFastLzCompressor.cs +++ b/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs @@ -19,17 +19,23 @@ freely, subject to the following restrictions: */ using DotRecast.Core; -using K4os.Compression.LZ4; namespace DotRecast.Detour.TileCache.Io.Compress { - public class DtFastLzCompressor : IRcCompressor + public class DtTileCacheFastLzCompressor : IRcCompressor { + public static readonly DtTileCacheFastLzCompressor Shared = new DtTileCacheFastLzCompressor(); + + private DtTileCacheFastLzCompressor() + { + + } + public byte[] Decompress(byte[] buf) { - return LZ4Pickler.Unpickle(buf); + return Decompress(buf, 0, buf.Length, buf.Length * 3); } - + public byte[] Decompress(byte[] buf, int offset, int len, int outputlen) { byte[] output = new byte[outputlen]; diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs b/src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs similarity index 80% rename from src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs rename to src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs index 7b4606f..3f90f06 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs +++ b/src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs @@ -22,14 +22,8 @@ using DotRecast.Core; namespace DotRecast.Detour.TileCache.Io.Compress { - public static class DtTileCacheCompressorFactory + public interface IDtTileCacheCompressorFactory { - public static IRcCompressor Get(bool cCompatibility) - { - if (cCompatibility) - return new DtFastLzCompressor(); - - return new DtLz4Compressor(); - } + IRcCompressor Get(bool cCompatibility); } } \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs b/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs index 97b5831..7aee276 100644 --- a/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs +++ b/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs @@ -28,6 +28,12 @@ namespace DotRecast.Detour.TileCache.Io public class DtTileCacheReader { private readonly DtNavMeshParamsReader paramReader = new DtNavMeshParamsReader(); + private readonly IDtTileCacheCompressorFactory _compFactory; + + public DtTileCacheReader(IDtTileCacheCompressorFactory compFactory) + { + _compFactory = compFactory; + } public DtTileCache Read(BinaryReader @is, int maxVertPerPoly, IDtTileCacheMeshProcess meshProcessor) { @@ -64,9 +70,8 @@ namespace DotRecast.Detour.TileCache.Io header.meshParams = paramReader.Read(bb); header.cacheParams = ReadCacheParams(bb, cCompatibility); DtNavMesh mesh = new DtNavMesh(header.meshParams, maxVertPerPoly); - IRcCompressor compressor = DtTileCacheCompressorFactory.Get(cCompatibility); - DtTileCache tc = new DtTileCache(header.cacheParams, new TileCacheStorageParams(bb.Order(), cCompatibility), mesh, - compressor, meshProcessor); + IRcCompressor comp = _compFactory.Get(cCompatibility); + DtTileCache tc = new DtTileCache(header.cacheParams, new TileCacheStorageParams(bb.Order(), cCompatibility), mesh, comp, meshProcessor); // Read tiles. for (int i = 0; i < header.numTiles; ++i) { @@ -91,7 +96,7 @@ namespace DotRecast.Detour.TileCache.Io private DtTileCacheParams ReadCacheParams(RcByteBuffer bb, bool cCompatibility) { DtTileCacheParams option = new DtTileCacheParams(); - + option.orig.x = bb.GetFloat(); option.orig.y = bb.GetFloat(); option.orig.z = bb.GetFloat(); diff --git a/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs b/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs index 1fb34f7..71c1ea8 100644 --- a/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs +++ b/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System.IO; using DotRecast.Core; using DotRecast.Detour.Io; +using DotRecast.Detour.TileCache.Io.Compress; namespace DotRecast.Detour.TileCache.Io { @@ -28,6 +29,13 @@ namespace DotRecast.Detour.TileCache.Io { private readonly DtNavMeshParamWriter paramWriter = new DtNavMeshParamWriter(); private readonly DtTileCacheBuilder builder = new DtTileCacheBuilder(); + private readonly IDtTileCacheCompressorFactory _compFactory; + + public DtTileCacheWriter(IDtTileCacheCompressorFactory compFactory) + { + _compFactory = compFactory; + } + public void Write(BinaryWriter stream, DtTileCache cache, RcByteOrder order, bool cCompatibility) { @@ -55,7 +63,8 @@ namespace DotRecast.Detour.TileCache.Io Write(stream, (int)cache.GetTileRef(tile), order); byte[] data = tile.data; DtTileCacheLayer layer = cache.DecompressTile(tile); - data = builder.CompressTileCacheLayer(layer, order, cCompatibility); + var comp = _compFactory.Get(cCompatibility); + data = builder.CompressTileCacheLayer(comp, layer, order, cCompatibility); Write(stream, data.Length, order); stream.Write(data); } diff --git a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj index e914a7a..66b2ef1 100644 --- a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj +++ b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj @@ -13,6 +13,7 @@ + diff --git a/src/DotRecast.Recast.Demo/DtVoxelTileLZ4DemoCompressor.cs b/src/DotRecast.Recast.Demo/DtVoxelTileLZ4DemoCompressor.cs new file mode 100644 index 0000000..c47bb84 --- /dev/null +++ b/src/DotRecast.Recast.Demo/DtVoxelTileLZ4DemoCompressor.cs @@ -0,0 +1,35 @@ +using System; +using DotRecast.Core; +using DotRecast.Detour.Dynamic.Io; +using K4os.Compression.LZ4; + +namespace DotRecast.Recast.Demo; + +public class DtVoxelTileLZ4DemoCompressor : IRcCompressor +{ + public static readonly DtVoxelTileLZ4DemoCompressor Shared = new(); + + private DtVoxelTileLZ4DemoCompressor() + { + } + + public byte[] Decompress(byte[] data) + { + int compressedSize = ByteUtils.GetIntBE(data, 0); + return LZ4Pickler.Unpickle(data.AsSpan(4, compressedSize)); + } + + public byte[] Decompress(byte[] buf, int offset, int len, int outputlen) + { + return LZ4Pickler.Unpickle(buf, offset, len); + } + + public byte[] Compress(byte[] data) + { + byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX); + byte[] result = new byte[4 + compressed.Length]; + ByteUtils.PutInt(compressed.Length, result, 0, RcByteOrder.BIG_ENDIAN); + Array.Copy(compressed, 0, result, 4, compressed.Length); + return result; + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index 75773dc..d8ca3c9 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -675,7 +675,7 @@ public class DynamicUpdateTool : IRcTool { using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read); using var br = new BinaryReader(fs); - VoxelFileReader reader = new VoxelFileReader(); + VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4DemoCompressor.Shared); VoxelFile voxelFile = reader.Read(br); dynaMesh = new DynamicNavMesh(voxelFile); dynaMesh.config.keepIntermediateResults = true; @@ -697,7 +697,7 @@ public class DynamicUpdateTool : IRcTool using var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write); using var bw = new BinaryWriter(fs); VoxelFile voxelFile = VoxelFile.From(dynaMesh); - VoxelFileWriter writer = new VoxelFileWriter(); + VoxelFileWriter writer = new VoxelFileWriter(DtVoxelTileLZ4DemoCompressor.Shared); writer.Write(bw, voxelFile, compression); } diff --git a/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj b/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj index a1e021d..5f83194 100644 --- a/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj +++ b/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj @@ -6,14 +6,15 @@ - - - + + + + - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -21,9 +22,9 @@ - - - + + + diff --git a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs index 8d82493..e99508a 100644 --- a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using DotRecast.Core; using DotRecast.Detour.Dynamic.Colliders; using DotRecast.Detour.Dynamic.Io; +using DotRecast.Detour.Dynamic.Test.Io; using NUnit.Framework; namespace DotRecast.Detour.Dynamic.Test; @@ -25,7 +26,7 @@ public class DynamicNavMeshTest using var bis = new BinaryReader(ms); // load voxels from file - VoxelFileReader reader = new VoxelFileReader(); + VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared); VoxelFile f = reader.Read(bis); // create dynamic navmesh DynamicNavMesh mesh = new DynamicNavMesh(f); diff --git a/src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs b/test/DotRecast.Detour.Dynamic.Test/Io/DtVoxelTileLZ4ForTestCompressor.cs similarity index 85% rename from src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs rename to test/DotRecast.Detour.Dynamic.Test/Io/DtVoxelTileLZ4ForTestCompressor.cs index ef62053..ef6b80c 100644 --- a/src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs +++ b/test/DotRecast.Detour.Dynamic.Test/Io/DtVoxelTileLZ4ForTestCompressor.cs @@ -18,12 +18,19 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; +using DotRecast.Detour.Dynamic.Io; using K4os.Compression.LZ4; -namespace DotRecast.Detour.Dynamic.Io +namespace DotRecast.Detour.Dynamic.Test.Io { - public class LZ4VoxelTileCompressor : IRcCompressor + public class DtVoxelTileLZ4ForTestCompressor : IRcCompressor { + public static readonly DtVoxelTileLZ4ForTestCompressor Shared = new(); + + private DtVoxelTileLZ4ForTestCompressor() + { + } + public byte[] Decompress(byte[] data) { int compressedSize = ByteUtils.GetIntBE(data, 0); diff --git a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs index 8afb8f3..f3cf855 100644 --- a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs @@ -33,7 +33,7 @@ public class VoxelFileReaderTest using var ms = new MemoryStream(bytes); using var bis = new BinaryReader(ms); - VoxelFileReader reader = new VoxelFileReader(); + VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared); VoxelFile f = reader.Read(bis); Assert.That(f.useTiles, Is.False); Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f })); @@ -59,7 +59,7 @@ public class VoxelFileReaderTest using var ms = new MemoryStream(bytes); using var bis = new BinaryReader(ms); - VoxelFileReader reader = new VoxelFileReader(); + VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared); VoxelFile f = reader.Read(bis); Assert.That(f.useTiles, Is.True); diff --git a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs index 45f9fbc..48e3e5d 100644 --- a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs @@ -87,12 +87,12 @@ public class VoxelFileReaderWriterTest private VoxelFile ReadWriteRead(BinaryReader bis, bool compression) { - VoxelFileReader reader = new VoxelFileReader(); + VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared); VoxelFile f = reader.Read(bis); using var msOut = new MemoryStream(); using var bwOut = new BinaryWriter(msOut); - VoxelFileWriter writer = new VoxelFileWriter(); + VoxelFileWriter writer = new VoxelFileWriter(DtVoxelTileLZ4ForTestCompressor.Shared); writer.Write(bwOut, f, compression); using var msIn = new MemoryStream(msOut.ToArray()); diff --git a/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs b/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs index 0590310..7f5dcbe 100644 --- a/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs @@ -22,6 +22,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Detour.Dynamic.Io; +using DotRecast.Detour.Dynamic.Test.Io; using DotRecast.Recast; using Moq; using NUnit.Framework; @@ -96,7 +97,7 @@ public class VoxelQueryTest using var bis = new BinaryReader(ms); // load voxels from file - VoxelFileReader reader = new VoxelFileReader(); + VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared); VoxelFile f = reader.Read(bis); // create dynamic navmesh var mesh = new DynamicNavMesh(f); diff --git a/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs b/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs index c5ef78b..c349ccd 100644 --- a/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using DotRecast.Core; using DotRecast.Detour.TileCache.Io.Compress; +using DotRecast.Detour.TileCache.Test.Io; using DotRecast.Recast.Geom; using NUnit.Framework; using static DotRecast.Core.RcMath; @@ -72,8 +73,8 @@ public class AbstractTileCacheTest navMeshParams.maxTiles = 256; navMeshParams.maxPolys = 16384; DtNavMesh navMesh = new DtNavMesh(navMeshParams, 6); - DtTileCache tc = new DtTileCache(option, new TileCacheStorageParams(order, cCompatibility), navMesh, - DtTileCacheCompressorFactory.Get(cCompatibility), new TestTileCacheMeshProcess()); + var comp = DtTileCacheCompressorForTestFactory.Shared.Get(cCompatibility); + DtTileCache tc = new DtTileCache(option, new TileCacheStorageParams(order, cCompatibility), navMesh, comp, new TestTileCacheMeshProcess()); return tc; } } \ No newline at end of file diff --git a/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj b/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj index 9106cbf..34c2fef 100644 --- a/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj +++ b/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj @@ -6,12 +6,13 @@ - - - + + + + - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -20,9 +21,9 @@ - - - + + + diff --git a/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs b/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs new file mode 100644 index 0000000..b8272c4 --- /dev/null +++ b/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs @@ -0,0 +1,21 @@ +using DotRecast.Core; +using DotRecast.Detour.TileCache.Io.Compress; + +namespace DotRecast.Detour.TileCache.Test.Io; + +public class DtTileCacheCompressorForTestFactory : IDtTileCacheCompressorFactory +{ + public static readonly DtTileCacheCompressorForTestFactory Shared = new(); + + private DtTileCacheCompressorForTestFactory() + { + } + + public IRcCompressor Get(bool cCompatibility) + { + if (cCompatibility) + return DtTileCacheFastLzCompressor.Shared; + + return DtTileCacheLZ4ForTestCompressor.Shared; + } +} \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/DtLz4Compressor.cs b/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheLZ4ForTestCompressor.cs similarity index 84% rename from src/DotRecast.Detour.TileCache/Io/Compress/DtLz4Compressor.cs rename to test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheLZ4ForTestCompressor.cs index aeb8a53..0a22d94 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/DtLz4Compressor.cs +++ b/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheLZ4ForTestCompressor.cs @@ -21,15 +21,21 @@ freely, subject to the following restrictions: using DotRecast.Core; using K4os.Compression.LZ4; -namespace DotRecast.Detour.TileCache.Io.Compress +namespace DotRecast.Detour.TileCache.Test.Io { - public class DtLz4Compressor : IRcCompressor + public class DtTileCacheLZ4ForTestCompressor : IRcCompressor { + public static readonly DtTileCacheLZ4ForTestCompressor Shared = new(); + + private DtTileCacheLZ4ForTestCompressor() + { + } + public byte[] Decompress(byte[] buf) { return LZ4Pickler.Unpickle(buf); } - + public byte[] Decompress(byte[] buf, int offset, int len, int outputlen) { return LZ4Pickler.Unpickle(buf, offset, len); diff --git a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs index 88b3ca4..b959d71 100644 --- a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs @@ -29,7 +29,7 @@ namespace DotRecast.Detour.TileCache.Test.Io; [Parallelizable] public class TileCacheReaderTest { - private readonly DtTileCacheReader reader = new DtTileCacheReader(); + private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared); [Test] public void TestNavmesh() diff --git a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs index d611f4f..d3334e9 100644 --- a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs @@ -31,8 +31,8 @@ namespace DotRecast.Detour.TileCache.Test.Io; [Parallelizable] public class TileCacheReaderWriterTest : AbstractTileCacheTest { - private readonly DtTileCacheReader reader = new DtTileCacheReader(); - private readonly DtTileCacheWriter writer = new DtTileCacheWriter(); + private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared); + private readonly DtTileCacheWriter writer = new DtTileCacheWriter(DtTileCacheCompressorForTestFactory.Shared); [Test] public void TestFastLz() diff --git a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs index cf4e50a..0a42fe9 100644 --- a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs +++ b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core; +using DotRecast.Detour.TileCache.Test.Io; using DotRecast.Recast; using DotRecast.Recast.Geom; @@ -107,7 +108,9 @@ public class TestTileLayerBuilder : AbstractTileLayersBuilder header.maxy = layer.maxy; header.hmin = layer.hmin; header.hmax = layer.hmax; - result.Add(builder.CompressTileCacheLayer(header, layer.heights, layer.areas, layer.cons, order, cCompatibility)); + + var comp = DtTileCacheCompressorForTestFactory.Shared.Get(cCompatibility); + result.Add(builder.CompressTileCacheLayer(header, layer.heights, layer.areas, layer.cons, order, cCompatibility, comp)); } } diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs index 2b60328..c3da135 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.IO; using DotRecast.Core; using DotRecast.Detour.TileCache.Io; +using DotRecast.Detour.TileCache.Test.Io; using NUnit.Framework; namespace DotRecast.Detour.TileCache.Test; @@ -38,7 +39,7 @@ public class TileCacheFindPathTest : AbstractTileCacheTest { using var msis = new MemoryStream(Loader.ToBytes("dungeon_all_tiles_tilecache.bin")); using var @is = new BinaryReader(msis); - DtTileCache tcC = new DtTileCacheReader().Read(@is, 6, new TestTileCacheMeshProcess()); + DtTileCache tcC = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared).Read(@is, 6, new TestTileCacheMeshProcess()); navmesh = tcC.GetNavMesh(); query = new DtNavMeshQuery(navmesh); }