Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions KSPCommunityFixes/Performance/MinorPerfTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ protected override void ApplyPatches()
AddPatch(PatchType.Override, typeof(Part), nameof(Part.isKerbalEVA));

AddPatch(PatchType.Override, typeof(VolumeNormalizer), nameof(VolumeNormalizer.Update));

AddPatch(PatchType.Override, typeof(MonoUtilities), nameof(MonoUtilities.RefreshContextWindows));
AddPatch(PatchType.Override, typeof(MonoUtilities), nameof(MonoUtilities.RefreshPartContextWindow));
}

// When FlightGlobals._fetch is null/destroyed, the stock "fetch" getter fallback to a FindObjectOfType()
Expand Down Expand Up @@ -89,5 +92,21 @@ private static void VolumeNormalizer_Update_Override(VolumeNormalizer vn)

vn.volume = newVolume;
}

// MonoUtilities.RefreshContextWindows calls Object.FindObjectsOfType.
// This is quite slow. The method is not used in stock but several mods
// do use it and it would otherwise take up a notable chunk of scene
// switch times.
private static void MonoUtilities_RefreshContextWindows_Override(Part part)
{
if (part.IsNotNullRef() && part.PartActionWindow.IsNotNullOrDestroyed())
part.PartActionWindow.displayDirty = true;
}

private static void MonoUtilities_RefreshPartContextWindow_Override(Part part)
{
if (part.IsNotNullRef() && part.PartActionWindow.IsNotNullOrDestroyed())
part.PartActionWindow.displayDirty = true;
}
}
}