diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..51c411f6 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,73 @@ +name: Publish + +on: [push, pull_request] + +env: + DOTNET_VERSION: "3.1.x" # The .NET SDK version to use + +jobs: + test: + runs-on: ubuntu-latest + + env: + ARTIFACT_BENCHMARK: "artifact/benchmark" + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Install dependencies + run: dotnet restore + + # - name: Build + # run: | + # dotnet build PapyrusCs -c Release --no-restore + + - name: Test + run: | + dotnet test --no-restore --verbosity normal + + - name: Prepare artifacts + run: | + mkdir -p "${{ env.ARTIFACT_BENCHMARK }}" + cp "MapLoader.NUnitTests/bin/Debug/netcoreapp3.1/benchmark.png" "${{ env.ARTIFACT_BENCHMARK }}/benchmark.png" + cp "MapLoader.NUnitTests/bin/Debug/netcoreapp3.1/benchmark/Benchmark.png" "${{ env.ARTIFACT_BENCHMARK }}/benchmark-original.png" + + - name: Upload benchmark + uses: actions/upload-artifact@v2 + with: + name: "benchmark" + path: "${{ env.ARTIFACT_BENCHMARK }}/**/*" + + publish: + runs-on: ubuntu-latest + strategy: + matrix: + runtime: [linux-x64, win-x64] + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Install dependencies + run: dotnet restore + + # - name: Build + # run: | + # dotnet build PapyrusCs -c Release --no-restore + + - name: Build ${{ matrix.runtime }} + run: | + dotnet publish PapyrusCs -c Release -o build/${{ matrix.runtime }} -r ${{ matrix.runtime }} --self-contained true + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: "papyruscs-${{ matrix.runtime }}" + path: "build/${{ matrix.runtime }}/**/*" diff --git a/MapLoader.NUnitTests/OtherTests.cs b/MapLoader.NUnitTests/OtherTests.cs index 8d26eb60..8e7bc358 100644 --- a/MapLoader.NUnitTests/OtherTests.cs +++ b/MapLoader.NUnitTests/OtherTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.IO; @@ -8,6 +8,7 @@ using Maploader.Renderer.Heightmap; using Maploader.Renderer.Imaging; using Maploader.Renderer.Texture; +using Maploader.World; using Microsoft.Extensions.ObjectPool; using NUnit.Framework; using PapyrusCs.Database; @@ -165,16 +166,24 @@ public void BenchmarkRender() { var dut = new Maploader.World.World(); dut.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "benchmark", "world", "db")); - int chunkRadius = 1; - int centerOffsetX = 1; //65; - int centerOffsetZ = 1; //65; + int XMin = -1, XMax = 3; + int ZMin = -1, ZMax = 4; string filename = "benchmark.png"; - RenderMap(chunkRadius, dut, centerOffsetX, centerOffsetZ, filename); + RenderMap(dut, filename, XMin, XMax, ZMin, ZMax); } private static void RenderMap(int chunkRadius, Maploader.World.World dut, int centerOffsetX, int centerOffsetZ, string filename) + { + int XMin = centerOffsetX - chunkRadius, XMax = centerOffsetX + chunkRadius; + int ZMin = centerOffsetZ - chunkRadius, ZMax = centerOffsetZ + chunkRadius; + + RenderMap(dut, filename, XMin, XMax, ZMin, ZMax); + } + + private static void RenderMap(Maploader.World.World dut, string filename, + int XMin, int XMax, int ZMin, int ZMax) { var json = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"textures", "terrain_texture.json")); @@ -185,20 +194,25 @@ private static void RenderMap(int chunkRadius, Maploader.World.World dut, int ce Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "textures"), g); finder.Debug = false; - var b = g.CreateEmptyImage(16 * 16 * (2 * chunkRadius + 1), 16 * 16 * (2 * chunkRadius + 1)); + var b = g.CreateEmptyImage(16 * 16 * (XMax - XMin + 1), 16 * 16 * (ZMax - ZMin + 1)); + + var render = new ChunkRenderer(finder, g, new RenderSettings() { YMax = 40 }); - var render = new ChunkRenderer(finder, g, new RenderSettings() {YMax = 40}); + var keysByXZ = dut.GetDimension(0) + .Select(x => new LevelDbWorldKey2(x)) + .Where(c => c.X <= XMax && c.X >= XMin && c.Z <= ZMax && c.Z >= ZMin) + .GroupBy(x => x.XZ); + var chunkKeys = keysByXZ.Select(chunkGroup => new GroupedChunkSubKeys(chunkGroup)); + var chunkDatas = chunkKeys.Select(dut.GetChunkData); - //Parallel.For(-chunkRadius, chunkRadius + 1,new ParallelOptions(){MaxDegreeOfParallelism = 8} , dx => - for (int dz = -chunkRadius; dz <= chunkRadius; dz++) + foreach (var chunkData in chunkDatas) { - for (int dx = -chunkRadius; dx <= chunkRadius; dx++) + var c = dut.GetChunk(chunkData.X, chunkData.Z, chunkData); + if (c != null) { - var c = dut.GetChunk(dx + centerOffsetX, dz + centerOffsetZ); - if (c != null) - { - render.RenderChunk(b, c, (chunkRadius + dx) * 256, (chunkRadius + dz) * 256); - } + int dx = chunkData.X - XMin; + int dz = chunkData.Z - ZMin; + render.RenderChunk(b, c, dx * 256, dz * 256); } } diff --git a/MapLoader.NUnitTests/benchmark/Benchmark.png b/MapLoader.NUnitTests/benchmark/Benchmark.png index c807e86f..dd8ad486 100644 Binary files a/MapLoader.NUnitTests/benchmark/Benchmark.png and b/MapLoader.NUnitTests/benchmark/Benchmark.png differ diff --git a/MapLoader.NUnitTests/benchmark/world/db/000106.ldb b/MapLoader.NUnitTests/benchmark/world/db/000106.ldb new file mode 100644 index 00000000..c0ac6088 Binary files /dev/null and b/MapLoader.NUnitTests/benchmark/world/db/000106.ldb differ diff --git a/MapLoader.NUnitTests/benchmark/world/db/001497.ldb b/MapLoader.NUnitTests/benchmark/world/db/001497.ldb deleted file mode 100644 index fd8f1169..00000000 Binary files a/MapLoader.NUnitTests/benchmark/world/db/001497.ldb and /dev/null differ diff --git a/MapLoader.NUnitTests/benchmark/world/db/001499.ldb b/MapLoader.NUnitTests/benchmark/world/db/001499.ldb deleted file mode 100644 index c514fed9..00000000 Binary files a/MapLoader.NUnitTests/benchmark/world/db/001499.ldb and /dev/null differ diff --git a/MapLoader.NUnitTests/benchmark/world/db/001500.log b/MapLoader.NUnitTests/benchmark/world/db/001500.log deleted file mode 100644 index 958cfc72..00000000 Binary files a/MapLoader.NUnitTests/benchmark/world/db/001500.log and /dev/null differ diff --git a/MapLoader.NUnitTests/benchmark/world/db/CURRENT b/MapLoader.NUnitTests/benchmark/world/db/CURRENT index e4f6d59b..1fb45e8c 100644 --- a/MapLoader.NUnitTests/benchmark/world/db/CURRENT +++ b/MapLoader.NUnitTests/benchmark/world/db/CURRENT @@ -1 +1 @@ -MANIFEST-001498 +MANIFEST-000103 diff --git a/MapLoader.NUnitTests/benchmark/world/db/LOCK b/MapLoader.NUnitTests/benchmark/world/db/LOCK deleted file mode 100644 index e69de29b..00000000 diff --git a/MapLoader.NUnitTests/benchmark/world/db/MANIFEST-000103 b/MapLoader.NUnitTests/benchmark/world/db/MANIFEST-000103 new file mode 100644 index 00000000..a0512581 Binary files /dev/null and b/MapLoader.NUnitTests/benchmark/world/db/MANIFEST-000103 differ diff --git a/MapLoader.NUnitTests/benchmark/world/db/MANIFEST-001498 b/MapLoader.NUnitTests/benchmark/world/db/MANIFEST-001498 deleted file mode 100644 index fbe64142..00000000 Binary files a/MapLoader.NUnitTests/benchmark/world/db/MANIFEST-001498 and /dev/null differ diff --git a/MapLoader.NUnitTests/benchmark/world/level.dat b/MapLoader.NUnitTests/benchmark/world/level.dat index 678c25e8..7b4ac605 100644 Binary files a/MapLoader.NUnitTests/benchmark/world/level.dat and b/MapLoader.NUnitTests/benchmark/world/level.dat differ diff --git a/MapLoader.NUnitTests/benchmark/world/level.dat_old b/MapLoader.NUnitTests/benchmark/world/level.dat_old index 6be48bef..72aa5978 100644 Binary files a/MapLoader.NUnitTests/benchmark/world/level.dat_old and b/MapLoader.NUnitTests/benchmark/world/level.dat_old differ diff --git a/MapLoader.NUnitTests/benchmark/world/levelname.txt b/MapLoader.NUnitTests/benchmark/world/levelname.txt index 3eec8496..c03ddeb8 100644 --- a/MapLoader.NUnitTests/benchmark/world/levelname.txt +++ b/MapLoader.NUnitTests/benchmark/world/levelname.txt @@ -1 +1 @@ -Benchmark New \ No newline at end of file +1.19.0 Test \ No newline at end of file diff --git a/MapLoader.NUnitTests/benchmark/world/world_icon.jpeg b/MapLoader.NUnitTests/benchmark/world/world_icon.jpeg index 8eb7665e..b4dda940 100644 Binary files a/MapLoader.NUnitTests/benchmark/world/world_icon.jpeg and b/MapLoader.NUnitTests/benchmark/world/world_icon.jpeg differ diff --git a/Maploader/World/World.cs b/Maploader/World/World.cs index e2294555..30905b38 100644 --- a/Maploader/World/World.cs +++ b/Maploader/World/World.cs @@ -120,6 +120,7 @@ public Chunk GetChunk(int x, int z, ChunkData data) return c; } + [Obsolete("Use GetChunk(int x, int z, ChunkData data) instead")] public Chunk GetChunk(int x, int z) { bool haveData = false; @@ -130,14 +131,14 @@ public Chunk GetChunk(int x, int z) var key = CreateKey(x, z); - for (byte subChunkIdx = 0; subChunkIdx < 15; subChunkIdx++) + for (sbyte subChunkIdx = -4; subChunkIdx < 20; subChunkIdx++) { - key[9] = subChunkIdx; + key[9] = (byte)subChunkIdx; UIntPtr length; var data = db.Get(key, out length); if (data != null) { - subChunks[subChunkIdx] = data; + subChunks[(byte)subChunkIdx] = data; haveData = true; } } diff --git a/readme.md b/readme.md index c0c4aa80..4cad2983 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,5 @@ Chat: [![Discord](https://img.shields.io/discord/569841820092203011.svg?logo=discord&logoColor=white)](https://discord.gg/J2sBaXa)
-Windows: [![Build status](https://ci.appveyor.com/api/projects/status/tfspbbi72bx73qg8?svg=true)](https://ci.appveyor.com/project/mjungnickel18/papyruscs)
-Linux: [![Build status](https://ci.appveyor.com/api/projects/status/xo9ew31l49hayjcm?svg=true)](https://ci.appveyor.com/project/mjungnickel18/papyruscs-ytqjm)
+Build: [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/papyrus-mc/papyruscs/publish?logo=github)](https://github.com/papyrus-mc/papyruscs/actions/workflows/publish.yml?query=branch%3Amaster)
# Papyrus