Skip to content

Commit

Permalink
Merge pull request #3160 from ProTriforcer/patch-1
Browse files Browse the repository at this point in the history
Loadout manager window performance fixes
  • Loading branch information
N7Huntsman authored Jun 4, 2024
2 parents 45084f2 + c6b68e7 commit 767a72b
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ public Dialog_ManageLoadouts(Loadout loadout)
_allSuitableDefs = DefDatabase<ThingDef>.AllDefs.Where(td => !td.IsMenuHidden() && IsSuitableThingDef(td)).ToList();
_allDefsGeneric = DefDatabase<LoadoutGenericDef>.AllDefs.OrderBy(g => g.label).ToList();
_selectableItems = new List<SelectableItem>();
List<ThingDef> suitableMapDefs = Find.CurrentMap.listerThings.AllThings.Where((Thing thing) => !thing.PositionHeld.Fogged(thing.MapHeld) && !thing.GetInnerIfMinified().def.Minifiable).Select((Thing thing) => thing.def).Distinct().Intersect(_allSuitableDefs).ToList();
foreach (var td in _allSuitableDefs)
{
_selectableItems.Add(new SelectableItem()
{
thingDef = td,
isGreyedOut = (Find.CurrentMap.listerThings.AllThings.Find(thing => thing.GetInnerIfMinified().def == td && !thing.def.Minifiable) == null)
//!thing.PositionHeld.Fogged(thing.MapHeld) //check Thing is visible on map. CPU expensive!
isGreyedOut = (suitableMapDefs.Find((ThingDef def) => def == td) == null)
});
}
SetSource(SourceSelection.Ranged);
Expand Down Expand Up @@ -1046,15 +1046,16 @@ private void initGenericVisibilityDictionary()
{
int tick = GenTicks.TicksAbs;
int position = 1;
foreach (LoadoutGenericDef def in _sourceGeneric)
List<ThingDef> 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;
}
Expand Down

0 comments on commit 767a72b

Please sign in to comment.