• R/O
  • HTTP
  • SSH
  • HTTPS

automap: Commit

Automap (OSS) GIT software repository


Commit MetaInfo

Revisionc01a95257de7335354c985472f6924bf80cce0aa (tree)
Time2020-11-14 09:36:19
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Weighted Rankins for Colum Counters,
W.I.P. "Standard" Renderer Heightmap, fix attempt #2

Change Summary

Incremental Difference

--- a/Automap/Automap.csproj
+++ b/Automap/Automap.csproj
@@ -99,6 +99,7 @@
9999 <Compile Include="Subsystems\JsonGenerator.cs" />
100100 <Compile Include="Subsystems\Snapshot.cs" />
101101 <Compile Include="Data\JSON\BlockPosJson.cs" />
102+ <Compile Include="Data\ColumnChanges.cs" />
102103 </ItemGroup>
103104 <ItemGroup>
104105 <Folder Include="VS_libs\" />
--- /dev/null
+++ b/Automap/Data/ColumnCounter.cs
@@ -0,0 +1,57 @@
1+using System;
2+using System.Linq;
3+
4+using Vintagestory.API.MathTools;
5+
6+namespace Automap
7+{
8+ public struct ColumnCounter
9+ {
10+ public bool NewOrLoaded;
11+ public byte[] EditTally;
12+
13+ public uint WeightedSum
14+ {
15+ get
16+ {//TODO: Rank deduction for lower chunks
17+ return ( uint )(EditTally.Sum(ed => ed)) + (NewOrLoaded ? 100u : 0u);
18+ }
19+ }
20+
21+ public ColumnCounter(int chunkSize)
22+ {
23+ NewOrLoaded = false;
24+ EditTally = new byte[chunkSize];
25+ }
26+
27+ public ColumnCounter(int chunkSize, bool editLoaded)
28+ {
29+ NewOrLoaded = editLoaded;
30+ EditTally = new byte[chunkSize];
31+ }
32+
33+ public ColumnCounter(int chunkSize, bool editLoaded, Vec3i chunkCoord)
34+ {
35+ int chunkY = chunkCoord.Y % chunkSize;
36+
37+ NewOrLoaded = editLoaded;
38+ EditTally = new byte[chunkSize];
39+
40+ EditTally[chunkY]++;
41+ }
42+
43+ public ColumnCounter Update(Vec3i chunkCoord, int chunkSize)
44+ {
45+ int chunkY = chunkCoord.Y % chunkSize;
46+ EditTally[chunkY]++;
47+
48+ return this;
49+ }
50+
51+ public override string ToString( )
52+ {
53+ return $"{(NewOrLoaded?'N':'O')} W:{WeightedSum}";
54+ }
55+}
56+}
57+
--- a/Automap/Renderers/StandardRenderer.cs
+++ b/Automap/Renderers/StandardRenderer.cs
@@ -56,30 +56,35 @@ namespace Automap
5656 var west = new Vec2i(chunkPos.X - 1, chunkPos.Y);
5757 var south = new Vec2i(chunkPos.X, chunkPos.Y - 1);
5858
59+ bool nullSouthWest = false, nullSouth = false, nullWest = false;
60+
5961 /*
6062 For missing corners / cardinal heightmaps...
6163 make fake heightmap dummy
6264 */
6365
6466 if (allCols.Contains(south_west)) {
65- mapCornerChunks.Add(allCols[south_west]);
67+ mapCornerChunks.Add(allCols[south_west]);
6668 }
67- else {
68- mapCornerChunks.Add(targetColMeta);//TODO: Make mirror image - heightmap
69+ else {
70+ nullSouthWest = true;
71+ mapCornerChunks.Add(targetColMeta);//Temporary!
6972 }
7073
7174 if (allCols.Contains(south)) {
7275 mapCornerChunks.Add(allCols[south]);
7376 }
7477 else {
75- mapCornerChunks.Add(targetColMeta);//TODO: Make mirror image - heightmap
78+ nullSouth = true;
79+ mapCornerChunks.Add(targetColMeta);//Temporary!
7680 }
7781
7882 if (allCols.Contains(west)) {
7983 mapCornerChunks.Add(allCols[west]);
8084 }
8185 else {
82- mapCornerChunks.Add(targetColMeta);//TODO: Make mirror image - heightmap
86+ nullWest = true;
87+ mapCornerChunks.Add(targetColMeta);//Temporary!
8388 }
8489
8590
@@ -128,9 +133,9 @@ namespace Automap
128133 topX = GameMath.Mod(topX, chunkSize);
129134 leftZ = GameMath.Mod(leftZ, chunkSize);
130135
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]);
136+ leftTop = nullSouthWest ? 0 : Math.Sign(localY - leftTopMapChunk.HeightMap[topX, leftZ]);
137+ rightTop = nullSouth ? 0 : Math.Sign(localY - rightTopMapChunk.HeightMap[topX, rightZ]);
138+ leftBot = nullWest ? 0 : Math.Sign(localY - leftBotMapChunk.HeightMap[botX, leftZ]);
134139
135140 float slopeness = (leftTop + rightTop + leftBot);
136141
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -33,6 +33,7 @@ namespace Automap
3333
3434 internal const string _mapPath = @"Maps";
3535 internal const string _chunkPath = @"Chunks";
36+ internal const uint editThreshold = 1;
3637 private const string _domain = @"automap";
3738 private const string chunkFile_filter = @"*_*.png";
3839 private const string poiFileName = @"poi_binary";
@@ -40,7 +41,7 @@ namespace Automap
4041 private const string pointsTsvFileName = @"points_of_interest.tsv";
4142 private static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+)\.png", RegexOptions.Singleline);
4243
43- private ConcurrentDictionary<Vec2i, uint> columnCounter = new ConcurrentDictionary<Vec2i, uint>(3, 150);
44+ private ConcurrentDictionary<Vec2i, ColumnCounter> columnCounters = new ConcurrentDictionary<Vec2i, ColumnCounter>(3, 150);
4445 private ColumnsMetadata chunkTopMetadata;
4546 private PointsOfInterest POIs = new PointsOfInterest();
4647 private EntitiesOfInterest EOIs = new EntitiesOfInterest();
@@ -132,14 +133,14 @@ namespace Automap
132133
133134 private void ChunkAChanging(Vec3i chunkCoord, IWorldChunk chunk, EnumChunkDirtyReason reason)
134135 {
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- //}
136+ Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z);
137+ bool newOrEdit = (reason == EnumChunkDirtyReason.NewlyCreated || reason == EnumChunkDirtyReason.NewlyLoaded);
138+
139+ columnCounters.AddOrUpdate(topPosition,
140+ new ColumnCounter(chunkSize, newOrEdit, chunkCoord),
141+ (chkPos, chkChng) => chkChng.Update(chunkCoord, chunkSize)
142+ );
143+
143144 }
144145
145146 private void AwakenCartographer(float delayed)
@@ -185,14 +186,14 @@ namespace Automap
185186
186187 try
187188 {
188- uint ejectedItem = 0;
189+ ColumnCounter ejectedItem ;
189190 uint updatedChunks = 0;
190191 uint updatedPixels = 0;
191192
192193 //-- Should dodge enumerator changing underfoot....at a cost.
193- if (!columnCounter.IsEmpty)
194+ if (!columnCounters.IsEmpty)
194195 {
195- var tempSet = columnCounter.ToArray().OrderByDescending(kvp => kvp.Value);
196+ var tempSet = columnCounters.ToArray().Where(cks => cks.Value.WeightedSum > editThreshold) .OrderByDescending(kvp => kvp.Value.WeightedSum);
196197 UpdateEntityMetadata();
197198
198199 foreach (var mostActiveCol in tempSet)
@@ -204,7 +205,7 @@ namespace Automap
204205 //TODO: REVISIT THIS CHUNK!
205206 Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
206207 nullMapCount++;
207- columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
208+ columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
208209 continue;
209210 }
210211
@@ -231,15 +232,15 @@ namespace Automap
231232 if (updatedPixels > 0)
232233 {
233234 #if DEBUG
234- Logger.VerboseDebug("Wrote top-chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels);
235+ Logger.VerboseDebug("Wrote top-chunk shard: ({0}) - Weight:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels);
235236 #endif
236237 updatedChunks++;
237238 chunkTopMetadata.Update(chunkMeta);
238- columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
239+ columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
239240 }
240241 else
241242 {
242- columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
243+ columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
243244 #if DEBUG
244245 Logger.VerboseDebug("Un-painted chunk shard: ({0}) ", mostActiveCol.Key);
245246 #endif
@@ -260,6 +261,12 @@ namespace Automap
260261 chunkTopMetadata.ClearMetadata( );
261262 }
262263
264+ #if DEBUG
265+ Logger.VerboseDebug("Clearing Column Counters of: {0} non-written shards", columnCounters.Count);
266+ #endif
267+
268+ columnCounters.Clear( );
269+
263270 //Then sleep until interupted again, and repeat
264271 #if DEBUG
265272 Logger.VerboseDebug("Thread '{0}' about to sleep indefinitely.", Thread.CurrentThread.Name);
@@ -440,7 +447,7 @@ namespace Automap
440447
441448 }
442449
443- private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, uint> mostActiveCol, IMapChunk mapChunk)
450+ private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, ColumnCounter> mostActiveCol, IMapChunk mapChunk)
444451 {
445452 ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), ClientAPI, (byte) chunkSize, (ClientAPI.World.BlockAccessor.MapSizeY / chunkSize));
446453 BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize,
Show on old repository browser