Skip to content

Commit f6ceffa

Browse files
committed
GraphicExtensions
RenderMode etc
1 parent 76f79f8 commit f6ceffa

12 files changed

+71
-46
lines changed

MapLoader.NUnitTests/BenchmarkTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void Uint64Test()
8888
[Test]
8989
public void BrillouinFkt()
9090
{
91-
var dut = new Brillouin();
91+
var dut = new Brillouin(10000);
9292

9393
}
9494
}

MapLoader.NUnitTests/MapLoader.NUnitTests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="nunit" Version="3.11.0" />
21-
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
21+
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

Maploader/Extensions/GraphicsExtensions.cs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.Specialized;
34
using System.Drawing;
45
using System.Drawing.Imaging;
6+
using System.Numerics;
57
using System.Text;
68
using System.Threading.Tasks;
79

@@ -25,7 +27,9 @@ public static void DrawImageBrightness(this Bitmap dest, Bitmap image, int x, in
2527
}
2628
}
2729

28-
public static unsafe void DrawTest(this Bitmap dest, Bitmap image, int x, int y, double brightness)
30+
public static Vector3 v255 = Vector3.One * 255;
31+
32+
public static unsafe void DrawTest(this Bitmap dest, Bitmap image, int x, int y, float brightness)
2933
{
3034
int w = image.Width;
3135
if (w > 16) w = 16;
@@ -46,22 +50,32 @@ public static unsafe void DrawTest(this Bitmap dest, Bitmap image, int x, int y,
4650
byte* srcPixel = scanSrc + oy * bSrc.Stride + ox * 4;
4751
byte* destPixel = scanDest + (oy) * bDest.Stride + (ox) * 4;
4852

49-
var aa = srcPixel[3] / 256d;
50-
var ab = destPixel[3] / 256d;
53+
var aa = srcPixel[3] / 256f;
54+
var ab = destPixel[3] / 256f;
5155
var ac = aa + (1 - aa) * ab;
56+
#if true
57+
var a = new Vector3(srcPixel[0], srcPixel[1], srcPixel[2]);
58+
var b = new Vector3(destPixel[0], destPixel[1], destPixel[2]);
59+
var c = (brightness * a * aa + ((1 - aa) * ab) * b)/ac;
5260

61+
c = Vector3.Clamp(c, Vector3.Zero, v255);
62+
63+
destPixel[0] = (byte) c.X;
64+
destPixel[1] = (byte) c.Y;
65+
destPixel[2] = (byte) c.Z;
66+
#else
5367
var dr = (brightness * srcPixel[0] * aa + (1 - aa) * ab * destPixel[0]);
5468
var dg = (brightness * srcPixel[1] * aa + (1 - aa) * ab * destPixel[1]);
5569
var db = (brightness * srcPixel[2] * aa + (1 - aa) * ab * destPixel[2]);
56-
70+
5771
if (dr > 255) dr = 255;
5872
if (dg > 255) dg = 255;
5973
if (db > 255) db = 255;
6074

61-
destPixel[0] = (byte) dr;
62-
destPixel[1] = (byte) dg;
63-
destPixel[2] = (byte) db;
64-
75+
destPixel[0] = (byte)dr;
76+
destPixel[1] = (byte)dg;
77+
destPixel[2] = (byte)db;
78+
#endif
6579
destPixel[3] = (byte) (ac * 255);
6680
}
6781
}

Maploader/Maploader.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
</PropertyGroup>
77

Maploader/Renderer/ChunkRenderer.cs

