From 4be459b29696b4753b6c7487c5ffe0b22912a011 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 19 Aug 2023 15:31:51 +0900 Subject: [PATCH] add tile cache compressor factory shared --- .../DtTileCacheLayerBuilder.cs | 2 +- .../Compress/DtTileCacheCompressorFactory.cs | 37 ++++++++++++ .../Compress/IDtTileCacheCompressorFactory.cs | 2 +- .../Io/DtTileCacheReader.cs | 2 +- .../Io/DtTileCacheWriter.cs | 2 +- .../DotRecast.Recast.Demo.csproj | 40 ++++++------- .../Draw/GLCheckerTexture.cs | 2 +- src/DotRecast.Recast.Demo/Draw/GLU.cs | 8 +-- src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs | 2 +- .../Draw/ModernOpenGLDraw.cs | 56 +++++++++---------- .../Draw/OpenGLVertex.cs | 29 +++++++--- .../Draw/RecastDebugDraw.cs | 1 - .../DtTileCacheCompressorDemoFactory.cs | 21 ------- .../DtTileCacheLZ4DemoCompressor.cs | 49 ---------------- .../Messages/IRecastDemoMessage.cs | 1 - .../Messages/NavMeshBuildBeganEvent.cs | 1 - .../Messages/NavMeshSaveBeganEvent.cs | 1 - src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 1 - .../Tools/Gizmos/BoxGizmo.cs | 18 +++--- .../Tools/Gizmos/CapsuleGizmo.cs | 3 +- .../Tools/Gizmos/CylinderGizmo.cs | 3 +- .../Tools/ObstacleTool.cs | 3 +- src/DotRecast.Recast.Demo/UI/RcCanvas.cs | 2 +- src/DotRecast.Recast.Demo/UI/RcLogView.cs | 4 +- src/DotRecast.Recast.Demo/UI/RcToolsetView.cs | 4 +- .../AbstractTileCacheTest.cs | 2 +- .../Io/DtTileCacheCompressorForTestFactory.cs | 21 ------- .../Io/TileCacheReaderTest.cs | 3 +- .../Io/TileCacheReaderWriterTest.cs | 5 +- .../TestTileLayerBuilder.cs | 2 +- .../TileCacheFindPathTest.cs | 3 +- .../TileCacheTestSetUpFixture.cs | 16 ++++++ 32 files changed, 158 insertions(+), 188 deletions(-) create mode 100644 src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs delete mode 100644 src/DotRecast.Recast.Demo/DtTileCacheCompressorDemoFactory.cs delete mode 100644 src/DotRecast.Recast.Demo/DtTileCacheLZ4DemoCompressor.cs delete mode 100644 test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs create mode 100644 test/DotRecast.Detour.TileCache.Test/TileCacheTestSetUpFixture.cs diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs index d382e67..6be9421 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs @@ -127,7 +127,7 @@ namespace DotRecast.Detour.TileCache header.hmin = layer.hmin; 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); result.Add(bytes); } diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs b/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs new file mode 100644 index 0000000..81e215f --- /dev/null +++ b/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheCompressorFactory.cs @@ -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 _compressors = new Dictionary(); + + 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; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs b/src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs index 3f90f06..c0ce433 100644 --- a/src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs +++ b/src/DotRecast.Detour.TileCache/Io/Compress/IDtTileCacheCompressorFactory.cs @@ -24,6 +24,6 @@ namespace DotRecast.Detour.TileCache.Io.Compress { public interface IDtTileCacheCompressorFactory { - IRcCompressor Get(bool cCompatibility); + IRcCompressor Create(int compatibility); } } \ 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 de5a4f0..6ea56d1 100644 --- a/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs +++ b/src/DotRecast.Detour.TileCache/Io/DtTileCacheReader.cs @@ -70,7 +70,7 @@ namespace DotRecast.Detour.TileCache.Io header.meshParams = paramReader.Read(bb); header.cacheParams = ReadCacheParams(bb, cCompatibility); 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); DtTileCache tc = new DtTileCache(header.cacheParams, storageParams, mesh, comp, meshProcessor); // Read tiles. diff --git a/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs b/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs index 71c1ea8..ceaee7b 100644 --- a/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs +++ b/src/DotRecast.Detour.TileCache/Io/DtTileCacheWriter.cs @@ -63,7 +63,7 @@ namespace DotRecast.Detour.TileCache.Io Write(stream, (int)cache.GetTileRef(tile), order); byte[] data = tile.data; DtTileCacheLayer layer = cache.DecompressTile(tile); - var comp = _compFactory.Get(cCompatibility); + var comp = _compFactory.Create(cCompatibility ? 0 : 1); 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 2782a1f..eb9522b 100644 --- a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj +++ b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj @@ -1,25 +1,25 @@ - - Exe - net7.0 - true - + + Exe + net7.0 + true + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - + \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs b/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs index 2ef2c6e..061ab23 100644 --- a/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs +++ b/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs @@ -31,7 +31,7 @@ public class GLCheckerTexture { _gl = gl; } - + public void Release() { if (m_texId != 0) diff --git a/src/DotRecast.Recast.Demo/Draw/GLU.cs b/src/DotRecast.Recast.Demo/Draw/GLU.cs index 166a600..6b91d5e 100644 --- a/src/DotRecast.Recast.Demo/Draw/GLU.cs +++ b/src/DotRecast.Recast.Demo/Draw/GLU.cs @@ -100,17 +100,17 @@ public class GLU result[4] = matrix1[0] * matrix2[4] + matrix1[4] * matrix2[5] + matrix1[8] * matrix2[6] + matrix1[12] * matrix2[7]; result[8] = matrix1[0] * matrix2[8] + matrix1[4] * matrix2[9] + matrix1[8] * matrix2[10] + matrix1[12] * matrix2[11]; result[12] = matrix1[0] * matrix2[12] + matrix1[4] * matrix2[13] + matrix1[8] * matrix2[14] + matrix1[12] * matrix2[15]; - + result[1] = matrix1[1] * matrix2[0] + matrix1[5] * matrix2[1] + matrix1[9] * matrix2[2] + matrix1[13] * matrix2[3]; result[5] = matrix1[1] * matrix2[4] + matrix1[5] * matrix2[5] + matrix1[9] * matrix2[6] + matrix1[13] * matrix2[7]; result[9] = matrix1[1] * matrix2[8] + matrix1[5] * matrix2[9] + matrix1[9] * matrix2[10] + matrix1[13] * matrix2[11]; result[13] = matrix1[1] * matrix2[12] + matrix1[5] * matrix2[13] + matrix1[9] * matrix2[14] + matrix1[13] * matrix2[15]; - + result[2] = matrix1[2] * matrix2[0] + matrix1[6] * matrix2[1] + matrix1[10] * matrix2[2] + matrix1[14] * matrix2[3]; result[6] = matrix1[2] * matrix2[4] + matrix1[6] * matrix2[5] + matrix1[10] * matrix2[6] + matrix1[14] * matrix2[7]; result[10] = matrix1[2] * matrix2[8] + matrix1[6] * matrix2[9] + matrix1[10] * matrix2[10] + matrix1[14] * matrix2[11]; result[14] = matrix1[2] * matrix2[12] + matrix1[6] * matrix2[13] + matrix1[10] * matrix2[14] + matrix1[14] * matrix2[15]; - + result[3] = matrix1[3] * matrix2[0] + matrix1[7] * matrix2[1] + matrix1[11] * matrix2[2] + matrix1[15] * matrix2[3]; result[7] = matrix1[3] * matrix2[4] + matrix1[7] * matrix2[5] + matrix1[11] * matrix2[6] + matrix1[15] * matrix2[7]; result[11] = matrix1[3] * matrix2[8] + matrix1[7] * matrix2[9] + matrix1[11] * matrix2[10] + matrix1[15] * matrix2[11]; @@ -447,4 +447,4 @@ public class GLU return dest; } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs b/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs index 0d47d24..5646fb4 100644 --- a/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs @@ -17,7 +17,7 @@ public interface IOpenGLDraw void Vertex(float[] pos, int color); void Vertex(RcVec3f pos, int color); - + void Vertex(RcVec3f pos, int color, RcVec2f uv); void Vertex(float x, float y, float z, int color, float u, float v); diff --git a/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs b/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs index 09a6ca8..ebc7536 100644 --- a/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs @@ -39,34 +39,34 @@ public class ModernOpenGLDraw : IOpenGLDraw { string SHADER_VERSION = "#version 400\n"; string vertex_shader = SHADER_VERSION + "uniform mat4 ProjMtx;\n" // - + "uniform mat4 ViewMtx;\n" // - + "in vec3 Position;\n" // - + "in vec2 TexCoord;\n" // - + "in vec4 Color;\n" // - + "out vec2 Frag_UV;\n" // - + "out vec4 Frag_Color;\n" // - + "out float Frag_Depth;\n" // - + "void main() {\n" // - + " Frag_UV = TexCoord;\n" // - + " Frag_Color = Color;\n" // - + " vec4 VSPosition = ViewMtx * vec4(Position, 1);\n" // - + " Frag_Depth = -VSPosition.z;\n" // - + " gl_Position = ProjMtx * VSPosition;\n" // - + "}\n"; + + "uniform mat4 ViewMtx;\n" // + + "in vec3 Position;\n" // + + "in vec2 TexCoord;\n" // + + "in vec4 Color;\n" // + + "out vec2 Frag_UV;\n" // + + "out vec4 Frag_Color;\n" // + + "out float Frag_Depth;\n" // + + "void main() {\n" // + + " Frag_UV = TexCoord;\n" // + + " Frag_Color = Color;\n" // + + " vec4 VSPosition = ViewMtx * vec4(Position, 1);\n" // + + " Frag_Depth = -VSPosition.z;\n" // + + " gl_Position = ProjMtx * VSPosition;\n" // + + "}\n"; string fragment_shader = SHADER_VERSION + "precision mediump float;\n" // - + "uniform sampler2D Texture;\n" // - + "uniform float UseTexture;\n" // - + "uniform float EnableFog;\n" // - + "uniform float FogStart;\n" // - + "uniform float FogEnd;\n" // - + "const vec4 FogColor = vec4(0.3f, 0.3f, 0.32f, 1.0f);\n" // - + "in vec2 Frag_UV;\n" // - + "in vec4 Frag_Color;\n" // - + "in float Frag_Depth;\n" // - + "out vec4 Out_Color;\n" // - + "void main(){\n" // - + " Out_Color = mix(FogColor, Frag_Color * mix(vec4(1), texture(Texture, Frag_UV.st), UseTexture), 1.0 - EnableFog * clamp( (Frag_Depth - FogStart) / (FogEnd - FogStart), 0.0, 1.0) );\n" // - + "}\n"; + + "uniform sampler2D Texture;\n" // + + "uniform float UseTexture;\n" // + + "uniform float EnableFog;\n" // + + "uniform float FogStart;\n" // + + "uniform float FogEnd;\n" // + + "const vec4 FogColor = vec4(0.3f, 0.3f, 0.32f, 1.0f);\n" // + + "in vec2 Frag_UV;\n" // + + "in vec4 Frag_Color;\n" // + + "in float Frag_Depth;\n" // + + "out vec4 Out_Color;\n" // + + "void main(){\n" // + + " Out_Color = mix(FogColor, Frag_Color * mix(vec4(1), texture(Texture, Frag_UV.st), UseTexture), 1.0 - EnableFog * clamp( (Frag_Depth - FogStart) / (FogEnd - FogStart), 0.0, 1.0) );\n" // + + "}\n"; program = _gl.CreateProgram(); uint vert_shdr = _gl.CreateShader(GLEnum.VertexShader); @@ -285,7 +285,7 @@ public class ModernOpenGLDraw : IOpenGLDraw { vertices.Add(new OpenGLVertex(pos, color)); } - + public void Vertex(RcVec3f pos, int color) { vertices.Add(new OpenGLVertex(pos, color)); diff --git a/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs b/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs index 1733d17..e33d6b4 100644 --- a/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs +++ b/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs @@ -8,12 +8,23 @@ namespace DotRecast.Recast.Demo.Draw; [StructLayout(LayoutKind.Explicit, Pack = 1)] public struct OpenGLVertex { - [FieldOffset(0)] private readonly float x; - [FieldOffset(4)] private readonly float y; - [FieldOffset(8)] private readonly float z; - [FieldOffset(12)] private readonly float u; - [FieldOffset(16)] private readonly float v; - [FieldOffset(20)] private readonly int color; + [FieldOffset(0)] + private readonly float x; + + [FieldOffset(4)] + private readonly float y; + + [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) : this(pos.x, pos.y, pos.z, uv.x, uv.y, color) @@ -24,7 +35,7 @@ public struct OpenGLVertex this(pos[0], pos[1], pos[2], 0f, 0f, color) { } - + public OpenGLVertex(RcVec3f pos, int color) : this(pos.x, pos.y, pos.z, 0f, 0f, color) { @@ -54,7 +65,7 @@ public struct OpenGLVertex // writer.Write(BitConverter.GetBytes(u)); // writer.Write(BitConverter.GetBytes(v)); // writer.Write(BitConverter.GetBytes(color)); - + writer.Write(x); writer.Write(y); writer.Write(z); @@ -62,4 +73,4 @@ public struct OpenGLVertex writer.Write(v); writer.Write(color); } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs index 710f744..0d07308 100644 --- a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs @@ -23,7 +23,6 @@ using System.Collections.Generic; using System.Numerics; using DotRecast.Core; using DotRecast.Detour; - using DotRecast.Recast.Toolset.Builder; using Silk.NET.OpenGL; diff --git a/src/DotRecast.Recast.Demo/DtTileCacheCompressorDemoFactory.cs b/src/DotRecast.Recast.Demo/DtTileCacheCompressorDemoFactory.cs deleted file mode 100644 index 361b90e..0000000 --- a/src/DotRecast.Recast.Demo/DtTileCacheCompressorDemoFactory.cs +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/DtTileCacheLZ4DemoCompressor.cs b/src/DotRecast.Recast.Demo/DtTileCacheLZ4DemoCompressor.cs deleted file mode 100644 index 6056687..0000000 --- a/src/DotRecast.Recast.Demo/DtTileCacheLZ4DemoCompressor.cs +++ /dev/null @@ -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); - } - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs b/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs index 7ec17aa..810ffc9 100644 --- a/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs +++ b/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs @@ -2,5 +2,4 @@ public class IRecastDemoMessage { - } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs b/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs index 96db561..2388c72 100644 --- a/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs +++ b/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs @@ -2,5 +2,4 @@ public class NavMeshBuildBeganEvent : IRecastDemoMessage { - } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs b/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs index b9ea7d1..1f32146 100644 --- a/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs +++ b/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs @@ -2,5 +2,4 @@ public class NavMeshSaveBeganEvent : IRecastDemoMessage { - } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index de87a9c..7160759 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -24,7 +24,6 @@ using DotRecast.Core; using DotRecast.Detour; using DotRecast.Detour.Crowd; using DotRecast.Detour.Crowd.Tracking; - using DotRecast.Recast.Toolset.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; diff --git a/src/DotRecast.Recast.Demo/Tools/Gizmos/BoxGizmo.cs b/src/DotRecast.Recast.Demo/Tools/Gizmos/BoxGizmo.cs index af8f111..1f8f91c 100644 --- a/src/DotRecast.Recast.Demo/Tools/Gizmos/BoxGizmo.cs +++ b/src/DotRecast.Recast.Demo/Tools/Gizmos/BoxGizmo.cs @@ -14,14 +14,14 @@ public class BoxGizmo : IColliderGizmo private static readonly RcVec3f[] VERTS = { - RcVec3f.Of( -1f, -1f, -1f), - RcVec3f.Of( 1f, -1f, -1f), - RcVec3f.Of( 1f, -1f, 1f), - RcVec3f.Of( -1f, -1f, 1f), - RcVec3f.Of( -1f, 1f, -1f), - RcVec3f.Of( 1f, 1f, -1f), - RcVec3f.Of( 1f, 1f, 1f), - RcVec3f.Of( -1f, 1f, 1f), + RcVec3f.Of(-1f, -1f, -1f), + RcVec3f.Of(1f, -1f, -1f), + RcVec3f.Of(1f, -1f, 1f), + RcVec3f.Of(-1f, -1f, 1f), + RcVec3f.Of(-1f, 1f, -1f), + RcVec3f.Of(1f, 1f, -1f), + RcVec3f.Of(1f, 1f, 1f), + RcVec3f.Of(-1f, 1f, 1f), }; private readonly float[] vertices = new float[8 * 3]; @@ -83,4 +83,4 @@ public class BoxGizmo : IColliderGizmo debugDraw.End(); } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/Gizmos/CapsuleGizmo.cs b/src/DotRecast.Recast.Demo/Tools/Gizmos/CapsuleGizmo.cs index 624ff6c..2f59554 100644 --- a/src/DotRecast.Recast.Demo/Tools/Gizmos/CapsuleGizmo.cs +++ b/src/DotRecast.Recast.Demo/Tools/Gizmos/CapsuleGizmo.cs @@ -1,6 +1,5 @@ using DotRecast.Core; using DotRecast.Recast.Demo.Draw; - using static DotRecast.Core.RcMath; using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper; @@ -86,4 +85,4 @@ public class CapsuleGizmo : IColliderGizmo debugDraw.End(); } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/Gizmos/CylinderGizmo.cs b/src/DotRecast.Recast.Demo/Tools/Gizmos/CylinderGizmo.cs index 5989278..0a3d455 100644 --- a/src/DotRecast.Recast.Demo/Tools/Gizmos/CylinderGizmo.cs +++ b/src/DotRecast.Recast.Demo/Tools/Gizmos/CylinderGizmo.cs @@ -1,6 +1,5 @@ using DotRecast.Core; using DotRecast.Recast.Demo.Draw; - using static DotRecast.Core.RcMath; using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper; @@ -92,4 +91,4 @@ public class CylinderGizmo : IColliderGizmo debugDraw.End(); } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs b/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs index 1293007..a1c4a97 100644 --- a/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs @@ -1,4 +1,5 @@ using DotRecast.Core; +using DotRecast.Detour.TileCache.Io.Compress; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; using DotRecast.Recast.Toolset.Tools; @@ -16,7 +17,7 @@ public class ObstacleTool : IRcTool public ObstacleTool() { - _impl = new(DtTileCacheCompressorDemoFactory.Shared); + _impl = new(DtTileCacheCompressorFactory.Shared); } public ISampleTool GetTool() diff --git a/src/DotRecast.Recast.Demo/UI/RcCanvas.cs b/src/DotRecast.Recast.Demo/UI/RcCanvas.cs index f53c496..c2ba9e0 100644 --- a/src/DotRecast.Recast.Demo/UI/RcCanvas.cs +++ b/src/DotRecast.Recast.Demo/UI/RcCanvas.cs @@ -34,7 +34,7 @@ public class RcCanvas private readonly IWindow _window; private readonly IRcView[] _views; private bool _mouseOver; - + public bool IsMouseOver() => _mouseOver; public Vector2D Size => _window.Size; diff --git a/src/DotRecast.Recast.Demo/UI/RcLogView.cs b/src/DotRecast.Recast.Demo/UI/RcLogView.cs index c66df0d..85e5bec 100644 --- a/src/DotRecast.Recast.Demo/UI/RcLogView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcLogView.cs @@ -68,7 +68,7 @@ public class RcLogView : IRcView ImGui.End(); return; } - + // size reset var size = ImGui.GetItemRectSize(); if (32 >= size.X && 32 >= size.Y) @@ -78,7 +78,7 @@ public class RcLogView : IRcView var width = _canvas.Size.X - (otherWidth * 2); //var posX = _canvas.Size.X - width; // ImGui.SetNextWindowPos(new Vector2(otherWidth1, _canvas.Size.Y - height)); - ImGui.SetWindowSize(new Vector2(width, height)); + ImGui.SetWindowSize(new Vector2(width, height)); } diff --git a/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs b/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs index 3d9bbe7..77e18b6 100644 --- a/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs @@ -56,7 +56,7 @@ public class RcToolsetView : IRcView public void Draw(double dt) { ImGui.Begin("Tools"); - + // size reset var size = ImGui.GetItemRectSize(); if (32 >= size.X && 32 >= size.Y) @@ -65,7 +65,7 @@ public class RcToolsetView : IRcView //ImGui.SetWindowPos(new Vector2(0, 0)); ImGui.SetWindowSize(new Vector2(width, _canvas.Size.Y)); } - + _isHovered = ImGui.IsWindowHovered(ImGuiHoveredFlags.RectOnly | ImGuiHoveredFlags.RootAndChildWindows); for (int i = 0; i < tools.Length; ++i) diff --git a/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs b/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs index eaa280b..9266838 100644 --- a/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs @@ -67,7 +67,7 @@ public class AbstractTileCacheTest navMeshParams.maxPolys = 16384; 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 process = new TestTileCacheMeshProcess(); DtTileCache tc = new DtTileCache(option, storageParams, navMesh, comp, process); diff --git a/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs b/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs deleted file mode 100644 index b8272c4..0000000 --- a/test/DotRecast.Detour.TileCache.Test/Io/DtTileCacheCompressorForTestFactory.cs +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs index b959d71..c5c4ab3 100644 --- a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderTest.cs @@ -22,6 +22,7 @@ using System; using System.IO; using DotRecast.Core; using DotRecast.Detour.TileCache.Io; +using DotRecast.Detour.TileCache.Io.Compress; using NUnit.Framework; namespace DotRecast.Detour.TileCache.Test.Io; @@ -29,7 +30,7 @@ namespace DotRecast.Detour.TileCache.Test.Io; [Parallelizable] public class TileCacheReaderTest { - private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared); + private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorFactory.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 d3334e9..cda5b18 100644 --- a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.IO; using DotRecast.Core; using DotRecast.Detour.TileCache.Io; +using DotRecast.Detour.TileCache.Io.Compress; using DotRecast.Recast; using DotRecast.Recast.Geom; using NUnit.Framework; @@ -31,8 +32,8 @@ namespace DotRecast.Detour.TileCache.Test.Io; [Parallelizable] public class TileCacheReaderWriterTest : AbstractTileCacheTest { - private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorForTestFactory.Shared); - private readonly DtTileCacheWriter writer = new DtTileCacheWriter(DtTileCacheCompressorForTestFactory.Shared); + private readonly DtTileCacheReader reader = new DtTileCacheReader(DtTileCacheCompressorFactory.Shared); + private readonly DtTileCacheWriter writer = new DtTileCacheWriter(DtTileCacheCompressorFactory.Shared); [Test] public void TestFastLz() diff --git a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs index 67f8a76..675860f 100644 --- a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs +++ b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs @@ -56,7 +56,7 @@ public class TestTileLayerBuilder : DtTileCacheLayerBuilder public readonly int tw; public readonly int th; - public TestTileLayerBuilder(IInputGeomProvider geom) : base(DtTileCacheCompressorForTestFactory.Shared) + public TestTileLayerBuilder(IInputGeomProvider geom) : base(DtTileCacheCompressorFactory.Shared) { _geom = geom; _cfg = new RcConfig(true, m_tileSize, m_tileSize, RcConfig.CalcBorder(AgentRadius, CellSize), diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs index c3da135..1a7f46d 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.Io.Compress; using DotRecast.Detour.TileCache.Test.Io; 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 @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(); query = new DtNavMeshQuery(navmesh); } diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheTestSetUpFixture.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheTestSetUpFixture.cs new file mode 100644 index 0000000..8eb417b --- /dev/null +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheTestSetUpFixture.cs @@ -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); + } +} \ No newline at end of file