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);
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Serilog" Version="3.0.1" />
|
<PackageReference Include="Serilog" Version="3.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
||||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
|
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.6" />
|
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.6" />
|
||||||
<PackageReference Include="Silk.NET" Version="2.17.1" />
|
<PackageReference Include="Silk.NET" Version="2.17.1" />
|
||||||
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.17.1" />
|
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.17.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DotRecast.Recast.Toolset\DotRecast.Recast.Toolset.csproj" />
|
<ProjectReference Include="..\DotRecast.Recast.Toolset\DotRecast.Recast.Toolset.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
|
@ -31,7 +31,7 @@ public class GLCheckerTexture
|
||||||
{
|
{
|
||||||
_gl = gl;
|
_gl = gl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Release()
|
public void Release()
|
||||||
{
|
{
|
||||||
if (m_texId != 0)
|
if (m_texId != 0)
|
||||||
|
|
|
@ -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[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[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[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[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[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[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[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[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[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[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[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[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[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];
|
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;
|
return dest;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ public interface IOpenGLDraw
|
||||||
|
|
||||||
void Vertex(float[] pos, int color);
|
void Vertex(float[] pos, int color);
|
||||||
void Vertex(RcVec3f pos, int color);
|
void Vertex(RcVec3f pos, int color);
|
||||||
|
|
||||||
void Vertex(RcVec3f pos, int color, RcVec2f uv);
|
void Vertex(RcVec3f pos, int color, RcVec2f uv);
|
||||||
|
|
||||||
void Vertex(float x, float y, float z, int color, float u, float v);
|
void Vertex(float x, float y, float z, int color, float u, float v);
|
||||||
|
|
|
@ -39,34 +39,34 @@ public class ModernOpenGLDraw : IOpenGLDraw
|
||||||
{
|
{
|
||||||
string SHADER_VERSION = "#version 400\n";
|
string SHADER_VERSION = "#version 400\n";
|
||||||
string vertex_shader = SHADER_VERSION + "uniform mat4 ProjMtx;\n" //
|
string vertex_shader = SHADER_VERSION + "uniform mat4 ProjMtx;\n" //
|
||||||
+ "uniform mat4 ViewMtx;\n" //
|
+ "uniform mat4 ViewMtx;\n" //
|
||||||
+ "in vec3 Position;\n" //
|
+ "in vec3 Position;\n" //
|
||||||
+ "in vec2 TexCoord;\n" //
|
+ "in vec2 TexCoord;\n" //
|
||||||
+ "in vec4 Color;\n" //
|
+ "in vec4 Color;\n" //
|
||||||
+ "out vec2 Frag_UV;\n" //
|
+ "out vec2 Frag_UV;\n" //
|
||||||
+ "out vec4 Frag_Color;\n" //
|
+ "out vec4 Frag_Color;\n" //
|
||||||
+ "out float Frag_Depth;\n" //
|
+ "out float Frag_Depth;\n" //
|
||||||
+ "void main() {\n" //
|
+ "void main() {\n" //
|
||||||
+ " Frag_UV = TexCoord;\n" //
|
+ " Frag_UV = TexCoord;\n" //
|
||||||
+ " Frag_Color = Color;\n" //
|
+ " Frag_Color = Color;\n" //
|
||||||
+ " vec4 VSPosition = ViewMtx * vec4(Position, 1);\n" //
|
+ " vec4 VSPosition = ViewMtx * vec4(Position, 1);\n" //
|
||||||
+ " Frag_Depth = -VSPosition.z;\n" //
|
+ " Frag_Depth = -VSPosition.z;\n" //
|
||||||
+ " gl_Position = ProjMtx * VSPosition;\n" //
|
+ " gl_Position = ProjMtx * VSPosition;\n" //
|
||||||
+ "}\n";
|
+ "}\n";
|
||||||
string fragment_shader = SHADER_VERSION + "precision mediump float;\n" //
|
string fragment_shader = SHADER_VERSION + "precision mediump float;\n" //
|
||||||
+ "uniform sampler2D Texture;\n" //
|
+ "uniform sampler2D Texture;\n" //
|
||||||
+ "uniform float UseTexture;\n" //
|
+ "uniform float UseTexture;\n" //
|
||||||
+ "uniform float EnableFog;\n" //
|
+ "uniform float EnableFog;\n" //
|
||||||
+ "uniform float FogStart;\n" //
|
+ "uniform float FogStart;\n" //
|
||||||
+ "uniform float FogEnd;\n" //
|
+ "uniform float FogEnd;\n" //
|
||||||
+ "const vec4 FogColor = vec4(0.3f, 0.3f, 0.32f, 1.0f);\n" //
|
+ "const vec4 FogColor = vec4(0.3f, 0.3f, 0.32f, 1.0f);\n" //
|
||||||
+ "in vec2 Frag_UV;\n" //
|
+ "in vec2 Frag_UV;\n" //
|
||||||
+ "in vec4 Frag_Color;\n" //
|
+ "in vec4 Frag_Color;\n" //
|
||||||
+ "in float Frag_Depth;\n" //
|
+ "in float Frag_Depth;\n" //
|
||||||
+ "out vec4 Out_Color;\n" //
|
+ "out vec4 Out_Color;\n" //
|
||||||
+ "void main(){\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" //
|
+ " 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";
|
+ "}\n";
|
||||||
|
|
||||||
program = _gl.CreateProgram();
|
program = _gl.CreateProgram();
|
||||||
uint vert_shdr = _gl.CreateShader(GLEnum.VertexShader);
|
uint vert_shdr = _gl.CreateShader(GLEnum.VertexShader);
|
||||||
|
@ -285,7 +285,7 @@ public class ModernOpenGLDraw : IOpenGLDraw
|
||||||
{
|
{
|
||||||
vertices.Add(new OpenGLVertex(pos, color));
|
vertices.Add(new OpenGLVertex(pos, color));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Vertex(RcVec3f pos, int color)
|
public void Vertex(RcVec3f pos, int color)
|
||||||
{
|
{
|
||||||
vertices.Add(new OpenGLVertex(pos, color));
|
vertices.Add(new OpenGLVertex(pos, color));
|
||||||
|
|
|
@ -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)
|
||||||
|
@ -24,7 +35,7 @@ public struct OpenGLVertex
|
||||||
this(pos[0], pos[1], pos[2], 0f, 0f, color)
|
this(pos[0], pos[1], pos[2], 0f, 0f, color)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenGLVertex(RcVec3f pos, int color) :
|
public OpenGLVertex(RcVec3f pos, int color) :
|
||||||
this(pos.x, pos.y, pos.z, 0f, 0f, 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(u));
|
||||||
// writer.Write(BitConverter.GetBytes(v));
|
// writer.Write(BitConverter.GetBytes(v));
|
||||||
// writer.Write(BitConverter.GetBytes(color));
|
// writer.Write(BitConverter.GetBytes(color));
|
||||||
|
|
||||||
writer.Write(x);
|
writer.Write(x);
|
||||||
writer.Write(y);
|
writer.Write(y);
|
||||||
writer.Write(z);
|
writer.Write(z);
|
||||||
|
@ -62,4 +73,4 @@ public struct OpenGLVertex
|
||||||
writer.Write(v);
|
writer.Write(v);
|
||||||
writer.Write(color);
|
writer.Write(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;
|
||||||
|
|
|
@ -14,14 +14,14 @@ public class BoxGizmo : IColliderGizmo
|
||||||
|
|
||||||
private static readonly RcVec3f[] VERTS =
|
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];
|
private readonly float[] vertices = new float[8 * 3];
|
||||||
|
@ -83,4 +83,4 @@ public class BoxGizmo : IColliderGizmo
|
||||||
|
|
||||||
debugDraw.End();
|
debugDraw.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -86,4 +85,4 @@ public class CapsuleGizmo : IColliderGizmo
|
||||||
|
|
||||||
debugDraw.End();
|
debugDraw.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -92,4 +91,4 @@ public class CylinderGizmo : IColliderGizmo
|
||||||
|
|
||||||
debugDraw.End();
|
debugDraw.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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()
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class RcCanvas
|
||||||
private readonly IWindow _window;
|
private readonly IWindow _window;
|
||||||
private readonly IRcView[] _views;
|
private readonly IRcView[] _views;
|
||||||
private bool _mouseOver;
|
private bool _mouseOver;
|
||||||
|
|
||||||
public bool IsMouseOver() => _mouseOver;
|
public bool IsMouseOver() => _mouseOver;
|
||||||
|
|
||||||
public Vector2D<int> Size => _window.Size;
|
public Vector2D<int> Size => _window.Size;
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class RcLogView : IRcView
|
||||||
ImGui.End();
|
ImGui.End();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// size reset
|
// size reset
|
||||||
var size = ImGui.GetItemRectSize();
|
var size = ImGui.GetItemRectSize();
|
||||||
if (32 >= size.X && 32 >= size.Y)
|
if (32 >= size.X && 32 >= size.Y)
|
||||||
|
@ -78,7 +78,7 @@ public class RcLogView : IRcView
|
||||||
var width = _canvas.Size.X - (otherWidth * 2);
|
var width = _canvas.Size.X - (otherWidth * 2);
|
||||||
//var posX = _canvas.Size.X - width;
|
//var posX = _canvas.Size.X - width;
|
||||||
// ImGui.SetNextWindowPos(new Vector2(otherWidth1, _canvas.Size.Y - height));
|
// ImGui.SetNextWindowPos(new Vector2(otherWidth1, _canvas.Size.Y - height));
|
||||||
ImGui.SetWindowSize(new Vector2(width, height));
|
ImGui.SetWindowSize(new Vector2(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class RcToolsetView : IRcView
|
||||||
public void Draw(double dt)
|
public void Draw(double dt)
|
||||||
{
|
{
|
||||||
ImGui.Begin("Tools");
|
ImGui.Begin("Tools");
|
||||||
|
|
||||||
// size reset
|
// size reset
|
||||||
var size = ImGui.GetItemRectSize();
|
var size = ImGui.GetItemRectSize();
|
||||||
if (32 >= size.X && 32 >= size.Y)
|
if (32 >= size.X && 32 >= size.Y)
|
||||||
|
@ -65,7 +65,7 @@ public class RcToolsetView : IRcView
|
||||||
//ImGui.SetWindowPos(new Vector2(0, 0));
|
//ImGui.SetWindowPos(new Vector2(0, 0));
|
||||||
ImGui.SetWindowSize(new Vector2(width, _canvas.Size.Y));
|
ImGui.SetWindowSize(new Vector2(width, _canvas.Size.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
_isHovered = ImGui.IsWindowHovered(ImGuiHoveredFlags.RectOnly | ImGuiHoveredFlags.RootAndChildWindows);
|
_isHovered = ImGui.IsWindowHovered(ImGuiHoveredFlags.RectOnly | ImGuiHoveredFlags.RootAndChildWindows);
|
||||||
|
|
||||||
for (int i = 0; i < tools.Length; ++i)
|
for (int i = 0; i < tools.Length; ++i)
|
||||||
|
|
|
@ -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