+10-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.Drawing.Imaging;
55
using System.Linq;
6+
using JetBrains.Annotations;
67
using Maploader.Extensions;
78
using Maploader.Renderer.Heightmap;
89
using Maploader.Renderer.Texture;
@@ -13,20 +14,19 @@ namespace Maploader.Renderer
1314
public class ChunkRenderer
1415
{
1516
private readonly TextureFinder textureFinder;
16-
private readonly RenderSettings renderSettings = new RenderSettings();
17+
private readonly RenderSettings renderSettings;
1718

18-
public ChunkRenderer(TextureFinder textureFinder, RenderSettings renderSettings = null)
19+
public ChunkRenderer([NotNull] TextureFinder textureFinder, RenderSettings settings = null)
1920
{
20-
this.textureFinder = textureFinder;
21-
if (renderSettings != null)
22-
{
23-
this.renderSettings = renderSettings;
24-
}
21+
this.textureFinder = textureFinder ?? throw new ArgumentNullException(nameof(textureFinder));
22+
this.renderSettings = settings ?? new RenderSettings();
23+
24+
b = new Brillouin(renderSettings.BrillouinJ);
2525
}
2626

2727
public List<string> MissingTextures { get; } = new List<string>();
2828

29-
public Brillouin b { get; } = new Brillouin();
29+
private Brillouin b;
3030

3131
public void RenderChunk(Chunk c, Graphics g, int xOffset, int zOffset, Bitmap dest)
3232
{
@@ -71,10 +71,8 @@ public void RenderChunk(Chunk c, Graphics g, int xOffset, int zOffset, Bitmap de
7171
{
7272
var x = xOffset + block.X * 16;
7373
var z = zOffset + block.Z * 16;
74-
//g.DrawImage(bitmapTile, xOffset + block.X * 16, zOffset + block.Z * 16);
75-
//g.DrawImageBrightness(bitmapTile, xOffset + block.X * 16, zOffset + block.Z * 16,b.GetBrightness(block.Y));
76-
//dest.DrawImageBrightness(bitmapTile, xOffset + block.X * 16, zOffset + block.Z * 16, b.GetBrightness(block.Y));
77-
dest.DrawTest(bitmapTile, x, z, b.GetBrightness(block.Y - 64));
74+
75+
dest.DrawTest(bitmapTile, x, z, b.GetBrightness(block.Y - Math.Min(64, renderSettings.YMax)));
7876

7977
}
8078
else

Maploader/Renderer/Heightmap/Brillouin.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ namespace Maploader.Renderer.Heightmap
88
{
99
public class Brillouin
1010
{
11-
private static double Compute(double j, double x)
11+
private readonly float j;
12+
13+
private float Compute(float x)
1214
{
1315
if (Math.Abs(x) < 0.01)
1416
return 0;
1517
return (2 * j + 1) / (2 * j) * Coth((2 * j + 1) / (2 * j) * x)
1618
- 1 / (2 * j) * Coth(1 / (2 * j) * x);
1719
}
1820

19-
private static double Coth(double x) => Math.Cosh(x) / Math.Sinh(x);
21+
private static float Coth(float x) => (float) (Math.Cosh(x) / Math.Sinh(x));
2022

21-
private Dictionary<int, double> Cache { get; } = new Dictionary<int, double>();
22-
public double GetBrightness(int height)
23+
private Dictionary<int, float> Cache { get; } = new Dictionary<int, float>();
24+
public float GetBrightness(int height)
2325
{
2426
if (!Cache.ContainsKey(height))
25-
Cache[height] = 1 + Compute(10000, 1 / 20d * height);
27+
Cache[height] = 1 + Compute(1 / 20f * height);
2628

2729
return Cache[height];
2830
}
29-
public Brillouin()
31+
public Brillouin(float j)
3032
{
33+
this.j = j;
3134
}
3235
}
3336
}

Maploader/Renderer/RenderSettings.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class RenderSettings
88
public bool RenderCoords { get; set; } = false;
99
public int MaxNumberOfThreads { get; set; } = 16;
1010
public HashSet<UInt64> Keys { get; set; }
11-
public int YMax { get; set; }
11+
public int YMax { get; set; } = -1;
12+
public float BrillouinJ { get; set; } = 10000;
1213
}
1314
}

Maploader/Renderer/Texture/TextureFinder.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -721,12 +721,7 @@ private TextureStack GetSubstitution(string name, long data, int x, int z, int y
721721
case "scaffolding":
722722
return GetTexture("scaffolding_top", data);
723723
case "sweet_berry_bush":
724-
if (data < 4)
725-
{
726-
return GetTexture($"sweet_berry_bush_{data}", 0);
727-
}
728-
729-
return null;
724+
return GetTexture($"sweet_berry_bush_{data%4}", 0);
730725
}
731726

732727
return null;
@@ -832,8 +827,6 @@ private TextureStack RenderButton(long data, string texture)
832827
default:
833828
return null;
834829
}
835-
836-
return t;
837830
}
838831

