From 22a699183efbab392a53b5803a6201e88e73d714 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 5 Aug 2023 21:45:05 +0900 Subject: [PATCH] changing compression feature into an Interface --- .../IRcCompressor.cs} | 5 +++-- src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs | 7 ++++++- src/DotRecast.Detour.Dynamic/Io/VoxelFile.cs | 2 +- src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs | 2 +- src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs | 2 +- src/DotRecast.Detour.TileCache/DtTileCache.cs | 6 +++--- src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs | 2 +- ...TileCacheFastLzCompressor.cs => DtFastLzCompressor.cs} | 8 +++++++- .../{DtTileCacheLZ4Compressor.cs => DtLz4Compressor.cs} | 8 +++++++- .../Io/Compress/DtTileCacheCompressorFactory.cs | 8 +++++--- src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs | 2 +- test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs | 1 - 12 files changed, 36 insertions(+), 17 deletions(-) rename src/{DotRecast.Detour.TileCache/IDtTileCacheCompressor.cs => DotRecast.Core/IRcCompressor.cs} (91%) rename src/DotRecast.Detour.TileCache/Io/Compress/{DtTileCacheFastLzCompressor.cs => DtFastLzCompressor.cs} (88%) rename src/DotRecast.Detour.TileCache/Io/Compress/{DtTileCacheLZ4Compressor.cs => DtLz4Compressor.cs} (87%) diff --git a/src/DotRecast.Detour.TileCache/IDtTileCacheCompressor.cs b/src/DotRecast.Core/IRcCompressor.cs similarity index 91% rename from src/DotRecast.Detour.TileCache/IDtTileCacheCompressor.cs rename to src/DotRecast.Core/IRcCompressor.cs index 6efbaa2..2eda567 100644 --- a/src/DotRecast.Detour.TileCache/IDtTileCacheCompressor.cs +++ b/src/DotRecast.Core/IRcCompressor.cs @@ -18,10 +18,11 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -namespace DotRecast.Detour.TileCache +namespace DotRecast.Core { - public interface IDtTileCacheCompressor + public interface IRcCompressor { + byte[] Decompress(byte[] data); byte[] Decompress(byte[] buf, int offset, int len, int outputlen); byte[] Compress(byte[] buf); diff --git a/src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs b/src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs index 0cd7f0e..ef62053 100644 --- a/src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs +++ b/src/DotRecast.Detour.Dynamic/Io/LZ4VoxelTileCompressor.cs @@ -22,7 +22,7 @@ using K4os.Compression.LZ4; namespace DotRecast.Detour.Dynamic.Io { - public class LZ4VoxelTileCompressor + public class LZ4VoxelTileCompressor : IRcCompressor { public byte[] Decompress(byte[] data) { @@ -30,6 +30,11 @@ namespace DotRecast.Detour.Dynamic.Io 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); diff --git a/src/DotRecast.Detour.Dynamic/Io/VoxelFile.cs b/src/DotRecast.Detour.Dynamic/Io/VoxelFile.cs index 098b725..6817d93 100644 --- a/src/DotRecast.Detour.Dynamic/Io/VoxelFile.cs +++ b/src/DotRecast.Detour.Dynamic/Io/VoxelFile.cs @@ -159,4 +159,4 @@ namespace DotRecast.Detour.Dynamic.Io return f; } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs b/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs index 661b05c..695b044 100644 --- a/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs +++ b/src/DotRecast.Detour.Dynamic/Io/VoxelFileReader.cs @@ -139,4 +139,4 @@ namespace DotRecast.Detour.Dynamic.Io return file; } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs b/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs index efb11ed..2d0b991 100644 --- a/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs +++ b/src/DotRecast.Detour.Dynamic/Io/VoxelFileWriter.cs @@ -92,4 +92,4 @@ namespace DotRecast.Detour.Dynamic.Io stream.Write(bytes); } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/DtTileCache.cs b/src/DotRecast.Detour.TileCache/DtTileCache.cs index 484d592..9ea6077 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCache.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCache.cs @@ -54,7 +54,7 @@ namespace DotRecast.Detour.TileCache private readonly DtTileCacheParams m_params; private readonly TileCacheStorageParams m_storageParams; - private readonly IDtTileCacheCompressor m_tcomp; + private readonly IRcCompressor m_tcomp; private readonly IDtTileCacheMeshProcess m_tmproc; private readonly List m_obstacles = new List(); @@ -112,7 +112,7 @@ namespace DotRecast.Detour.TileCache } public DtTileCache(DtTileCacheParams option, TileCacheStorageParams storageParams, DtNavMesh navmesh, - IDtTileCacheCompressor tcomp, IDtTileCacheMeshProcess tmprocs) + IRcCompressor tcomp, IDtTileCacheMeshProcess tmprocs) { m_params = option; m_storageParams = storageParams; @@ -726,7 +726,7 @@ namespace DotRecast.Detour.TileCache return m_params; } - public IDtTileCacheCompressor GetCompressor() + public IRcCompressor GetCompressor() { return m_tcomp; } diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs index f3fb19d..990f299 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs @@ -1958,7 +1958,7 @@ namespace DotRecast.Detour.TileCache } } - public DtTileCacheLayer DecompressTileCacheLayer(IDtTileCacheCompressor comp, byte[] compressed, RcByteOrder order, + public DtTileCacheLayer DecompressTileCacheLayer(IRcCompressor comp, byte[] compressed, RcByteOrder order, bool cCompatibility) { RcByteBuffer buf = new RcByteBuffer(compressed); diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs b/src/DotRecast.Detour.TileCache/Io/Compress/DtFastLzCompressor.cs similarity index 88% rename from src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs rename to src/DotRecast.Detour.TileCache/Io/Compress/DtFastLzCompressor.cs index 44bf899..8b079e8 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs +++ b/src/DotRecast.Detour.TileCache/Io/Compress/DtFastLzCompressor.cs @@ -19,11 +19,17 @@ freely, subject to the following restrictions: */ using DotRecast.Core; +using K4os.Compression.LZ4; namespace DotRecast.Detour.TileCache.Io.Compress { - public class DtTileCacheFastLzCompressor : IDtTileCacheCompressor + public class DtFastLzCompressor : IRcCompressor { + public byte[] Decompress(byte[] buf) + { + return LZ4Pickler.Unpickle(buf); + } + 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/DtTileCacheLZ4Compressor.cs b/src/DotRecast.Detour.TileCache/Io/Compress/DtLz4Compressor.cs similarity index 87% rename from src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheLZ4Compressor.cs rename to src/DotRecast.Detour.TileCache/Io/Compress/DtLz4Compressor.cs index 0b898cf..aeb8a53 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheLZ4Compressor.cs +++ b/src/DotRecast.Detour.TileCache/Io/Compress/DtLz4Compressor.cs @@ -18,12 +18,18 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +using DotRecast.Core; using K4os.Compression.LZ4; namespace DotRecast.Detour.TileCache.Io.Compress { - public class DtTileCacheLZ4Compressor : IDtTileCacheCompressor + public class DtLz4Compressor : IRcCompressor { + 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/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs b/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs index f893c36..7b4606f 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs +++ b/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs @@ -18,16 +18,18 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +using DotRecast.Core; + namespace DotRecast.Detour.TileCache.Io.Compress { public static class DtTileCacheCompressorFactory { - public static IDtTileCacheCompressor Get(bool cCompatibility) + public static IRcCompressor Get(bool cCompatibility) { if (cCompatibility) - return new DtTileCacheFastLzCompressor(); + return new DtFastLzCompressor(); - return new DtTileCacheLZ4Compressor(); + return new DtLz4Compressor(); } } } \ 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 f7e3f59..97b5831 100644 --- a/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs +++ b/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs @@ -64,7 +64,7 @@ namespace DotRecast.Detour.TileCache.Io header.meshParams = paramReader.Read(bb); header.cacheParams = ReadCacheParams(bb, cCompatibility); DtNavMesh mesh = new DtNavMesh(header.meshParams, maxVertPerPoly); - IDtTileCacheCompressor compressor = DtTileCacheCompressorFactory.Get(cCompatibility); + IRcCompressor compressor = DtTileCacheCompressorFactory.Get(cCompatibility); DtTileCache tc = new DtTileCache(header.cacheParams, new TileCacheStorageParams(bb.Order(), cCompatibility), mesh, compressor, meshProcessor); // Read tiles. diff --git a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs index a3dfe53..8d82493 100644 --- a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using DotRecast.Core; using DotRecast.Detour.Dynamic.Colliders; using DotRecast.Detour.Dynamic.Io; - using NUnit.Framework; namespace DotRecast.Detour.Dynamic.Test;