• R/O
  • HTTP
  • SSH
  • HTTPS

automap: Commit

Automap (OSS) GIT software repository


Commit MetaInfo

Revision8c8161c8be42749b0fd0cc90bf3298052a13d355 (tree)
Time2022-05-28 05:53:19
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Revisit(er) & ReadOnly chunk use

Plus minor fix for possible null BlockEntity.pos

Change Summary

Incremental Difference

--- a/Automap/Designators/DefaultDesignators.cs
+++ b/Automap/Designators/DefaultDesignators.cs
@@ -161,9 +161,9 @@ namespace Automap
161161
162162 internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
163163 {
164-#if DEBUG
164+ #if DEBUG
165165 clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!");
166-#endif
166+ #endif
167167 //sign post Text into a POI field...
168168 BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost;
169169
@@ -185,6 +185,9 @@ namespace Automap
185185
186186 internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity)
187187 {
188+ #if DEBUG
189+ clientAPI.Logger.VerboseDebug("TRADER Designator Invoked!");
190+ #endif
188191 //clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn);
189192
190193 var traderJoe = entity as EntityTrader;
--- a/Automap/Subsystems/AutomapSystem.cs
+++ b/Automap/Subsystems/AutomapSystem.cs
@@ -44,6 +44,7 @@ namespace Automap
4444 private static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+)\.png", RegexOptions.Singleline);
4545
4646 private ConcurrentDictionary<Vec2i, ColumnCounter> columnCounters = new ConcurrentDictionary<Vec2i, ColumnCounter>(3, 150);
47+ private Queue<Vec2i> revisitChunkList = new Queue<Vec2i>();
4748 private ColumnsMetadata chunkTopMetadata;
4849 internal PointsOfInterest POIs = new PointsOfInterest();
4950 internal EntitiesOfInterest EOIs = new EntitiesOfInterest();
@@ -175,7 +176,7 @@ namespace Automap
175176 }
176177 else if (snapshot != null && snapshot.Finished) {
177178 #if DEBUG
178- Logger.VerboseDebug("COMPLETED Snapshot: {0} Wx{1} Hx{2}, taking {3}", snapshot.fileName, snapshot.Width, snapshot.Height, snapshot.Timer.Elapsed);
179+ Logger.VerboseDebug("COMPLETED Snapshot: {0} Wx{1} Hx{2}, taking {3}", snapshot.fileName, snapshot.Width, snapshot.Height, snapshot.Timer.Elapsed);
179180 #endif
180181 snapshot = null;
181182 CurrentState = CommandType.Run;
@@ -195,10 +196,50 @@ namespace Automap
195196 uint updatedChunks = 0;
196197 uint updatedPixels = 0;
197198
198- //-- Should dodge enumerator changing underfoot....at a cost.
199- if (!columnCounters.IsEmpty)
200- {
201- var tempSet = columnCounters.ToArray().Where(cks => cks.Value.WeightedSum > editThreshold) .OrderByDescending(kvp => kvp.Value.WeightedSum);
199+
200+ //Revisit failed chunks first;
201+ while (revisitChunkList.Count > 0)
202+ {
203+ var revisitCoord = revisitChunkList.Dequeue( );
204+ var rv_mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(revisitCoord);
205+
206+ if (rv_mapChunk == null) continue;
207+
208+ ColumnMeta rv_chunkMeta;
209+ if (chunkTopMetadata.Contains(revisitCoord))
210+ {
211+ rv_chunkMeta = chunkTopMetadata[revisitCoord];
212+ #if DEBUG
213+ Logger.VerboseDebug("(re)Loaded meta-chunk {0}", revisitCoord);
214+ #endif
215+ }
216+ else
217+ {
218+ rv_chunkMeta = CreateColumnMetadata(revisitCoord, rv_mapChunk);
219+ #if DEBUG
220+ Logger.VerboseDebug("(re)Created meta-chunk {0}", revisitCoord);
221+ #endif
222+ }
223+
224+ ProcessChunkBlocks(revisitCoord, rv_mapChunk, ref rv_chunkMeta);
225+
226+ ChunkRenderer.SetupPngImage(revisitCoord, path, _chunkPath, ref rv_chunkMeta);
227+ ChunkRenderer.GenerateChunkPngShard(revisitCoord, rv_mapChunk, rv_chunkMeta, ref chunkTopMetadata, out updatedPixels);
228+
229+ if (updatedPixels > 0)
230+ {
231+ #if DEBUG
232+ Logger.VerboseDebug("(re)Wrote top-chunk shard: ({0}), Pixels#:{2}", revisitCoord, updatedPixels);
233+ #endif
234+ updatedChunks++;
235+ chunkTopMetadata.Update(rv_chunkMeta);
236+ }
237+ }//*********** REVISIT'd ******************
238+
239+ if (!columnCounters.IsEmpty)
240+ {//-- Should dodge enumerator changing underfoot....at a cost.
241+ var tempSet = columnCounters.ToArray().Where(cks => cks.Value.WeightedSum > editThreshold) .OrderByDescending(kvp => kvp.Value.WeightedSum);
242+
202243 UpdateEntityMetadata();
203244
204245 foreach (var mostActiveCol in tempSet)
@@ -206,13 +247,13 @@ namespace Automap
206247 var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key);
207248
208249 if (mapChunk == null)
209- {
210- //TODO: REVISIT THIS CHUNK!
250+ {
211251 #if DEBUG
212252 Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
213253 #endif
214254 nullMapCount++;
215255 columnCounters.TryRemove(mostActiveCol.Key, out ejectedItem);
256+ revisitChunkList.Enqueue(mostActiveCol.Key);
216257 continue;
217258 }
218259
@@ -252,6 +293,7 @@ namespace Automap
252293 #if DEBUG
253294 Logger.VerboseDebug("Un-painted chunk shard: ({0}) ", mostActiveCol.Key);
254295 #endif
296+ revisitChunkList.Enqueue(mostActiveCol.Key);
255297 }
256298 }
257299 }
@@ -276,32 +318,32 @@ namespace Automap
276318 columnCounters.Clear( );
277319
278320 //Then sleep until interupted again, and repeat
279-#if DEBUG
321+ #if DEBUG
280322 Logger.VerboseDebug("Thread '{0}' about to sleep indefinitely.", Thread.CurrentThread.Name);
281-#endif
323+ #endif
282324 Thread.Sleep(Timeout.Infinite);
283325
284326 }
285327 catch (ThreadInterruptedException)
286328 {
287329
288-#if DEBUG
330+ #if DEBUG
289331 Logger.VerboseDebug("Thread '{0}' interupted [awoken]", Thread.CurrentThread.Name);
290-#endif
332+ #endif
291333 goto wake;
292334
293335 }
294336 catch (ThreadAbortException)
295337 {
296-#if DEBUG
338+ #if DEBUG
297339 Logger.VerboseDebug("Thread '{0}' aborted.", Thread.CurrentThread.Name);
298-#endif
340+ #endif
299341 }
300342 finally
301343 {
302-#if DEBUG
344+ #if DEBUG
303345 Logger.VerboseDebug("Thread '{0}' executing finally block.", Thread.CurrentThread.Name);
304-#endif
346+ #endif
305347 PersistPointsData();
306348 Write_PlainMetadata( );
307349 }
@@ -310,23 +352,23 @@ namespace Automap
310352 private void Snap()
311353 {
312354 snapshotTake:
313-#if DEBUG
355+ #if DEBUG
314356 Logger.VerboseDebug("Snapshot started");
315-#endif
357+ #endif
316358 try
317359 {
318360 snapshot.Take();
319-#if DEBUG
361+ #if DEBUG
320362 Logger.VerboseDebug("Snapshot sleeping");
321-#endif
363+ #endif
322364 CurrentState = CommandType.Run;
323365 Thread.Sleep(Timeout.Infinite);
324366 }
325367 catch (ThreadInterruptedException)
326368 {
327-#if DEBUG
369+ #if DEBUG
328370 Logger.VerboseDebug("Snapshot intertupted");
329-#endif
371+ #endif
330372 goto snapshotTake;
331373 }
332374 }
@@ -512,6 +554,19 @@ namespace Automap
512554 return data;
513555 }
514556
557+ private ColumnMeta CreateColumnMetadata(Vec2i coords, IMapChunk mapChunk)
558+ {
559+ ColumnMeta data = new ColumnMeta(coords, ClientAPI, ( byte )chunkSize, (ClientAPI.World.BlockAccessor.MapSizeY / chunkSize));
560+ BlockPos equivBP = new BlockPos(coords.X * chunkSize,
561+ mapChunk.YMax,
562+ coords.Y * chunkSize);
563+
564+ var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP);
565+ data.UpdateFieldsFrom(climate, mapChunk, TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours));
566+
567+ return data;
568+ }
569+
515570 /// <summary>
516571 /// Reload chunk bounds from chunk shards
517572 /// </summary>
@@ -626,7 +681,7 @@ namespace Automap
626681 if (worldChunk == null || worldChunk.BlockEntities == null)
627682 {
628683 #if DEBUG
629- Logger.VerboseDebug("WORLD chunk: null or empty X{0} Y{1} Z{2} !", key.X, targetChunkY, key.Y);
684+ Logger.VerboseDebug("WORLD chunk: null, B.E. null X{0} Y{1} Z{2} !", key.X, targetChunkY, key.Y);
630685 #endif
631686 nullChunkCount++;
632687 continue;
@@ -637,7 +692,13 @@ namespace Automap
637692 #if DEBUG
638693 Logger.VerboseDebug("WORLD chunk: Compressed: X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y);
639694 #endif
640- worldChunk.Unpack( );//RESEARCH: Thread Unsafe?
695+ //VALIDATE: check Read-only applicable
696+ if (worldChunk.Unpack_ReadOnly( ) == false)
697+ {
698+ Logger.Warning("Failed to unpack chunk: X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y);
699+ nullChunkCount++;
700+ continue;
701+ };
641702 }
642703
643704 /*************** Chunk Entities Scanning *********************/
@@ -649,7 +710,7 @@ namespace Automap
649710
650711 foreach (var blockEnt in worldChunk.BlockEntities)
651712 {
652- if (blockEnt.Key != null && blockEnt.Value != null && blockEnt.Value.Block != null && BlockID_Designators.ContainsKey(blockEnt.Value.Block.BlockId))
713+ if (blockEnt.Key != null && blockEnt.Value != null && blockEnt.Value.Block != null && blockEnt.Value.Pos != null && BlockID_Designators.ContainsKey(blockEnt.Value.Block.BlockId))
653714 {
654715 var designator = BlockID_Designators[blockEnt.Value.Block.BlockId];
655716 designator?.SpecialAction(ClientAPI, POIs, blockEnt.Value.Pos.Copy(), blockEnt.Value.Block);
@@ -663,7 +724,7 @@ namespace Automap
663724 int X_index, Y_index, Z_index;
664725
665726 //First Chance fail-safe;
666- if (worldChunk.Blocks == null || worldChunk.Blocks.Length <= 0) {
727+ if (worldChunk.MaybeBlocks == null || worldChunk.MaybeBlocks.Length <= 0) {
667728 #if DEBUG
668729 Logger.VerboseDebug("WORLD chunk; Missing block DATA⁈ X{0} Y{1} Z{2} ⁈", key.X, targetChunkY, key.Y);
669730 #endif
@@ -682,7 +743,7 @@ namespace Automap
682743 var indicie = MapUtil.Index3d(X_index, Y_index, Z_index, chunkSize, chunkSize);
683744
684745 //'Last' Chance fail-safe;
685- if (worldChunk.Blocks == null || worldChunk.Blocks.Length <= 0) {
746+ if (worldChunk.MaybeBlocks == null || worldChunk.MaybeBlocks.Length <= 0) {
686747 #if DEBUG
687748 Logger.VerboseDebug("Processing Block: Missing block DATA⁈ X{0} Y{1} Z{2} ⁈", X_index, Y_index, Z_index);
688749 #endif
@@ -690,7 +751,7 @@ namespace Automap
690751 goto loop_bustout;
691752 }
692753
693- int aBlockId = worldChunk.Blocks[indicie];
754+ int aBlockId = worldChunk.MaybeBlocks[indicie];
694755
695756 if (aBlockId == 0 || AiryIdCodes.ContainsKey(aBlockId)) {//Airy blocks,,,
696757 chunkMeta.AirBlocks++;
--- a/Automap/modinfo.json
+++ b/Automap/modinfo.json
@@ -7,7 +7,7 @@
77 "version": "0.1.8",
88 "side":"Client",
99 "dependencies": {
10- "game": "1.16.4"
10+ "game": "1.16.5"
1111 },
1212 "website": "http://automap.osdn.io/"
1313 }
\ No newline at end of file
Show on old repository browser