839832
private TextureStack RenderFenceGate(long data, string texture)

Mcpe.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XZ/@EntryIndexedValue">XZ</s:String></wpf:ResourceDictionary>

PapyrusCs/PapyrusCs.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="CommandLineParser" Version="2.4.3" />
11+
<PackageReference Include="CommandLineParser" Version="2.5.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

PapyrusCs/Program.cs

+19-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public enum Strategy
2222
ParallelFor,
2323
}
2424

25+
public enum RenderMode
26+
{
27+
Basic,
28+
Heightmap,
29+
}
30+
31+
2532
public class Options
2633
{
2734

@@ -52,6 +59,12 @@ public class Options
5259
[Option("threads", Required = false, HelpText = "Set maximum of used threads", Default = 16)]
5360
public int MaxNumberOfThreads { get; set; }
5461

62+
[Option('j', "brillouinj", Required = false, HelpText = "Sets factor j for heightmap brightness formular brillouin", Default = 10000f)]
63+
public float BrillouinJ { get; set; }
64+
65+
[Option('r', "rendermode", Required = false, HelpText = "RenderMode: Basic - Render without brightness adjustment.\nHeightmap - Render with brightness adjustment based on.height of block", Default = RenderMode.Heightmap)]
66+
public RenderMode RenderMode { get; set; }
67+
5568
public bool Loaded { get; set; }
5669
public int? LimitXLow { get; set; }
5770
public int? LimitXHigh { get; set; }
@@ -87,7 +100,7 @@ static int Main(string[] args)
87100
options.LimitXHigh = splittedLimit[1];
88101
}
89102
}
90-
catch (Exception ex)
103+
catch (Exception)
91104
{
92105
Console.WriteLine($"The value '{options.LimitX}' for the LimitZ parameter is not valid. Try something like -10,10");
93106
return -1;
@@ -104,7 +117,7 @@ static int Main(string[] args)
104117
options.LimitZHigh = splittedLimit[1];
105118
}
106119
}
107-
catch (Exception ex)
120+
catch (Exception)
108121
{
109122
Console.WriteLine($"The value '{options.LimitZ}' for the LimitZ parameter is not valid. Try something like -10,10");
110123
return -1;
@@ -217,8 +230,9 @@ static int Main(string[] args)
217230
RenderCoords = options.RenderCoords,
218231
MaxNumberOfThreads = options.MaxNumberOfThreads,
219232
Keys = keys64,
220-
YMax = options.LimitY
221-
};
233+
YMax = options.LimitY,
234+
BrillouinJ = options.BrillouinJ
235+
};
222236
strat.InitialDiameter = extendedDia;
223237
strat.InitialZoomLevel = (int)zoom;
224238
strat.World = world;
@@ -247,7 +261,7 @@ static int Main(string[] args)
247261
{
248262
var mapHtml = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "map.thtml"));
249263
mapHtml = mapHtml.Replace("%maxnativezoom%", zoom.ToString());
250-
mapHtml = mapHtml.Replace("%maxzoom%", (zoom + 1).ToString());
264+
mapHtml = mapHtml.Replace("%maxzoom%", (zoom + 2).ToString());
251265
mapHtml = mapHtml.Replace("%tilesize%", (tileSize).ToString());
252266

253267
File.WriteAllText(Path.Combine(options.OutputPath, options.MapHtml), mapHtml);

PapyrusCs/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"PapyrusCs": {
44
"commandName": "Project",
5-
"commandLineArgs": "-w \"C:\\papyruscs\\oldhome\\db\" -o c:\\papyrus --threads 8 --coords true --htmlfile index.html "
5+
"commandLineArgs": "-w \"C:\\papyruscs\\homeworld\\db\" -o c:\\papyrus\\190504d3 --threads 8 --coords true --htmlfile index.html --limitx 61,-61 --limitz 61,-61 -y 12 -j 0.5"
66
}
77
}
88
}

0 commit comments

Comments
 (0)