From c6b68e737a048827d5205db3fd13b0c7bc116661 Mon Sep 17 00:00:00 2001 From: ProTriforcer <25221392+ProTriforcer@users.noreply.github.com> Date: Thu, 30 May 2024 07:09:18 +0500 Subject: [PATCH] Generic def performance fix --- .../Loadouts/Dialog_ManageLoadouts.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/Loadouts/Dialog_ManageLoadouts.cs b/Source/CombatExtended/CombatExtended/Loadouts/Dialog_ManageLoadouts.cs index c290298112..d32dbc4498 100644 --- a/Source/CombatExtended/CombatExtended/Loadouts/Dialog_ManageLoadouts.cs +++ b/Source/CombatExtended/CombatExtended/Loadouts/Dialog_ManageLoadouts.cs @@ -1046,15 +1046,16 @@ private void initGenericVisibilityDictionary() { int tick = GenTicks.TicksAbs; int position = 1; - foreach (LoadoutGenericDef def in _sourceGeneric) + List mapDefs = Find.CurrentMap.listerThings.AllThings.Where((Thing thing) => !thing.PositionHeld.Fogged(thing.MapHeld) && !thing.GetInnerIfMinified().def.Minifiable).Select((Thing thing) => thing.def).Distinct().ToList(); + foreach (LoadoutGenericDef loadoutDef in _sourceGeneric) { - if (!genericVisibility.ContainsKey(def)) + if (!genericVisibility.ContainsKey(loadoutDef)) { - genericVisibility.Add(def, new VisibilityCache()); + genericVisibility.Add(loadoutDef, new VisibilityCache()); } - genericVisibility[def].ticksToRecheck = tick; - genericVisibility[def].check = Find.CurrentMap.listerThings.AllThings.Find(x => def.lambda(x.GetInnerIfMinified().def) && !x.def.Minifiable) == null; - genericVisibility[def].position = position; + genericVisibility[loadoutDef].ticksToRecheck = tick; + genericVisibility[loadoutDef].check = mapDefs.Find((ThingDef def) => loadoutDef.lambda(def)) == null; + genericVisibility[loadoutDef].position = position; position++; tick += advanceTicks; }