• R/O
  • HTTP
  • SSH
  • HTTPS

automap: Commit

Automap (OSS) GIT software repository


Commit MetaInfo

Revisionfb10556337a87e9853f87ba4562e2263bfff1975 (tree)
Time2020-11-10 11:01:57
Authormelchior <melchior@user...>
Commitermelchior

Log Message

W.I.P. Experimental use of Heightmap to replace Region map data
(edge incline shading)

Change Summary

Incremental Difference

--- a/Automap/Renderers/AChunkRenderer.cs
+++ b/Automap/Renderers/AChunkRenderer.cs
@@ -30,7 +30,7 @@ namespace Automap
3030
3131 }
3232
33- public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, out uint pixelCount);
33+ public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount);
3434
3535 public virtual PngWriter SetupPngImage(Vec2i coord, string path, string chunkPath, ref ColumnMeta metadata)
3636 {
--- a/Automap/Renderers/AlternateRenderer.cs
+++ b/Automap/Renderers/AlternateRenderer.cs
@@ -22,7 +22,7 @@ namespace Automap
2222
2323 }
2424
25- public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, out uint pixelCount)
25+ public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, ref ColumnsMetadata allCols, out uint pixelCount)
2626 {
2727 pixelCount = 0;
2828 BlockPos tmpPos = new BlockPos();
--- a/Automap/Renderers/StandardRenderer.cs
+++ b/Automap/Renderers/StandardRenderer.cs
@@ -1,4 +1,5 @@
11 using System;
2+using System.Collections.Generic;
23 using System.Linq;
34
45 using Hjg.Pngcs;
@@ -23,7 +24,7 @@ namespace Automap
2324
2425 }
2526
26- public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, out uint pixelCount)
27+ public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount)
2728 {
2829 pixelCount = 0;
2930 BlockPos tmpPos = new BlockPos( );
@@ -34,52 +35,74 @@ namespace Automap
3435 //pre-create PNG line slices...
3536 ImageLine[ ] lines = Enumerable.Repeat(new object( ), chunkSize).Select(l => new ImageLine(this.PngWriter.ImgInfo)).ToArray( );
3637
37- int topChunkY = metaData.YMax / chunkSize;
38+ int topChunkY = targetColMeta.YMax / chunkSize;
3839
39- for (int chunkY = 0; chunkY <= topChunkY; chunkY++)
40- {
41- chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y);
42- WorldChunk ownChunk = chunksColumn[chunkY] as WorldChunk;
43- if (ownChunk != null)
44- {
45- if (ownChunk.IsPacked( )) ownChunk.Unpack( );//Gah - probably done already by chunk processor
46- }
47- else
48- {
49- Logger.Warning("CHUNK A.W.O.L. : X{0} Y{1} Z{2} - Missing slice FOR COLUMN", chunkPos.X, chunkY, chunkPos.Y);
50- //return;
51- }
40+ for (int chunkY = 0; chunkY <= topChunkY; chunkY++) {
41+ chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y);
42+ WorldChunk ownChunk = chunksColumn[chunkY] as WorldChunk;
43+ if (ownChunk != null) {
44+ if (ownChunk.IsPacked( )) ownChunk.Unpack( );//Gah - probably done already by chunk processor
45+ }
46+ else {
47+ Logger.Warning("CHUNK A.W.O.L. : X{0} Y{1} Z{2} - Missing slice FOR COLUMN", chunkPos.X, chunkY, chunkPos.Y);
48+ //return;
49+ }
5250 }
5351
5452 // Prefetch map chunks, in pattern
55- IMapChunk[ ] mapChunks = new IMapChunk[ ]
56- {
57- ClientAPI.World.BlockAccessor.GetMapChunk(chunkPos.X - 1, chunkPos.Y - 1),
58- ClientAPI.World.BlockAccessor.GetMapChunk(chunkPos.X - 1, chunkPos.Y),
59- ClientAPI.World.BlockAccessor.GetMapChunk(chunkPos.X, chunkPos.Y - 1)
60- };
61-
53+ var mapCornerChunks = new List<ColumnMeta>(3);
54+
55+ var south_west = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1);
56+ var west = new Vec2i(chunkPos.X - 1, chunkPos.Y);
57+ var south = new Vec2i(chunkPos.X, chunkPos.Y - 1);
58+
59+ /*
60+ For missing corners / cardinal heightmaps...
61+ make fake heightmap dummy
62+ */
63+
64+ if (allCols.Contains(south_west)) {
65+ mapCornerChunks.Add(allCols[south_west]);
66+ }
67+ else {
68+ mapCornerChunks.Add(targetColMeta);//TODO: Make mirror image - heightmap
69+ }
70+
71+ if (allCols.Contains(south)) {
72+ mapCornerChunks.Add(allCols[south]);
73+ }
74+ else {
75+ mapCornerChunks.Add(targetColMeta);//TODO: Make mirror image - heightmap
76+ }
77+
78+ if (allCols.Contains(west)) {
79+ mapCornerChunks.Add(allCols[west]);
80+ }
81+ else {
82+ mapCornerChunks.Add(targetColMeta);//TODO: Make mirror image - heightmap
83+ }
84+
6285
6386 for (int pixelIndex = 0; pixelIndex < (chunkSize * chunkSize); pixelIndex++) {
6487 MapUtil.PosInt2d(pixelIndex, chunkSize, localpos);
6588 int localX = localpos.X;
6689 int localZ = localpos.Y;
67- ushort localY = metaData.HeightMap[localX, localZ];
90+ ushort localY = targetColMeta.HeightMap[localX, localZ];
6891
6992 int localChunkY = localY / chunkSize;
7093 if (localChunkY >= (chunksColumn.Length)) continue;//Out of range!
7194 if (chunksColumn[localChunkY] == null) continue;//BIG Gaps!
72- if (mapChunks.Any(chks => chks == null)) {
73- //Logger.Warning("MapChunk A.W.O.L. near : X{0} Y{1} Z{2} - ", localX, localY, localZ);
74- continue;
75- }
95+ //if (mapCornerChunks.Any(chks => chks == null)) {
96+ //Logger.Warning("mapCornerChunks A.W.O.L. near : X{0} Y{1} Z{2} - ", localX, localY, localZ);
97+ //continue;
98+ //}
7699
77100 float slopeBoost = 1;
78101 int leftTop, rightTop, leftBot;
79102
80- IMapChunk leftTopMapChunk = mc;
81- IMapChunk rightTopMapChunk = mc;
82- IMapChunk leftBotMapChunk = mc;
103+ ColumnMeta leftTopMapChunk = targetColMeta;
104+ ColumnMeta rightTopMapChunk = targetColMeta;
105+ ColumnMeta leftBotMapChunk = targetColMeta;
83106
84107 int topX = localX - 1;
85108 int botX = localX;
@@ -87,27 +110,27 @@ namespace Automap
87110 int rightZ = localZ;
88111
89112 if (topX < 0 && leftZ < 0) {
90- leftTopMapChunk = mapChunks[0];
91- rightTopMapChunk = mapChunks[1];
92- leftBotMapChunk = mapChunks[2];
113+ leftTopMapChunk = mapCornerChunks[0];
114+ rightTopMapChunk = mapCornerChunks[1];
115+ leftBotMapChunk = mapCornerChunks[2];
93116 }
94117 else {
95118 if (topX < 0) {
96- leftTopMapChunk = mapChunks[1];
97- rightTopMapChunk = mapChunks[1];
119+ leftTopMapChunk = mapCornerChunks[1];
120+ rightTopMapChunk = mapCornerChunks[1];
98121 }
99122 if (leftZ < 0) {
100- leftTopMapChunk = mapChunks[2];
101- leftBotMapChunk = mapChunks[2];
123+ leftTopMapChunk = mapCornerChunks[2];
124+ leftBotMapChunk = mapCornerChunks[2];
102125 }
103126 }
104127
105128 topX = GameMath.Mod(topX, chunkSize);
106129 leftZ = GameMath.Mod(leftZ, chunkSize);
107- //TODO: Replace with Metadata Heightmap?
108- leftTop = leftTopMapChunk == null ? 0 : Math.Sign(localY - leftTopMapChunk.RainHeightMap[leftZ * chunkSize + topX]);
109- rightTop = rightTopMapChunk == null ? 0 : Math.Sign(localY - rightTopMapChunk.RainHeightMap[rightZ * chunkSize + topX]);
110- leftBot = leftBotMapChunk == null ? 0 : Math.Sign(localY - leftBotMapChunk.RainHeightMap[leftZ * chunkSize + botX]);
130+
131+ leftTop = Math.Sign(localY - leftTopMapChunk.HeightMap[topX, leftZ]);
132+ rightTop = Math.Sign(localY - rightTopMapChunk.HeightMap[topX, rightZ]);
133+ leftBot = Math.Sign(localY - leftBotMapChunk.HeightMap[botX, leftZ]);
111134
112135 float slopeness = (leftTop + rightTop + leftBot);
113136
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -132,9 +132,14 @@ namespace Automap
132132
133133 private void ChunkAChanging(Vec3i chunkCoord, IWorldChunk chunk, EnumChunkDirtyReason reason)
134134 {
135- Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z);
136-
137- columnCounter.AddOrUpdate(topPosition, 1, (key, colAct) => colAct + 1);
135+ Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z);
136+
137+ //TODO: Track Y Chunk - Column, surface chunks being more important
138+ //Only NEW/LOADED chunks unless edits > N
139+ //if (reason == EnumChunkDirtyReason.NewlyCreated || reason == EnumChunkDirtyReason.NewlyLoaded)
140+ //{
141+ columnCounter.AddOrUpdate(topPosition, 1, (key, colAct) => colAct + 1);
142+ //}
138143 }
139144
140145 private void AwakenCartographer(float delayed)
@@ -221,7 +226,7 @@ namespace Automap
221226 ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
222227
223228 ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta);
224- ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, out updatedPixels);
229+ ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, ref chunkTopMetadata, out updatedPixels);
225230
226231 if (updatedPixels > 0)
227232 {
Show on old repository browser