changing compression feature into an Interface

This commit is contained in:
ikpil 2023-08-05 21:45:05 +09:00
parent d19133268e
commit 22a699183e
12 changed files with 36 additions and 17 deletions

View File

@ -18,10 +18,11 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 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[] Decompress(byte[] buf, int offset, int len, int outputlen);
byte[] Compress(byte[] buf); byte[] Compress(byte[] buf);

View File

@ -22,7 +22,7 @@ using K4os.Compression.LZ4;
namespace DotRecast.Detour.Dynamic.Io namespace DotRecast.Detour.Dynamic.Io
{ {
public class LZ4VoxelTileCompressor public class LZ4VoxelTileCompressor : IRcCompressor
{ {
public byte[] Decompress(byte[] data) public byte[] Decompress(byte[] data)
{ {
@ -30,6 +30,11 @@ namespace DotRecast.Detour.Dynamic.Io
return LZ4Pickler.Unpickle(data.AsSpan(4, compressedSize)); 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) public byte[] Compress(byte[] data)
{ {
byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX); byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX);

View File

@ -54,7 +54,7 @@ namespace DotRecast.Detour.TileCache
private readonly DtTileCacheParams m_params; private readonly DtTileCacheParams m_params;
private readonly TileCacheStorageParams m_storageParams; private readonly TileCacheStorageParams m_storageParams;
private readonly IDtTileCacheCompressor m_tcomp; private readonly IRcCompressor m_tcomp;
private readonly IDtTileCacheMeshProcess m_tmproc; private readonly IDtTileCacheMeshProcess m_tmproc;
private readonly List<DtTileCacheObstacle> m_obstacles = new List<DtTileCacheObstacle>(); private readonly List<DtTileCacheObstacle> m_obstacles = new List<DtTileCacheObstacle>();
@ -112,7 +112,7 @@ namespace DotRecast.Detour.TileCache
} }
public DtTileCache(DtTileCacheParams option, TileCacheStorageParams storageParams, DtNavMesh navmesh, public DtTileCache(DtTileCacheParams option, TileCacheStorageParams storageParams, DtNavMesh navmesh,
IDtTileCacheCompressor tcomp, IDtTileCacheMeshProcess tmprocs) IRcCompressor tcomp, IDtTileCacheMeshProcess tmprocs)
{ {
m_params = option; m_params = option;
m_storageParams = storageParams; m_storageParams = storageParams;
@ -726,7 +726,7 @@ namespace DotRecast.Detour.TileCache
return m_params; return m_params;
} }
public IDtTileCacheCompressor GetCompressor() public IRcCompressor GetCompressor()
{ {
return m_tcomp; return m_tcomp;
} }

View File

@ -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) bool cCompatibility)
{ {
RcByteBuffer buf = new RcByteBuffer(compressed); RcByteBuffer buf = new RcByteBuffer(compressed);

View File

@ -19,11 +19,17 @@ freely, subject to the following restrictions:
*/ */
using DotRecast.Core; using DotRecast.Core;
using K4os.Compression.LZ4;
namespace DotRecast.Detour.TileCache.Io.Compress 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) public byte[] Decompress(byte[] buf, int offset, int len, int outputlen)
{ {
byte[] output = new byte[outputlen]; byte[] output = new byte[outputlen];

View File

@ -18,12 +18,18 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
using DotRecast.Core;
using K4os.Compression.LZ4; using K4os.Compression.LZ4;
namespace DotRecast.Detour.TileCache.Io.Compress 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) public byte[] Decompress(byte[] buf, int offset, int len, int outputlen)
{ {
return LZ4Pickler.Unpickle(buf, offset, len); return LZ4Pickler.Unpickle(buf, offset, len);

View File

@ -18,16 +18,18 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
using DotRecast.Core;
namespace DotRecast.Detour.TileCache.Io.Compress namespace DotRecast.Detour.TileCache.Io.Compress
{ {
public static class DtTileCacheCompressorFactory public static class DtTileCacheCompressorFactory
{ {
public static IDtTileCacheCompressor Get(bool cCompatibility) public static IRcCompressor Get(bool cCompatibility)
{ {
if (cCompatibility) if (cCompatibility)
return new DtTileCacheFastLzCompressor(); return new DtFastLzCompressor();
return new DtTileCacheLZ4Compressor(); return new DtLz4Compressor();
} }
} }
} }

View File

@ -64,7 +64,7 @@ namespace DotRecast.Detour.TileCache.Io
header.meshParams = paramReader.Read(bb); header.meshParams = paramReader.Read(bb);
header.cacheParams = ReadCacheParams(bb, cCompatibility); header.cacheParams = ReadCacheParams(bb, cCompatibility);
DtNavMesh mesh = new DtNavMesh(header.meshParams, maxVertPerPoly); 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, DtTileCache tc = new DtTileCache(header.cacheParams, new TileCacheStorageParams(bb.Order(), cCompatibility), mesh,
compressor, meshProcessor); compressor, meshProcessor);
// Read tiles. // Read tiles.

View File

@ -4,7 +4,6 @@ using System.Threading.Tasks;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Detour.Dynamic.Colliders; using DotRecast.Detour.Dynamic.Colliders;
using DotRecast.Detour.Dynamic.Io; using DotRecast.Detour.Dynamic.Io;
using NUnit.Framework; using NUnit.Framework;
namespace DotRecast.Detour.Dynamic.Test; namespace DotRecast.Detour.Dynamic.Test;