Automap (client) [VS plugin mod]
Revision | 8958039090797fadd178f3c433390b2affb40827 (tree) |
---|---|
Time | 2021-05-19 04:27:30 |
Author | melchior <melchior@user...> |
Commiter | melchior |
W.I.P. fixed positioning errors, various tweaks
@@ -7,14 +7,15 @@ namespace Automap | ||
7 | 7 | { |
8 | 8 | public struct ColumnCounter |
9 | 9 | { |
10 | - public bool NewOrLoaded; | |
11 | - public byte[] EditTally; | |
10 | + private bool NewOrLoaded; | |
11 | + private byte[] EditTally; | |
12 | + private byte HeightCutoff; //CHUNK # | |
12 | 13 | |
13 | 14 | public uint WeightedSum |
14 | 15 | { |
15 | 16 | get |
16 | - {//TODO: Rank deduction for lower chunks | |
17 | - return ( uint )(EditTally.Sum(ed => ed)) + (NewOrLoaded ? 100u : 0u); | |
17 | + {//TODO: Rank ZERO for deep sub-surface chunks | |
18 | + return ( uint )(EditTally.Skip(HeightCutoff - 1).Sum(ed => ed)) + (NewOrLoaded ? 100u : 0u); | |
18 | 19 | } |
19 | 20 | } |
20 | 21 |
@@ -22,12 +23,14 @@ namespace Automap | ||
22 | 23 | { |
23 | 24 | NewOrLoaded = false; |
24 | 25 | EditTally = new byte[chunkSize]; |
26 | + HeightCutoff = 0; | |
25 | 27 | } |
26 | 28 | |
27 | 29 | public ColumnCounter(int chunkSize, bool editLoaded) |
28 | 30 | { |
29 | 31 | NewOrLoaded = editLoaded; |
30 | 32 | EditTally = new byte[chunkSize]; |
33 | + HeightCutoff = 0; | |
31 | 34 | } |
32 | 35 | |
33 | 36 | public ColumnCounter(int chunkSize, bool editLoaded, Vec3i chunkCoord) |
@@ -38,20 +41,28 @@ namespace Automap | ||
38 | 41 | EditTally = new byte[chunkSize]; |
39 | 42 | |
40 | 43 | EditTally[chunkY]++; |
44 | + HeightCutoff = ( byte )chunkY; | |
41 | 45 | } |
42 | 46 | |
43 | 47 | public ColumnCounter Update(Vec3i chunkCoord, int chunkSize, bool partlyNewOrLoaded = false) |
44 | 48 | { |
45 | 49 | int chunkY = chunkCoord.Y % chunkSize; |
46 | - EditTally[chunkY]++; | |
47 | - if (partlyNewOrLoaded) NewOrLoaded = true;; | |
50 | + if (EditTally[chunkY] < Byte.MaxValue) EditTally[chunkY]++; | |
51 | + if (partlyNewOrLoaded) NewOrLoaded = true; | |
48 | 52 | |
49 | 53 | return this; |
50 | 54 | } |
51 | 55 | |
56 | + public void SetCutoff(int height) | |
57 | + { | |
58 | + | |
59 | + HeightCutoff = ( byte )height; | |
60 | + | |
61 | + } | |
62 | + | |
52 | 63 | public override string ToString( ) |
53 | 64 | { |
54 | - return $"{(NewOrLoaded?'N':'O')} W:{WeightedSum}"; | |
65 | + return $"{(NewOrLoaded?"NEW":"Old")} W:{WeightedSum}"; | |
55 | 66 | } |
56 | 67 | } |
57 | 68 | } |
@@ -96,7 +96,8 @@ namespace Automap | ||
96 | 96 | |
97 | 97 | public static ushort RainHeight2DMap(this IMapChunk mapChunk, int x, int y, int chunkSize = 32) |
98 | 98 | { |
99 | - int index = y % chunkSize * chunkSize + x % chunkSize; | |
99 | + //int num = posZ % this.chunksize * this.chunksize + posX % this.chunksize; | |
100 | + int index = (y % chunkSize) * chunkSize + (x % chunkSize); | |
100 | 101 | return mapChunk.RainHeightMap[index]; |
101 | 102 | } |
102 | 103 |
@@ -51,9 +51,11 @@ namespace Automap | ||
51 | 51 | } |
52 | 52 | |
53 | 53 | // Prefetch map chunks, in pattern |
54 | - var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y + 1); | |
54 | + var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1); | |
55 | 55 | var west_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y); |
56 | - var north_pos = new Vec2i(chunkPos.X, chunkPos.Y + 1); | |
56 | + var north_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1); | |
57 | + | |
58 | + uint missingRainmap = 0, missingHeightmap = 0; | |
57 | 59 | |
58 | 60 | ColumnMeta north, northWest, west; |
59 | 61 | /* |
@@ -77,29 +79,31 @@ namespace Automap | ||
77 | 79 | overlapHeightmap[0, 0] = northWest.HeightMap[chunkSize - 1, chunkSize - 1]; |
78 | 80 | } |
79 | 81 | else { |
82 | + missingHeightmap++; | |
80 | 83 | var cornerMC = ClientAPI.World.BlockAccessor.GetMapChunk(corner_pos); |
81 | 84 | if (cornerMC != null && cornerMC.RainHeightMap != null) |
82 | 85 | { |
83 | - overlapHeightmap[0, 0] = cornerMC.RainHeight2DMap(chunkSize - 1, (chunkSize - 1) ); | |
84 | - } | |
85 | - } | |
86 | + overlapHeightmap[0, 0] = cornerMC.RainHeight2DMap(chunkSize - 1, (chunkSize - 1)); | |
87 | + } else missingRainmap++; | |
88 | + } | |
86 | 89 | |
87 | 90 | if (allCols.Contains(north_pos) && allCols[north_pos].HeightMap != null) { |
88 | 91 | north = allCols[north_pos]; |
89 | 92 | |
90 | 93 | for (int northEdgeIndex = 0; northEdgeIndex < chunkSize; northEdgeIndex++) |
91 | 94 | { |
92 | - overlapHeightmap[1, northEdgeIndex + 1 ] = north.HeightMap[ (chunkSize - 1), northEdgeIndex]; | |
95 | + overlapHeightmap[0, northEdgeIndex + 1 ] = north.HeightMap[ (chunkSize - 1), northEdgeIndex]; | |
93 | 96 | } |
94 | 97 | } |
95 | 98 | else { |
99 | + missingHeightmap++; | |
96 | 100 | var northMC = ClientAPI.World.BlockAccessor.GetMapChunk(north_pos); |
97 | 101 | if (northMC != null && northMC.RainHeightMap != null) { |
98 | 102 | for (int northEdgeIndex = 0; northEdgeIndex < chunkSize; northEdgeIndex++) |
99 | 103 | { |
100 | - overlapHeightmap[1, northEdgeIndex + 1] = northMC.RainHeight2DMap((chunkSize - 1), northEdgeIndex); | |
104 | + overlapHeightmap[0, northEdgeIndex + 1] = northMC.RainHeight2DMap((chunkSize - 1), northEdgeIndex); | |
101 | 105 | } |
102 | - } | |
106 | + } else missingRainmap++; | |
103 | 107 | } |
104 | 108 | |
105 | 109 | if (allCols.Contains(west_pos) && allCols[west_pos].HeightMap != null) { |
@@ -111,18 +115,24 @@ namespace Automap | ||
111 | 115 | } |
112 | 116 | } |
113 | 117 | else { |
118 | + missingHeightmap++; | |
114 | 119 | var westMC = ClientAPI.World.BlockAccessor.GetMapChunk(west_pos); |
115 | 120 | if (westMC != null && westMC.RainHeightMap != null) { |
116 | - for (int westEdgeIndex = 0; westEdgeIndex < chunkSize; westEdgeIndex++) { | |
117 | - overlapHeightmap[westEdgeIndex + 1, 0] = westMC.RainHeight2DMap(westEdgeIndex, chunkSize - 1); | |
118 | - } | |
121 | + for (int westEdgeIndex = 0; westEdgeIndex < chunkSize; westEdgeIndex++) { | |
122 | + overlapHeightmap[westEdgeIndex + 1, 0] = westMC.RainHeight2DMap(westEdgeIndex, chunkSize - 1); | |
119 | 123 | } |
124 | + } else missingRainmap++; | |
120 | 125 | } |
121 | 126 | |
122 | - var avgOverlap_Y = overlapHeightmap.OfType<ushort>( ).Average((ushort sel) => sel == 0 ? targetColMeta.YMax : sel); | |
127 | + ushort avgOverlap_Y = ( ushort )overlapHeightmap.OfType<ushort>( ).Average((ushort sel) => sel == 0 ? targetColMeta.YMax : sel); | |
123 | 128 | //TODO: Row - then - Column averaging at Edges? |
124 | - | |
125 | - // if (height == 0) height = ( ushort )avgOverlap_Y; | |
129 | + | |
130 | + #if DEBUG | |
131 | + var badHeightData = overlapHeightmap.OfType<ushort>( ).Count((ushort arg) => arg == 0); | |
132 | + | |
133 | + if (badHeightData > 0) | |
134 | + Logger.VerboseDebug("H.M Zeros# {0} , Missing Rainmaps {1} Heightmaps {2}",badHeightData ,missingRainmap, missingHeightmap); | |
135 | + #endif | |
126 | 136 | |
127 | 137 | |
128 | 138 |
@@ -154,14 +164,14 @@ namespace Automap | ||
154 | 164 | int up_X = localX; |
155 | 165 | int low_X = localX + 1; |
156 | 166 | int left_Z = localZ; |
157 | - int right_Z = localZ + 1; | |
158 | - | |
167 | + int right_Z = localZ + 1; | |
168 | + | |
159 | 169 | //topX = GameMath.Mod(topX, chunkSize + 1); |
160 | - //leftZ = GameMath.Mod(leftZ, chunkSize + 1); | |
170 | + //leftZ = GameMath.Mod(leftZ, chunkSize + 1); | |
161 | 171 | |
162 | - leftTop = Math.Sign(localY - overlapHeightmap[up_X, left_Z]); | |
163 | - rightTop = Math.Sign(localY - overlapHeightmap[up_X, right_Z]); | |
164 | - leftBot = Math.Sign(localY - overlapHeightmap[low_X, left_Z]); | |
172 | + leftTop = Math.Sign(localY - (overlapHeightmap[up_X, left_Z] == 0 ? avgOverlap_Y : overlapHeightmap[up_X, left_Z])); | |
173 | + rightTop = Math.Sign(localY - (overlapHeightmap[up_X, right_Z]== 0 ? avgOverlap_Y : overlapHeightmap[up_X, right_Z])); | |
174 | + leftBot = Math.Sign(localY - (overlapHeightmap[low_X, left_Z]== 0 ? avgOverlap_Y : overlapHeightmap[low_X, left_Z])); | |
165 | 175 | |
166 | 176 | float slopeness = (leftTop + rightTop + leftBot); |
167 | 177 |
@@ -33,7 +33,7 @@ namespace Automap | ||
33 | 33 | |
34 | 34 | internal const string _mapPath = @"Maps"; |
35 | 35 | internal const string _chunkPath = @"Chunks"; |
36 | - internal const uint editThreshold = 1; | |
36 | + internal const uint editThreshold = 9; | |
37 | 37 | private const string _domain = @"automap"; |
38 | 38 | private const string chunkFile_filter = @"*_*.png"; |
39 | 39 | private const string poiFileName = @"poi_binary"; |
@@ -227,6 +227,7 @@ namespace Automap | ||
227 | 227 | #endif |
228 | 228 | } |
229 | 229 | ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta); |
230 | + mostActiveCol.Value.SetCutoff(chunkMeta.YMax / chunkSize); | |
230 | 231 | |
231 | 232 | ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta); |
232 | 233 | ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, ref chunkTopMetadata, out updatedPixels); |
@@ -342,7 +343,7 @@ namespace Automap | ||
342 | 343 | var airBlocksQuery = from airyBlock in ClientAPI.World.Blocks |
343 | 344 | where airyBlock.MatterState == EnumMatterState.Solid |
344 | 345 | where airyBlock.BlockMaterial == EnumBlockMaterial.Plant || airyBlock.BlockMaterial == EnumBlockMaterial.Leaves |
345 | - where airyBlock.CollisionBoxes == null || airyBlock.CollisionBoxes.Length == 0 | |
346 | + where airyBlock.CollisionBoxes == null || airyBlock.CollisionBoxes.Length == 0 ||airyBlock.RainPermeable == true | |
346 | 347 | select airyBlock; |
347 | 348 | //^^ 'Solid' phase - 'Plant' Blocks without any boundg box ? Except water... |
348 | 349 | this.AiryIdCodes = airBlocksQuery.ToDictionary(aBlk => aBlk.BlockId, aBlk => aBlk.Code.Path); |