From bf6ee495d24c4321f9eb649202777aeebb687b0f Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 24 Apr 2024 23:40:11 +0900 Subject: [PATCH 1/8] upgrade Silk.NET 2.20.0 -> 2.21.0 --- src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj index 399aa50..15c6da7 100644 --- a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj +++ b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj @@ -2,7 +2,7 @@ Exe - net6.0;net7.0;net8.0 + net8.0 true DotRecast.Recast.Demo README.md @@ -27,8 +27,8 @@ - - + + From 4a80473e2f9125ac3813bb3bacfd0a31bdb045e5 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 25 Apr 2024 00:02:27 +0900 Subject: [PATCH 2/8] fix workflow --- .github/workflows/dotnet.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 972fa7a..aac3f76 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -45,7 +45,9 @@ jobs: run: dotnet restore - name: Build - run: dotnet build -c Release --no-restore --framework net${{ matrix.dotnet-version }}.0 + run: | + dotnet restore + dotnet build -c Release --no-restore --framework net${{ matrix.dotnet-version }}.0 - name: Test run: dotnet test -c Release --no-build --verbosity normal --framework net${{ matrix.dotnet-version }}.0 From f22ec940389df80779c7ba034d0c2fc5f7d8be26 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 25 Apr 2024 00:59:02 +0900 Subject: [PATCH 3/8] support C# 10, 11 in DotRecast.Recast.Demo --- .github/workflows/codeql.yml | 2 +- .github/workflows/dotnet.yml | 6 ++---- .github/workflows/publish.yml | 2 +- .github/workflows/release.yml | 2 +- .../DotRecast.Recast.Demo.csproj | 2 +- .../Draw/GLCheckerTexture.cs | 21 +++++++++++++------ 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1001d74..0093ad1 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -49,7 +49,7 @@ jobs: uses: actions/checkout@v4 - name: Set up .NET 8.0 - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 8.x diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index aac3f76..af233a5 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -37,7 +37,7 @@ jobs: fetch-depth: 0 # Get all history to allow automatic versioning using MinVer - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ matrix.dotnet-version }}.x @@ -45,9 +45,7 @@ jobs: run: dotnet restore - name: Build - run: | - dotnet restore - dotnet build -c Release --no-restore --framework net${{ matrix.dotnet-version }}.0 + run: dotnet build -c Release --no-restore --framework net${{ matrix.dotnet-version }}.0 - name: Test run: dotnet test -c Release --no-build --verbosity normal --framework net${{ matrix.dotnet-version }}.0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a849a60..f00fc9f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,7 +33,7 @@ jobs: fetch-depth: 0 # Get all history to allow automatic versioning using MinVer - name: Setup Dotnet - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '8.x' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f14ed1..2e75fbe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: fetch-depth: 0 # Get all history to allow automatic versioning using MinVer - name: Setup Dotnet - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '8.x' diff --git a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj index 15c6da7..b231327 100644 --- a/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj +++ b/src/DotRecast.Recast.Demo/DotRecast.Recast.Demo.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net6.0;net7.0;net8.0 true DotRecast.Recast.Demo README.md diff --git a/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs b/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs index 061ab23..e044757 100644 --- a/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs +++ b/src/DotRecast.Recast.Demo/Draw/GLCheckerTexture.cs @@ -32,15 +32,18 @@ public class GLCheckerTexture _gl = gl; } - public void Release() + public unsafe void Release() { if (m_texId != 0) { - _gl.DeleteTextures(1, m_texId); + fixed (uint* p = &m_texId) + { + _gl.DeleteTextures(1, p); + } } } - public void Bind() + public unsafe void Bind() { if (m_texId == 0) { @@ -50,7 +53,11 @@ public class GLCheckerTexture uint TSIZE = 64; int[] data = new int[TSIZE * TSIZE]; - _gl.GenTextures(1, out m_texId); + fixed (uint* p = &m_texId) + { + _gl.GenTextures(1, p); + } + _gl.BindTexture(GLEnum.Texture2D, m_texId); int level = 0; @@ -70,8 +77,10 @@ public class GLCheckerTexture level++; } - _gl.TexParameterI(GLEnum.Texture2D, GLEnum.TextureMinFilter, (uint)GLEnum.LinearMipmapNearest); - _gl.TexParameterI(GLEnum.Texture2D, GLEnum.TextureMagFilter, (uint)GLEnum.Linear); + uint linearMipmapNearest = (uint)GLEnum.LinearMipmapNearest; + uint linear = (uint)GLEnum.Linear; + _gl.TexParameterI(GLEnum.Texture2D, GLEnum.TextureMinFilter, &linearMipmapNearest); + _gl.TexParameterI(GLEnum.Texture2D, GLEnum.TextureMagFilter, &linear); } else { From 97777511a7e82f679942b22745c22916cc37a376 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 25 Apr 2024 01:18:04 +0900 Subject: [PATCH 4/8] Added the keepInterResults option to RcBuilder.Build() - https://github.com/ikpil/DotRecast/issues/66 --- src/DotRecast.Detour.Dynamic/DtDynamicTile.cs | 2 +- .../Builder/SoloNavMeshBuilder.cs | 17 +--------- src/DotRecast.Recast/RcBuilder.cs | 33 +++++++++---------- .../RecastTestMeshBuilder.cs | 2 +- .../RecastTestMeshBuilder.cs | 2 +- .../TestDetourBuilder.cs | 2 +- .../RecastTileMeshTest.cs | 12 +++---- 7 files changed, 26 insertions(+), 44 deletions(-) diff --git a/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs b/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs index 7712497..4f31dcd 100644 --- a/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs +++ b/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs @@ -100,7 +100,7 @@ namespace DotRecast.Detour.Dynamic Math.Min(DtDynamicNavMesh.MAX_VERTS_PER_POLY, config.vertsPerPoly), config.detailSampleDistance, config.detailSampleMaxError, true, true, true, default, true); - RcBuilderResult r = builder.Build(context, vt.tileX, vt.tileZ, null, rcConfig, heightfield); + RcBuilderResult r = builder.Build(context, vt.tileX, vt.tileZ, null, rcConfig, heightfield, false); if (config.keepIntermediateResults) { recastResult = r; diff --git a/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs b/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs index 71d2c0f..10b4c09 100644 --- a/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs +++ b/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs @@ -80,22 +80,7 @@ namespace DotRecast.Recast.Toolset.Builder { RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax()); RcBuilder rcBuilder = new RcBuilder(); - var result = rcBuilder.Build(geom, bcfg); - if (!keepInterResults) - { - return new RcBuilderResult( - result.TileX, - result.TileZ, - null, - null, - null, - result.Mesh, - result.MeshDetail, - result.Context - ); - } - - return result; + return rcBuilder.Build(geom, bcfg, keepInterResults); } public DtMeshData BuildMeshData(DemoInputGeomProvider geom, diff --git a/src/DotRecast.Recast/RcBuilder.cs b/src/DotRecast.Recast/RcBuilder.cs index 8cad533..0620809 100644 --- a/src/DotRecast.Recast/RcBuilder.cs +++ b/src/DotRecast.Recast/RcBuilder.cs @@ -132,30 +132,17 @@ namespace DotRecast.Recast public RcBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tx, int ty, RcAtomicInteger progress, int total, bool keepInterResults) { var bcfg = new RcBuilderConfig(cfg, bmin, bmax, tx, ty); - RcBuilderResult result = Build(geom, bcfg); + RcBuilderResult result = Build(geom, bcfg, keepInterResults); if (_progressListener != null) { _progressListener.OnProgress(progress.IncrementAndGet(), total); } - if (!keepInterResults) - { - return new RcBuilderResult( - result.TileX, - result.TileZ, - null, - null, - null, - result.Mesh, - result.MeshDetail, - result.Context - ); - } return result; } - public RcBuilderResult Build(IInputGeomProvider geom, RcBuilderConfig bcfg) + public RcBuilderResult Build(IInputGeomProvider geom, RcBuilderConfig bcfg, bool keepInterResults) { RcConfig cfg = bcfg.cfg; RcContext ctx = new RcContext(); @@ -163,10 +150,10 @@ namespace DotRecast.Recast // Step 1. Rasterize input polygon soup. // RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, bcfg); - return Build(ctx, bcfg.tileX, bcfg.tileZ, geom, cfg, solid); + return Build(ctx, bcfg.tileX, bcfg.tileZ, geom, cfg, solid, keepInterResults); } - public RcBuilderResult Build(RcContext ctx, int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid) + public RcBuilderResult Build(RcContext ctx, int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid, bool keepInterResults) { FilterHeightfield(ctx, solid, cfg); RcCompactHeightfield chf = BuildCompactHeightfield(ctx, geom, cfg, solid); @@ -237,7 +224,17 @@ namespace DotRecast.Recast RcPolyMeshDetail dmesh = cfg.BuildMeshDetail ? RcMeshDetails.BuildPolyMeshDetail(ctx, pmesh, chf, cfg.DetailSampleDist, cfg.DetailSampleMaxError) : null; - return new RcBuilderResult(tileX, tileZ, solid, chf, cset, pmesh, dmesh, ctx); + + return new RcBuilderResult( + tileX, + tileZ, + keepInterResults ? solid : null, + keepInterResults ? chf : null, + keepInterResults ? cset : null, + pmesh, + dmesh, + ctx + ); } /* diff --git a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs index 7fd70c3..bacecb9 100644 --- a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs @@ -72,7 +72,7 @@ public class RecastTestMeshBuilder SampleAreaModifications.SAMPLE_AREAMOD_GROUND, true); RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax()); RcBuilder rcBuilder = new RcBuilder(); - RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg); + RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg, false); RcPolyMesh m_pmesh = rcResult.Mesh; for (int i = 0; i < m_pmesh.npolys; ++i) { diff --git a/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs index b1830bb..12c618e 100644 --- a/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs @@ -72,7 +72,7 @@ public class RecastTestMeshBuilder SampleAreaModifications.SAMPLE_AREAMOD_GROUND, true); RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax()); RcBuilder rcBuilder = new RcBuilder(); - RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg); + RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg, false); RcPolyMesh m_pmesh = rcResult.Mesh; for (int i = 0; i < m_pmesh.npolys; ++i) { diff --git a/test/DotRecast.Detour.Test/TestDetourBuilder.cs b/test/DotRecast.Detour.Test/TestDetourBuilder.cs index d7b9268..4df7c6d 100644 --- a/test/DotRecast.Detour.Test/TestDetourBuilder.cs +++ b/test/DotRecast.Detour.Test/TestDetourBuilder.cs @@ -27,7 +27,7 @@ public class TestDetourBuilder : DetourBuilder float agentMaxClimb, int x, int y, bool applyRecastDemoFlags) { RcBuilder rcBuilder = new RcBuilder(); - RcBuilderResult rcResult = rcBuilder.Build(geom, rcConfig); + RcBuilderResult rcResult = rcBuilder.Build(geom, rcConfig, false); RcPolyMesh pmesh = rcResult.Mesh; if (applyRecastDemoFlags) diff --git a/test/DotRecast.Recast.Test/RecastTileMeshTest.cs b/test/DotRecast.Recast.Test/RecastTileMeshTest.cs index 8d98546..6fa4676 100644 --- a/test/DotRecast.Recast.Test/RecastTileMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastTileMeshTest.cs @@ -69,27 +69,27 @@ public class RecastTileMeshTest true, true, true, SampleAreaModifications.SAMPLE_AREAMOD_GROUND, true); RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), 7, 8); - RcBuilderResult rcResult = builder.Build(geom, bcfg); + RcBuilderResult rcResult = builder.Build(geom, bcfg, false); Assert.That(rcResult.Mesh.npolys, Is.EqualTo(1)); Assert.That(rcResult.Mesh.nverts, Is.EqualTo(5)); bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), 6, 9); - rcResult = builder.Build(geom, bcfg); + rcResult = builder.Build(geom, bcfg, false); Assert.That(rcResult.Mesh.npolys, Is.EqualTo(2)); Assert.That(rcResult.Mesh.nverts, Is.EqualTo(7)); bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), 2, 9); - rcResult = builder.Build(geom, bcfg); + rcResult = builder.Build(geom, bcfg, false); Assert.That(rcResult.Mesh.npolys, Is.EqualTo(2)); Assert.That(rcResult.Mesh.nverts, Is.EqualTo(9)); bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), 4, 3); - rcResult = builder.Build(geom, bcfg); + rcResult = builder.Build(geom, bcfg, false); Assert.That(rcResult.Mesh.npolys, Is.EqualTo(3)); Assert.That(rcResult.Mesh.nverts, Is.EqualTo(6)); bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), 2, 8); - rcResult = builder.Build(geom, bcfg); + rcResult = builder.Build(geom, bcfg, false); Assert.That(rcResult.Mesh.npolys, Is.EqualTo(5)); Assert.That(rcResult.Mesh.nverts, Is.EqualTo(17)); bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), 0, 8); - rcResult = builder.Build(geom, bcfg); + rcResult = builder.Build(geom, bcfg, false); Assert.That(rcResult.Mesh.npolys, Is.EqualTo(6)); Assert.That(rcResult.Mesh.nverts, Is.EqualTo(15)); } From fb49a5bca6ce6d9ea3fea362d344d208c6bb0b1d Mon Sep 17 00:00:00 2001 From: ikpil Date: Fri, 26 Apr 2024 01:02:09 +0900 Subject: [PATCH 5/8] checking ... --- src/DotRecast.Core/RcArrays.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/DotRecast.Core/RcArrays.cs b/src/DotRecast.Core/RcArrays.cs index e8c291a..c06d605 100644 --- a/src/DotRecast.Core/RcArrays.cs +++ b/src/DotRecast.Core/RcArrays.cs @@ -11,6 +11,13 @@ namespace DotRecast.Core { Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Copy(Span sourceArray, int sourceIndex, Span destinationArray, int destinationIndex, int length) + { + sourceArray.Slice(sourceIndex, length).CopyTo(destinationArray.Slice(destinationIndex)); + } + // Type Safe Copy [MethodImpl(MethodImplOptions.AggressiveInlining)] From adbb265ca21cb18e5d9ffdde3b48feb647b0a64c Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 27 Apr 2024 10:51:52 +0900 Subject: [PATCH 6/8] added T[] vs Span benchmark --- src/DotRecast.Core/RcArrays.cs | 6 +- .../RcArrayBenchmarkTests.cs | 75 +++++++++++++++++-- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/DotRecast.Core/RcArrays.cs b/src/DotRecast.Core/RcArrays.cs index c06d605..adcfd09 100644 --- a/src/DotRecast.Core/RcArrays.cs +++ b/src/DotRecast.Core/RcArrays.cs @@ -11,11 +11,13 @@ namespace DotRecast.Core { Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length); } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Copy(Span sourceArray, int sourceIndex, Span destinationArray, int destinationIndex, int length) { - sourceArray.Slice(sourceIndex, length).CopyTo(destinationArray.Slice(destinationIndex)); + var src = sourceArray.Slice(sourceIndex, length); + var dst = destinationArray.Slice(destinationIndex); + src.CopyTo(dst); } diff --git a/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs b/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs index 1296d88..4b5410e 100644 --- a/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs +++ b/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs @@ -1,6 +1,7 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.Net.Sockets; using DotRecast.Core.Buffers; using DotRecast.Core.Collections; using NUnit.Framework; @@ -84,18 +85,76 @@ public class RcArrayBenchmarkTests [Test] public void TestBenchmarkArrays() { - var list = new List<(string title, long ticks)>(); - list.Add(Bench("new int[len]", RoundForArray)); - list.Add(Bench("ArrayPool.Shared.Rent(len)", RoundForPureRentArray)); - list.Add(Bench("RcRentedArray.Rent(len)", RoundForRcRentedArray)); - list.Add(Bench("new RcStackArray512()", RoundForRcStackArray)); - list.Add(Bench("stackalloc int[len]", RoundForStackalloc)); + var results = new List<(string title, long ticks)>(); + results.Add(Bench("new int[len]", RoundForArray)); + results.Add(Bench("ArrayPool.Shared.Rent(len)", RoundForPureRentArray)); + results.Add(Bench("RcRentedArray.Rent(len)", RoundForRcRentedArray)); + results.Add(Bench("new RcStackArray512()", RoundForRcStackArray)); + results.Add(Bench("stackalloc int[len]", RoundForStackalloc)); - list.Sort((x, y) => x.ticks.CompareTo(y.ticks)); + results.Sort((x, y) => x.ticks.CompareTo(y.ticks)); - foreach (var t in list) + foreach (var t in results) { Console.WriteLine($"{t.title} {t.ticks / (double)TimeSpan.TicksPerMillisecond} ms"); } } + + [Test] + public void TestSpanVsArray() + { + var r = new RcRand(); + var list = new List<(long[] src, long[] dest)>(); + for (int i = 0; i < 14; ++i) + { + var s = new long[(int)Math.Pow(2, i + 1)]; + var d = new long[(int)Math.Pow(2, i + 1)]; + for (int ii = 0; ii < s.Length; ++ii) + { + s[ii] = r.NextInt32(); + } + + list.Add((s, d)); + } + + var results = new List<(string title, long ticks)>(); + for (int i = 0; i < list.Count; ++i) + { + var seq = i; + + Array.Fill(list[seq].dest, 0); + var resultLong = Bench($"long[{list[seq].src.Length}]", _ => + { + var v = list[seq]; + RcArrays.Copy(v.src, 0, v.dest, 0, v.src.Length); + }); + + + Array.Fill(list[seq].dest, 0); + var resultSpan = Bench($"Span", _ => + { + var v = list[seq]; + Span src = v.src; + Span dest = v.dest; + RcArrays.Copy(src, 0, dest, 0, src.Length); + }); + + + results.Add(resultLong); + results.Add(resultSpan); + } + + + int newLine = 0; + foreach (var t in results) + { + Console.WriteLine($"{t.title}: {t.ticks / (double)TimeSpan.TicksPerMillisecond} ms"); + newLine += 1; + if (0 == (newLine % 2)) + { + Console.WriteLine(""); + } + + } + } } \ No newline at end of file From 2ef6c0b27c5e9c9b1d3319519699e0e36f1823ec Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 27 Apr 2024 10:52:14 +0900 Subject: [PATCH 7/8] upgrade NUnit.Analyzers Version="4.2.0" --- test/DotRecast.Core.Test/DotRecast.Core.Test.csproj | 2 +- .../DotRecast.Detour.Crowd.Test.csproj | 2 +- .../DotRecast.Detour.Dynamic.Test.csproj | 2 +- .../DotRecast.Detour.Extras.Test.csproj | 2 +- test/DotRecast.Detour.Test/DotRecast.Detour.Test.csproj | 2 +- .../DotRecast.Detour.TileCache.Test.csproj | 2 +- test/DotRecast.Recast.Test/DotRecast.Recast.Test.csproj | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/DotRecast.Core.Test/DotRecast.Core.Test.csproj b/test/DotRecast.Core.Test/DotRecast.Core.Test.csproj index ebef2b5..343e1ce 100644 --- a/test/DotRecast.Core.Test/DotRecast.Core.Test.csproj +++ b/test/DotRecast.Core.Test/DotRecast.Core.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/DotRecast.Detour.Crowd.Test/DotRecast.Detour.Crowd.Test.csproj b/test/DotRecast.Detour.Crowd.Test/DotRecast.Detour.Crowd.Test.csproj index e416f45..55953c2 100644 --- a/test/DotRecast.Detour.Crowd.Test/DotRecast.Detour.Crowd.Test.csproj +++ b/test/DotRecast.Detour.Crowd.Test/DotRecast.Detour.Crowd.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj b/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj index 153236f..57e7160 100644 --- a/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj +++ b/test/DotRecast.Detour.Dynamic.Test/DotRecast.Detour.Dynamic.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/DotRecast.Detour.Extras.Test/DotRecast.Detour.Extras.Test.csproj b/test/DotRecast.Detour.Extras.Test/DotRecast.Detour.Extras.Test.csproj index 9af54f1..a11f9e8 100644 --- a/test/DotRecast.Detour.Extras.Test/DotRecast.Detour.Extras.Test.csproj +++ b/test/DotRecast.Detour.Extras.Test/DotRecast.Detour.Extras.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/DotRecast.Detour.Test/DotRecast.Detour.Test.csproj b/test/DotRecast.Detour.Test/DotRecast.Detour.Test.csproj index aae8db2..c4e8dd5 100644 --- a/test/DotRecast.Detour.Test/DotRecast.Detour.Test.csproj +++ b/test/DotRecast.Detour.Test/DotRecast.Detour.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj b/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj index d7247b0..4278add 100644 --- a/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj +++ b/test/DotRecast.Detour.TileCache.Test/DotRecast.Detour.TileCache.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/DotRecast.Recast.Test/DotRecast.Recast.Test.csproj b/test/DotRecast.Recast.Test/DotRecast.Recast.Test.csproj index cd9cbc4..bd28373 100644 --- a/test/DotRecast.Recast.Test/DotRecast.Recast.Test.csproj +++ b/test/DotRecast.Recast.Test/DotRecast.Recast.Test.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 3ae7582043d9a4acf327397253a40c2291ed5eff Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 27 Apr 2024 11:08:55 +0900 Subject: [PATCH 8/8] added RcSpans util --- src/DotRecast.Core/RcArrays.cs | 9 -------- src/DotRecast.Core/RcSpans.cs | 22 +++++++++++++++++++ .../RcArrayBenchmarkTests.cs | 5 +---- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 src/DotRecast.Core/RcSpans.cs diff --git a/src/DotRecast.Core/RcArrays.cs b/src/DotRecast.Core/RcArrays.cs index adcfd09..e8c291a 100644 --- a/src/DotRecast.Core/RcArrays.cs +++ b/src/DotRecast.Core/RcArrays.cs @@ -12,15 +12,6 @@ namespace DotRecast.Core Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy(Span sourceArray, int sourceIndex, Span destinationArray, int destinationIndex, int length) - { - var src = sourceArray.Slice(sourceIndex, length); - var dst = destinationArray.Slice(destinationIndex); - src.CopyTo(dst); - } - - // Type Safe Copy [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Copy(T[] sourceArray, T[] destinationArray, long length) diff --git a/src/DotRecast.Core/RcSpans.cs b/src/DotRecast.Core/RcSpans.cs new file mode 100644 index 0000000..474f492 --- /dev/null +++ b/src/DotRecast.Core/RcSpans.cs @@ -0,0 +1,22 @@ +using System; +using System.Runtime.CompilerServices; + +namespace DotRecast.Core +{ + public static class RcSpans + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Copy(Span source, Span destination) + { + Copy(source, 0, destination, 0, source.Length); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Copy(Span source, int sourceIdx, Span destination, int destinationIdx, int length) + { + var src = source.Slice(sourceIdx, length); + var dst = destination.Slice(destinationIdx); + src.CopyTo(dst); + } + } +} \ No newline at end of file diff --git a/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs b/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs index 4b5410e..3117e7d 100644 --- a/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs +++ b/test/DotRecast.Core.Test/RcArrayBenchmarkTests.cs @@ -134,9 +134,7 @@ public class RcArrayBenchmarkTests var resultSpan = Bench($"Span", _ => { var v = list[seq]; - Span src = v.src; - Span dest = v.dest; - RcArrays.Copy(src, 0, dest, 0, src.Length); + RcSpans.Copy(v.src, 0, v.dest, 0, v.src.Length); }); @@ -154,7 +152,6 @@ public class RcArrayBenchmarkTests { Console.WriteLine(""); } - } } } \ No newline at end of file