forked from bit/DotRecastNetSim
changing compression feature into an Interface
This commit is contained in:
parent
d19133268e
commit
22a699183e
|
@ -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);
|
|
@ -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);
|
||||
|
|
|
@ -159,4 +159,4 @@ namespace DotRecast.Detour.Dynamic.Io
|
|||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -139,4 +139,4 @@ namespace DotRecast.Detour.Dynamic.Io
|
|||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -92,4 +92,4 @@ namespace DotRecast.Detour.Dynamic.Io
|
|||
stream.Write(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<DtTileCacheObstacle> m_obstacles = new List<DtTileCacheObstacle>();
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
|
@ -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);
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue