2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
9 using System.Text.RegularExpressions;
10 using System.Threading;
14 using Hjg.Pngcs.Chunks;
16 using Vintagestory.API.Client;
17 using Vintagestory.API.Common;
18 using Vintagestory.API.Common.Entities;
19 using Vintagestory.API.Config;
20 using Vintagestory.API.MathTools;
21 using Vintagestory.Common;
25 public class AutomapSystem
27 private Thread cartographer_thread;
28 private ICoreClientAPI ClientAPI { get; set; }
29 private ILogger Logger { get; set; }
30 private IChunkRenderer ChunkRenderer { get; set; }
32 private const string _mapPath = @"Maps";
33 private const string _chunkPath = @"Chunks";
34 private const string _domain = @"automap";
35 private const string chunkFile_filter = @"*_*.png";
36 private static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+).png", RegexOptions.Singleline);
38 private ConcurrentDictionary<Vec2i, uint> columnCounter = new ConcurrentDictionary<Vec2i, uint>(3, 150 );
39 private ColumnsMetadata chunkTopMetadata;
40 private PointsOfInterest POIs;
41 private EntitiesOfInterest EOIs;
43 internal Dictionary<int, BlockDesignator> BlockID_Designators { get; private set;}
44 internal Dictionary<AssetLocation, EntityDesignator> Entity_Designators { get; private set; }
45 internal Dictionary<int, string> RockIdCodes { get; private set; }
47 internal bool Enabled { get; set; }
48 //Run status, Chunks processed, stats, center of map....
49 private uint nullChunkCount, updatedChunksTotal;
50 private Vec2i startChunkColumn;
52 private readonly int chunkSize;
54 private IAsset stylesFile;
56 public static string automapStatusEventKey = @"AutomapStatus";
59 public AutomapSystem(ICoreClientAPI clientAPI, ILogger logger)
61 this.ClientAPI = clientAPI;
63 chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
64 ClientAPI.Event.LevelFinalize += EngageAutomap;
66 //TODO:Choose which one from GUI
67 this.ChunkRenderer = new StandardRenderer(clientAPI, logger);
72 private void EngageAutomap( )
74 path = ClientAPI.GetOrCreateDataPath(_mapPath);
75 path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too...'ServerApi.WorldManager.CurrentWorldName'
77 stylesFile = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap_format.css"));
78 Logger.VerboseDebug("CSS loaded: {0} size: {1}",stylesFile.IsLoaded() ,stylesFile.ToText( ).Length);
80 Prefill_POI_Designators( );
81 startChunkColumn = new Vec2i((ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.X / chunkSize), (ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Z / chunkSize));
82 chunkTopMetadata = new ColumnsMetadata(startChunkColumn);
84 Logger.Notification("AUTOMAP Start {0}", startChunkColumn);
87 ClientAPI.Event.ChunkDirty += ChunkAChanging;
89 cartographer_thread = new Thread(Cartographer);
90 cartographer_thread.Name = "Cartographer";
91 cartographer_thread.Priority = ThreadPriority.Lowest;
92 cartographer_thread.IsBackground = true;
94 ClientAPI.Event.RegisterGameTickListener(AwakenCartographer, 6000);
97 private void ChunkAChanging(Vec3i chunkCoord, IWorldChunk chunk, EnumChunkDirtyReason reason)
99 Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z);
101 columnCounter.AddOrUpdate(topPosition, 1, (key, colAct) => colAct + 1);
104 private void AwakenCartographer(float delayed)
107 if (Enabled && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true)) {
109 Logger.VerboseDebug("Cartographer re-trigger from [{0}]", cartographer_thread.ThreadState);
112 if (cartographer_thread.ThreadState.HasFlag(ThreadState.Unstarted)) {
113 cartographer_thread.Start( );
115 else if (cartographer_thread.ThreadState.HasFlag(ThreadState.WaitSleepJoin)) {
116 //Time to (re)write chunk shards
117 cartographer_thread.Interrupt( );
120 ClientAPI.TriggerChatMessage($"Automap {updatedChunksTotal} Updates - MAX (N:{chunkTopMetadata.North_mostChunk},S:{chunkTopMetadata.South_mostChunk},E:{chunkTopMetadata.East_mostChunk}, W:{chunkTopMetadata.West_mostChunk} - TOTAL: {chunkTopMetadata.Count})");
127 private void Cartographer( )
130 Logger.VerboseDebug("Cartographer thread awoken");
133 uint ejectedItem = 0;
134 uint updatedChunks = 0;
136 //-- Should dodge enumerator changing underfoot....at a cost.
137 if (!columnCounter.IsEmpty) {
138 var tempSet = columnCounter.ToArray( ).OrderByDescending(kvp => kvp.Value);
139 foreach (var mostActiveCol in tempSet) {
141 var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key);
143 if (mapChunk == null) {
144 Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
146 columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem );
150 ColumnMeta chunkMeta = CreateColumnMetadata(mostActiveCol,mapChunk);
151 PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, chunkMeta);
152 UpdateEntityMetadata( );
153 ProcessChunkBlocks(mostActiveCol.Key, mapChunk, chunkMeta);
155 uint updatedPixels = 0;
157 ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter , out updatedPixels);
159 if (updatedPixels > 0) {
162 Logger.VerboseDebug("Wrote chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels);
165 chunkTopMetadata.Update(chunkMeta);
166 columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
169 columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
170 Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key);
176 UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks);
178 if (updatedChunks > 0) {
179 //What about chunk updates themselves; a update bitmap isn't kept...
180 updatedChunksTotal += updatedChunks;
185 //Then sleep until interupted again, and repeat
187 Logger.VerboseDebug("Thread '{0}' about to sleep indefinitely.", Thread.CurrentThread.Name);
189 Thread.Sleep(Timeout.Infinite);
191 } catch (ThreadInterruptedException) {
193 Logger.VerboseDebug("Thread '{0}' interupted [awoken]", Thread.CurrentThread.Name);
196 } catch (ThreadAbortException) {
197 Logger.VerboseDebug("Thread '{0}' aborted.", Thread.CurrentThread.Name);
200 Logger.VerboseDebug("Thread '{0}' executing finally block.", Thread.CurrentThread.Name);
204 private void UpdateStatus( uint totalUpdates, uint voidChunks, uint delta)
206 StatusData updateData = new StatusData(totalUpdates, voidChunks, delta);
208 this.ClientAPI.Event.PushEvent(automapStatusEventKey, updateData);
211 private void Prefill_POI_Designators( )
213 this.POIs = new PointsOfInterest( );
214 this.EOIs = new EntitiesOfInterest( );
215 this.BlockID_Designators = new Dictionary<int, BlockDesignator>( );
216 this.Entity_Designators = new Dictionary<AssetLocation, EntityDesignator>( );
217 this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock"), EnumBlockMaterial.Stone);
219 //Add special marker types for BlockID's of "Interest", overwrite colour, and method
221 Install_POI_Designators(DefaultDesignators.DefaultBlockDesignators(), DefaultDesignators.DefaultEntityDesignators());
224 private void Install_POI_Designators(ICollection<BlockDesignator> blockDesig, List<EntityDesignator> entDesig)
226 Logger.VerboseDebug("Connecting {0} standard Block-Designators", blockDesig.Count);
227 foreach (var designator in blockDesig) {
228 var blockIDs = Helpers.ArbitrarytBlockIdHunter(ClientAPI, designator.Pattern, designator.Material);
229 if (blockIDs.Count > 0) { Logger.VerboseDebug("Designator {0} has {1} associated blockIDs", designator.ToString( ), blockIDs.Count); }
230 foreach (var entry in blockIDs) {
231 BlockID_Designators.Add(entry.Key, designator);
234 this.ChunkRenderer.BlockID_Designators = BlockID_Designators;
237 Logger.VerboseDebug("Connecting {0} standard Entity-Designators", entDesig.Count);
238 foreach (var designator in entDesig) {
239 //Get Variants first, from EntityTypes...better be populated!
240 var matched = ClientAPI.World.EntityTypes.FindAll(entp => entp.Code.BeginsWith(designator.Pattern.Domain, designator.Pattern.Path));
242 foreach (var match in matched) {
243 Logger.VerboseDebug("Linked Entity: {0} Designator: {1}", match.Code, designator);
244 this.Entity_Designators.Add(match.Code, designator);
249 //EntityProperties props = ClientAPI.World.GetEntityType(designator.Pattern);
255 //TODO: Convert to RAZOR model
256 private void GenerateMapHTML( )
258 string mapFilename = Path.Combine(path, "Automap.html");
260 int TopNorth = chunkTopMetadata.North_mostChunk;
261 int TopSouth = chunkTopMetadata.South_mostChunk;
262 int TopEast = chunkTopMetadata.East_mostChunk;
263 int TopWest = chunkTopMetadata.West_mostChunk;
265 using (StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))) {
266 using (HtmlTextWriter tableWriter = new HtmlTextWriter(outputText)) {
267 tableWriter.BeginRender( );
268 tableWriter.RenderBeginTag(HtmlTextWriterTag.Html);
270 tableWriter.RenderBeginTag(HtmlTextWriterTag.Head);
271 tableWriter.RenderBeginTag(HtmlTextWriterTag.Title);
272 tableWriter.WriteEncodedText("Generated Automap");
273 tableWriter.RenderEndTag( );
275 tableWriter.RenderBeginTag(HtmlTextWriterTag.Style);
276 tableWriter.Write(stylesFile.ToText( ));
277 tableWriter.RenderEndTag( );//</style>
279 //## JSON map-state data ######################
280 tableWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
281 tableWriter.RenderBeginTag(HtmlTextWriterTag.Script);
283 tableWriter.Write("var available_images = [");
285 foreach (var shard in this.chunkTopMetadata) {
286 tableWriter.Write("{{X:{0},Y:{1} }}, ", shard.Location.X, shard.Location.Y);
289 tableWriter.Write(" ];\n");
291 tableWriter.RenderEndTag( );
293 tableWriter.RenderEndTag( );
295 tableWriter.RenderBeginTag(HtmlTextWriterTag.Body);
296 tableWriter.RenderBeginTag(HtmlTextWriterTag.P);
297 tableWriter.WriteEncodedText($"Created {DateTimeOffset.UtcNow.ToString("u")}");
298 tableWriter.RenderEndTag( );
299 tableWriter.RenderBeginTag(HtmlTextWriterTag.P);
300 tableWriter.WriteEncodedText($"W:{TopWest}, E: {TopEast}, N:{TopNorth}, S:{TopSouth} ");
301 tableWriter.RenderEndTag( );
302 tableWriter.WriteLine( );
303 tableWriter.RenderBeginTag(HtmlTextWriterTag.Table);
304 tableWriter.RenderBeginTag(HtmlTextWriterTag.Caption);
305 tableWriter.WriteEncodedText($"Start: {startChunkColumn}, Seed: {ClientAPI.World.Seed}\n");
306 tableWriter.RenderEndTag( );
308 //################ X-Axis <thead> #######################
309 tableWriter.RenderBeginTag(HtmlTextWriterTag.Thead);
310 tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
312 tableWriter.RenderBeginTag(HtmlTextWriterTag.Th);
313 tableWriter.Write("N, W");
314 tableWriter.RenderEndTag( );
316 for (int xAxisT = TopWest; xAxisT <= TopEast; xAxisT++) {
317 tableWriter.RenderBeginTag(HtmlTextWriterTag.Th);
318 tableWriter.Write(xAxisT);
319 tableWriter.RenderEndTag( );
322 tableWriter.RenderBeginTag(HtmlTextWriterTag.Th);
323 tableWriter.Write("N, E");
324 tableWriter.RenderEndTag( );
326 tableWriter.RenderEndTag( );
327 tableWriter.RenderEndTag( );
328 //###### </thead> ################################
330 //###### <tbody> - Chunk rows & Y-axis cols
331 tableWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);
333 //######## <tr> for every vertical row
334 for (int yAxis = TopNorth; yAxis <= TopSouth; yAxis++) {
335 tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
336 tableWriter.RenderBeginTag(HtmlTextWriterTag.Td);
337 tableWriter.Write(yAxis);//legend: Y-axis
338 tableWriter.RenderEndTag( );
340 for (int xAxis = TopWest; xAxis <= TopEast; xAxis++) {
341 //###### <td> #### for chunk shard
342 tableWriter.RenderBeginTag(HtmlTextWriterTag.Td);
343 var colLoc = new Vec2i(xAxis, yAxis);
344 if (chunkTopMetadata.Contains( colLoc)){
345 ColumnMeta meta = chunkTopMetadata[colLoc];
347 tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip");
348 tableWriter.RenderBeginTag(HtmlTextWriterTag.Div);
350 tableWriter.AddAttribute(HtmlTextWriterAttribute.Src, $"{xAxis}_{yAxis}.png");
351 tableWriter.RenderBeginTag(HtmlTextWriterTag.Img);
352 tableWriter.RenderEndTag( );
353 // <span class="tooltiptext">Tooltip text
354 tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltiptext");
355 tableWriter.RenderBeginTag(HtmlTextWriterTag.Span);
357 StringBuilder tooltipText = new StringBuilder( );
358 tooltipText.Append($"{meta.Location.PrettyCoords(ClientAPI)} ");
359 tooltipText.Append($" Max-Height: {meta.YMax}, Temp: {meta.Temperature.ToString("F1")} " );
360 tooltipText.Append($" Rainfall: {meta.Rainfall.ToString("F1")}, ");
361 tooltipText.Append($" Shrubs: {meta.ShrubDensity.ToString("F1")}, ");
362 tooltipText.Append($" Forest: {meta.ForestDensity.ToString("F1")}, ");
363 tooltipText.Append($" Fertility: {meta.Fertility.ToString("F1")}, ");
365 if (meta.RockRatio != null) {
366 foreach (KeyValuePair<int, uint> blockID in meta.RockRatio) {
367 var block = ClientAPI.World.GetBlock(blockID.Key);
368 tooltipText.AppendFormat(" {0} × {1},\t", block.Code.GetName( ), meta.RockRatio[blockID.Key]);
372 tableWriter.WriteEncodedText(tooltipText.ToString() );
374 tableWriter.RenderEndTag( );//</span>
377 tableWriter.RenderEndTag( );//</div> --tooltip enclosure
380 tableWriter.Write("?");
383 tableWriter.RenderEndTag( );
384 }//############ </td> ###########
386 tableWriter.RenderBeginTag(HtmlTextWriterTag.Td);
387 tableWriter.Write(yAxis);//legend: Y-axis
388 tableWriter.RenderEndTag( );
390 tableWriter.RenderEndTag( );
393 tableWriter.RenderEndTag( );
395 //################ X-Axis <tfoot> #######################
396 tableWriter.RenderBeginTag(HtmlTextWriterTag.Tfoot);
397 tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
399 tableWriter.RenderBeginTag(HtmlTextWriterTag.Td);
400 tableWriter.Write("S, W");
401 tableWriter.RenderEndTag( );
403 for (int xAxisB = TopWest; xAxisB <= TopEast; xAxisB++) {
404 tableWriter.RenderBeginTag(HtmlTextWriterTag.Td);
405 tableWriter.Write(xAxisB);
406 tableWriter.RenderEndTag( );
409 tableWriter.RenderBeginTag(HtmlTextWriterTag.Td);
410 tableWriter.Write("S, E");
411 tableWriter.RenderEndTag( );
413 tableWriter.RenderEndTag( );
414 tableWriter.RenderEndTag( );
415 //###### </tfoot> ################################
418 tableWriter.RenderEndTag( );//</table>
420 //############## POI list #####################
421 tableWriter.RenderBeginTag(HtmlTextWriterTag.P);
422 tableWriter.WriteLine("Points of Interest");
423 tableWriter.RenderEndTag( );
424 tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul);
425 foreach (var poi in this.POIs) {
426 tableWriter.RenderBeginTag(HtmlTextWriterTag.Li);
427 tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI)+"\t");
428 tableWriter.WriteEncodedText(poi.Notes+ "\t");
429 tableWriter.WriteEncodedText(poi.Timestamp.ToString("u"));
430 tableWriter.RenderEndTag( );
433 foreach (var eoi in this.EOIs.PointsList) {
434 tableWriter.RenderBeginTag(HtmlTextWriterTag.Li);
435 tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI)+ "\t");
436 tableWriter.WriteEncodedText(eoi.Notes+ "\t");
437 tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u") );
438 tableWriter.RenderEndTag( );
441 tableWriter.RenderEndTag( );
446 tableWriter.RenderEndTag( );//### </BODY> ###
448 tableWriter.EndRender( );
449 tableWriter.Flush( );
454 Logger.VerboseDebug("Generated HTML map");
459 private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, uint> mostActiveCol, IMapChunk mapChunk)
461 ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), chunkSize);
462 BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize,
464 mostActiveCol.Key.Y * chunkSize);
466 var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP);
467 data.UpdateFieldsFrom(climate, mapChunk,TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours));
473 /// Reload chunk bounds from chunk shards
475 /// <returns>The metadata.</returns>
476 private void Reload_Metadata( )
478 var worldmapDir = new DirectoryInfo(path);
480 if (worldmapDir.Exists) {
482 var files = worldmapDir.GetFiles(chunkFile_filter);
484 if (files.Length > 0) {
486 Logger.VerboseDebug("{0} Existing world chunk shards", files.Length);
491 foreach (var shardFile in files) {
493 if (shardFile.Length < 512) continue;
494 var result = chunkShardRegex.Match(shardFile.Name);
495 if (result.Success) {
496 int X_chunk_pos = int.Parse(result.Groups["X"].Value );
497 int Z_chunk_pos = int.Parse(result.Groups["Z"].Value );
499 //Parse PNG chunks for METADATA in shard
500 using (var fileStream = shardFile.OpenRead( ))
502 PngReader pngRead = new PngReader(fileStream );
503 pngRead.ReadSkippingAllRows( );
506 PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
508 chunkTopMetadata.Add(metadataFromPng.ChunkMetadata);
518 Logger.VerboseDebug("Could not open world map directory");
526 private PngWriter SetupPngImage(Vec2i coord, ColumnMeta metadata)
528 ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
530 string filename = $"{coord.X}_{coord.Y}.png";
531 filename = Path.Combine(path, filename);
533 PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
534 PngMetadata meta = pngWriter.GetMetadata( );
536 meta.SetText("Chunk_X", coord.X.ToString("D"));
537 meta.SetText("Chunk_Y", coord.Y.ToString("D"));
538 //Setup specialized meta-data PNG chunks here...
539 PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo);
540 pngChunkMeta.ChunkMetadata = metadata;
541 pngWriter.GetChunksList( ).Queue(pngChunkMeta);
547 /// Does the heavy lifting of Scanning columns of chunks - creates Heightmap and Processes POIs, Entities, and stats...
549 /// <param name="key">Chunk Coordinate</param>
550 /// <param name="mapChunk">Map chunk.</param>
551 /// <param name="chunkMeta">Chunk metadata</param>
552 private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ColumnMeta chunkMeta)
555 int targetChunkY = mapChunk.YMax / chunkSize;//Surface ...
556 for (; targetChunkY > 0; targetChunkY--) {
557 WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk;
559 if (chunkData == null || chunkData.BlockEntities == null) {
561 Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X,targetChunkY,key.Y);
566 /*************** Chunk Entities Scanning *********************/
567 if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0) {
569 Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length);
572 foreach (var blockEnt in chunkData.BlockEntities) {
574 if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId))
576 var designator = BlockID_Designators[blockEnt.Block.BlockId];
577 designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy( ), blockEnt.Block);
582 /********************* Chunk/Column BLOCKs scanning ****************/
583 //Heightmap, Stats, block tally
586 int X_index, Y_index, Z_index;
587 X_index = Y_index = Z_index = 0;
592 /* Encode packed indicie
593 (y * chunksize + z) * chunksize + x
595 var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index);
596 int aBlockId = chunkData.Blocks[indicie];
598 if (aBlockId == 0) {//Air
599 chunkMeta.AirBlocks++;
603 if (RockIdCodes.ContainsKey(aBlockId)) {
604 if (chunkMeta.RockRatio.ContainsKey(aBlockId)) { chunkMeta.RockRatio[aBlockId]++; } else { chunkMeta.RockRatio.Add(aBlockId, 1); }
607 chunkMeta.NonAirBlocks++;
610 if (chunkMeta.HeightMap[X_index, Z_index] == 0)
611 { chunkMeta.HeightMap[X_index, Z_index] = ( ushort )(Y_index + (targetChunkY * chunkSize)); }
614 while (X_index++ < (chunkSize - 1));
617 while (Z_index++ < (chunkSize - 1));
620 while (Y_index++ < (chunkSize - 1));
625 private void UpdateEntityMetadata( )
627 Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count);
628 //Mabey scan only for 'new' entities by tracking ID in set?
629 foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToList()) {
632 //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<");
635 var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code));
636 if (dMatch.Value != null) {
637 dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy( ), loadedEntity.Value);