OSDN Git Service

2nd Entity processing fix attempt
authormelchior <melchior@users.osdn.me>
Sun, 1 May 2022 18:22:25 +0000 (14:22 -0400)
committermelchior <melchior@users.osdn.me>
Sun, 1 May 2022 18:22:25 +0000 (14:22 -0400)
Automap/Subsystems/AutomapSystem.cs

index b7a554c..32cda38 100644 (file)
@@ -9,11 +9,12 @@ using System.Text.RegularExpressions;
 using System.Threading;
 
 using Hjg.Pngcs;
-
+using Mono.Collections.Generic;
 using ProtoBuf;
 
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
+using Vintagestory.API.Common.Entities;
 using Vintagestory.API.Config;
 using Vintagestory.API.Datastructures;
 using Vintagestory.API.MathTools;
@@ -728,21 +729,26 @@ namespace Automap
                Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count);
                #endif
 
-               //Handles mutations better than a plain Iterator
-               for (int entIndex = 0; entIndex < ClientAPI.World.LoadedEntities.Count;  entIndex++ )
+               var keyList = new long[ClientAPI.World.LoadedEntities.Keys.Count];
+               ClientAPI.World.LoadedEntities.Keys.CopyTo(keyList, 0);
+
+            //'ElementAt'; worse! instead; walk fixed list...
+               Entity loadedEntity;
+               foreach (var key in keyList)
                        {
-                       var loadedEntity = ClientAPI.World.LoadedEntities.Values.ElementAt(entIndex);
-                                                                    
-                       #if DEBUG
-                       //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos}    <<<<<<<<<<<<");
-                       #endif
+                       if (ClientAPI.World.LoadedEntities.TryGetValue(key, out loadedEntity))
+                               {               
+                               #if DEBUG
+                               //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos}    <<<<<<<<<<<<");
+                               #endif
 
-                       var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Code));
-                       if (dMatch.Value != null) 
-                               {
-                               dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Pos.AsBlockPos.Copy( ), loadedEntity);
-                               }
-                       }                               
+                               var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Code));
+                               if (dMatch.Value != null) 
+                                       {
+                                       dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Pos.AsBlockPos.Copy( ), loadedEntity);
+                                       }
+                               }                               
+                       }
                }
 
                private void AddNote(string notation)