forked from bit/DotRecastNetSim
add tile cache compressor factory shared
This commit is contained in:
parent
2050c476a2
commit
4be459b296
|
@ -127,7 +127,7 @@ namespace DotRecast.Detour.TileCache
|
||||||
header.hmin = layer.hmin;
|
header.hmin = layer.hmin;
|
||||||
header.hmax = layer.hmax;
|
header.hmax = layer.hmax;
|
||||||
|
|
||||||
var comp = _compFactory.Get(storageParams.Compatibility);
|
var comp = _compFactory.Create(storageParams.Compatibility ? 0 : 1);
|
||||||
var bytes = builder.CompressTileCacheLayer(header, layer.heights, layer.areas, layer.cons, storageParams.Order, storageParams.Compatibility, comp);
|
var bytes = builder.CompressTileCacheLayer(header, layer.heights, layer.areas, layer.cons, storageParams.Order, storageParams.Compatibility, comp);
|
||||||
result.Add(bytes);
|
result.Add(bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DotRecast.Core;
|
||||||
|
|
||||||
|
namespace DotRecast.Detour.TileCache.Io.Compress
|
||||||
|
{
|
||||||
|
public class DtTileCacheCompressorFactory : IDtTileCacheCompressorFactory
|
||||||
|
{
|
||||||
|
public static readonly DtTileCacheCompressorFactory Shared = new DtTileCacheCompressorFactory();
|
||||||
|
|
||||||
|
private readonly Dictionary<int, IRcCompressor> _compressors = new Dictionary<int, IRcCompressor>();
|
||||||
|
|
||||||
|
public bool TryAdd(int type, IRcCompressor compressor)
|
||||||
|
{
|
||||||
|
if (0 == type)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_compressors[type] = compressor;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRcCompressor Create(int compatibility)
|
||||||
|
{
|
||||||
|
// default
|
||||||
|
if (0 == compatibility)
|
||||||
|
{
|
||||||
|
return DtTileCacheFastLzCompressor.Shared;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_compressors.TryGetValue(compatibility, out var comp))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return comp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,6 @@ namespace DotRecast.Detour.TileCache.Io.Compress
|
||||||
{
|
{
|
||||||
public interface IDtTileCacheCompressorFactory
|
public interface IDtTileCacheCompressorFactory
|
||||||
{
|
{
|
||||||
IRcCompressor Get(bool cCompatibility);
|
IRcCompressor Create(int compatibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -70,7 +70,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);
|
||||||
IRcCompressor comp = _compFactory.Get(cCompatibility);
|
IRcCompressor comp = _compFactory.Create(cCompatibility ? 0 : 1);
|
||||||
DtTileCacheStorageParams storageParams = new DtTileCacheStorageParams(bb.Order(), cCompatibility);
|
DtTileCacheStorageParams storageParams = new DtTileCacheStorageParams(bb.Order(), cCompatibility);
|
||||||
DtTileCache tc = new DtTileCache(header.cacheParams, storageParams, mesh, comp, meshProcessor);
|
DtTileCache tc = new DtTileCache(header.cacheParams, storageParams, mesh, comp, meshProcessor);
|
||||||
// Read tiles.
|
// Read tiles.
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace DotRecast.Detour.TileCache.Io
|
||||||
Write(stream, (int)cache.GetTileRef(tile), order);
|
Write(stream, (int)cache.GetTileRef(tile), order);
|
||||||
byte[] data = tile.data;
|
byte[] data = tile.data;
|
||||||
DtTileCacheLayer layer = cache.DecompressTile(tile);
|
DtTileCacheLayer layer = cache.DecompressTile(tile);
|
||||||
var comp = _compFactory.Get(cCompatibility);
|
var comp = _compFactory.Create(cCompatibility ? 0 : 1);
|
||||||
data = builder.CompressTileCacheLayer(comp, layer, order, cCompatibility);
|
data = builder.CompressTileCacheLayer(comp, layer, order, cCompatibility);
|
||||||
Write(stream, data.Length, order);
|
Write(stream, data.Length, order);
|
||||||
stream.Write(data);
|
stream.Write(data);
|
||||||
|
|
|
@ -8,12 +8,23 @@ namespace DotRecast.Recast.Demo.Draw;
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 1)]
|
[StructLayout(LayoutKind.Explicit, Pack = 1)]
|
||||||
public struct OpenGLVertex
|
public struct OpenGLVertex
|
||||||
{
|
{
|
||||||
[FieldOffset(0)] private readonly float x;
|
[FieldOffset(0)]
|
||||||
[FieldOffset(4)] private readonly float y;
|
private readonly float x;
|
||||||
[FieldOffset(8)] private readonly float z;
|
|
||||||
[FieldOffset(12)] private readonly float u;
|
[FieldOffset(4)]
|
||||||
[FieldOffset(16)] private readonly float v;
|
private readonly float y;
|
||||||
[FieldOffset(20)] private readonly int color;
|
|
||||||
|
[FieldOffset(8)]
|
||||||
|
private readonly float z;
|
||||||
|
|
||||||
|
[FieldOffset(12)]
|
||||||
|
private readonly float u;
|
||||||
|
|
||||||
|
[FieldOffset(16)]
|
||||||
|
private readonly float v;
|
||||||
|
|
||||||
|
[FieldOffset(20)]
|
||||||
|
private readonly int color;
|
||||||
|
|
||||||
public OpenGLVertex(RcVec3f pos, RcVec2f uv, int color) :
|
public OpenGLVertex(RcVec3f pos, RcVec2f uv, int color) :
|
||||||
this(pos.x, pos.y, pos.z, uv.x, uv.y, color)
|
this(pos.x, pos.y, pos.z, uv.x, uv.y, color)
|
||||||
|
|
|
@ -23,7 +23,6 @@ using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour;
|
using DotRecast.Detour;
|
||||||
|
|
||||||
using DotRecast.Recast.Toolset.Builder;
|
using DotRecast.Recast.Toolset.Builder;
|
||||||
using Silk.NET.OpenGL;
|
using Silk.NET.OpenGL;
|
||||||
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
using DotRecast.Core;
|
|
||||||
using DotRecast.Detour.TileCache.Io.Compress;
|
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo;
|
|
||||||
|
|
||||||
public class DtTileCacheCompressorDemoFactory : IDtTileCacheCompressorFactory
|
|
||||||
{
|
|
||||||
public static readonly DtTileCacheCompressorDemoFactory Shared = new();
|
|
||||||
|
|
||||||
private DtTileCacheCompressorDemoFactory()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public IRcCompressor Get(bool cCompatibility)
|
|
||||||
{
|
|
||||||
if (cCompatibility)
|
|
||||||
return DtTileCacheFastLzCompressor.Shared;
|
|
||||||
|
|
||||||
return DtTileCacheLZ4DemoCompressor.Shared;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
||||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
|
||||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
|
||||||
|
|
||||||
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 DotRecast.Core;
|
|
||||||
using K4os.Compression.LZ4;
|
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo
|
|
||||||
{
|
|
||||||
public class DtTileCacheLZ4DemoCompressor : IRcCompressor
|
|
||||||
{
|
|
||||||
public static readonly DtTileCacheLZ4DemoCompressor Shared = new();
|
|
||||||
|
|
||||||
private DtTileCacheLZ4DemoCompressor()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Compress(byte[] buf)
|
|
||||||
{
|
|
||||||
return LZ4Pickler.Pickle(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,5 +2,4 @@
|
||||||
|
|
||||||
public class IRecastDemoMessage
|
public class IRecastDemoMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,5 +2,4 @@
|
||||||
|
|
||||||
public class NavMeshBuildBeganEvent : IRecastDemoMessage
|
public class NavMeshBuildBeganEvent : IRecastDemoMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,5 +2,4 @@
|
||||||
|
|
||||||
public class NavMeshSaveBeganEvent : IRecastDemoMessage
|
public class NavMeshSaveBeganEvent : IRecastDemoMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@ using DotRecast.Core;
|
||||||
using DotRecast.Detour;
|
using DotRecast.Detour;
|
||||||
using DotRecast.Detour.Crowd;
|
using DotRecast.Detour.Crowd;
|
||||||
using DotRecast.Detour.Crowd.Tracking;
|
using DotRecast.Detour.Crowd.Tracking;
|
||||||
|
|
||||||
using DotRecast.Recast.Toolset.Builder;
|
using DotRecast.Recast.Toolset.Builder;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using DotRecast.Recast.Toolset;
|
using DotRecast.Recast.Toolset;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
|
|
||||||
using static DotRecast.Core.RcMath;
|
using static DotRecast.Core.RcMath;
|
||||||
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
|
|
||||||
using static DotRecast.Core.RcMath;
|
using static DotRecast.Core.RcMath;
|
||||||
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using DotRecast.Recast.Toolset;
|
using DotRecast.Recast.Toolset;
|
||||||
using DotRecast.Recast.Toolset.Tools;
|
using DotRecast.Recast.Toolset.Tools;
|
||||||
|
@ -16,7 +17,7 @@ public class ObstacleTool : IRcTool
|
||||||
|
|
||||||
public ObstacleTool()
|
public ObstacleTool()
|
||||||
{
|
{
|
||||||
_impl = new(DtTileCacheCompressorDemoFactory.Shared);
|
_impl = new(DtTileCacheCompressorFactory.Shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISampleTool GetTool()
|
public ISampleTool GetTool()
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class AbstractTileCacheTest
|
||||||
navMeshParams.maxPolys = 16384;
|
navMeshParams.maxPolys = 16384;
|
||||||
|
|
||||||
var navMesh = new DtNavMesh(navMeshParams, 6);
|
var navMesh = new DtNavMesh(navMeshParams, 6);
|
||||||
var comp = DtTileCacheCompressorForTestFactory.Shared.Get(cCompatibility);
|
var comp = DtTileCacheCompressorFactory.Shared.Create(cCompatibility ? 0 : 1);
|
||||||
var storageParams = new DtTileCacheStorageParams(order, cCompatibility);
|
var storageParams = new DtTileCacheStorageParams(order, cCompatibility);
|
||||||
var process = new TestTileCacheMeshProcess();
|
var process = new TestTileCacheMeshProcess();
|
||||||
DtTileCache tc = new DtTileCache(option, storageParams, navMesh, comp, process);
|
DtTileCache tc = new DtTileCache(option, storageParams, navMesh, comp, process);
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io;
|
using DotRecast.Detour.TileCache.Io;
|
||||||
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache.Test.Io;
|
namespace DotRecast.Detour.TileCache.Test.Io;
|
||||||
|
@ -29,7 +30,7 @@ namespace DotRecast.Detour.TileCache.Test.Io;
|
||||||
[Parallelizable]
|
[Parallelizable]
|
||||||
public class TileCacheReaderTest
|
public class TileCacheReaderTest
|
||||||
{
|
{
|
||||||
private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared);
|
private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorFactory.Shared);
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestNavmesh()
|
public void TestNavmesh()
|
||||||
|
|
|
@ -22,6 +22,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io;
|
using DotRecast.Detour.TileCache.Io;
|
||||||
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using DotRecast.Recast.Geom;
|
using DotRecast.Recast.Geom;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -31,8 +32,8 @@ namespace DotRecast.Detour.TileCache.Test.Io;
|
||||||
[Parallelizable]
|
[Parallelizable]
|
||||||
public class TileCacheReaderWriterTest : AbstractTileCacheTest
|
public class TileCacheReaderWriterTest : AbstractTileCacheTest
|
||||||
{
|
{
|
||||||
private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared);
|
private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorFactory.Shared);
|
||||||
private readonly DtTileCacheWriter writer = new DtTileCacheWriter(DtTileCacheCompressorForTestFactory.Shared);
|
private readonly DtTileCacheWriter writer = new DtTileCacheWriter(DtTileCacheCompressorFactory.Shared);
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestFastLz()
|
public void TestFastLz()
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class TestTileLayerBuilder : DtTileCacheLayerBuilder
|
||||||
public readonly int tw;
|
public readonly int tw;
|
||||||
public readonly int th;
|
public readonly int th;
|
||||||
|
|
||||||
public TestTileLayerBuilder(IInputGeomProvider geom) : base(DtTileCacheCompressorForTestFactory.Shared)
|
public TestTileLayerBuilder(IInputGeomProvider geom) : base(DtTileCacheCompressorFactory.Shared)
|
||||||
{
|
{
|
||||||
_geom = geom;
|
_geom = geom;
|
||||||
_cfg = new RcConfig(true, m_tileSize, m_tileSize, RcConfig.CalcBorder(AgentRadius, CellSize),
|
_cfg = new RcConfig(true, m_tileSize, m_tileSize, RcConfig.CalcBorder(AgentRadius, CellSize),
|
||||||
|
|
|
@ -22,6 +22,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io;
|
using DotRecast.Detour.TileCache.Io;
|
||||||
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using DotRecast.Detour.TileCache.Test.Io;
|
using DotRecast.Detour.TileCache.Test.Io;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ public class TileCacheFindPathTest : AbstractTileCacheTest
|
||||||
{
|
{
|
||||||
using var msis = new MemoryStream(Loader.ToBytes("dungeon_all_tiles_tilecache.bin"));
|
using var msis = new MemoryStream(Loader.ToBytes("dungeon_all_tiles_tilecache.bin"));
|
||||||
using var @is = new BinaryReader(msis);
|
using var @is = new BinaryReader(msis);
|
||||||
DtTileCache tcC = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared).Read(@is, 6, new TestTileCacheMeshProcess());
|
DtTileCache tcC = new DtTileCacheReader(DtTileCacheCompressorFactory.Shared).Read(@is, 6, new TestTileCacheMeshProcess());
|
||||||
navmesh = tcC.GetNavMesh();
|
navmesh = tcC.GetNavMesh();
|
||||||
query = new DtNavMeshQuery(navmesh);
|
query = new DtNavMeshQuery(navmesh);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
|
using DotRecast.Detour.TileCache.Test.Io;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DotRecast.Detour.TileCache.Test;
|
||||||
|
|
||||||
|
[SetUpFixture]
|
||||||
|
public class TileCacheTestSetUpFixture
|
||||||
|
{
|
||||||
|
[OneTimeSetUp]
|
||||||
|
public void OneTimeSetUp()
|
||||||
|
{
|
||||||
|
// add lz4
|
||||||
|
DtTileCacheCompressorFactory.Shared.TryAdd(1, DtTileCacheLZ4ForTestCompressor.Shared);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue