From 1c8849af29a916822885541c010ffc4b7bb90d5a Mon Sep 17 00:00:00 2001 From: melchior Date: Sun, 1 May 2022 14:22:25 -0400 Subject: [PATCH] 2nd Entity processing fix attempt --- Automap/Subsystems/AutomapSystem.cs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Automap/Subsystems/AutomapSystem.cs b/Automap/Subsystems/AutomapSystem.cs index b7a554c..32cda38 100644 --- a/Automap/Subsystems/AutomapSystem.cs +++ b/Automap/Subsystems/AutomapSystem.cs @@ -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) -- 2.11.0