From 934ff507d31dc57ca62e8abaa3f91af4eafc3e0d Mon Sep 17 00:00:00 2001 From: gotmachine <24925209+gotmachine@users.noreply.github.com> Date: Thu, 7 Dec 2023 19:14:17 +0100 Subject: [PATCH] 1.32.1 hotfix : fixed issue where the IMGUIOptimization patch was breaking some mods UIs due to not resetting some internal state correctly --- .../KSPCommunityFixes.version | 2 +- KSPCommunityFixes/KSPCommunityFixes.csproj | 11 +---- .../Performance/IMGUIOptimization.cs | 44 +++++++++++++++++-- KSPCommunityFixes/Properties/AssemblyInfo.cs | 4 +- README.md | 3 ++ 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/GameData/KSPCommunityFixes/KSPCommunityFixes.version b/GameData/KSPCommunityFixes/KSPCommunityFixes.version index 669d88a..a24dfae 100644 --- a/GameData/KSPCommunityFixes/KSPCommunityFixes.version +++ b/GameData/KSPCommunityFixes/KSPCommunityFixes.version @@ -2,7 +2,7 @@ "NAME": "KSPCommunityFixes", "URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version", "DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases", - "VERSION": {"MAJOR": 1, "MINOR": 32, "PATCH": 0, "BUILD": 0}, + "VERSION": {"MAJOR": 1, "MINOR": 32, "PATCH": 1, "BUILD": 0}, "KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}, "KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0}, "KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5} diff --git a/KSPCommunityFixes/KSPCommunityFixes.csproj b/KSPCommunityFixes/KSPCommunityFixes.csproj index 6c42e8b..723b75c 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.csproj +++ b/KSPCommunityFixes/KSPCommunityFixes.csproj @@ -92,16 +92,7 @@ - - - - - - - - - - + diff --git a/KSPCommunityFixes/Performance/IMGUIOptimization.cs b/KSPCommunityFixes/Performance/IMGUIOptimization.cs index 06746b9..0d74d75 100644 --- a/KSPCommunityFixes/Performance/IMGUIOptimization.cs +++ b/KSPCommunityFixes/Performance/IMGUIOptimization.cs @@ -1,4 +1,4 @@ -// Copypasted from https://forum.unity.com/threads/garbage-collector-spikes-because-of-gui.60217/page-2#post-6317280 +// Based upon https://forum.unity.com/threads/garbage-collector-spikes-because-of-gui.60217/page-2#post-6317280 // Basically, every OnGUI() method implies a call to GUILayout.Repaint(), itself calling GUILayoutUtility.Begin(), // which does a bunch of allocations (even if the OnGUI() method does nothing). This replacement method reuse the // existing objects instead of instantiating new ones, which both reduce GC pressure (about 0.36 KB/frame per OnGUI() @@ -33,15 +33,18 @@ static bool GUILayoutUtility_Begin_Prefix(int instanceID) { if (layoutCache.topLevel == null) layoutCache.topLevel = new GUILayoutGroup(); + else + ResetGUILayoutGroup(layoutCache.topLevel); + if (layoutCache.windows == null) layoutCache.windows = new GUILayoutGroup(); - - layoutCache.topLevel.entries.Clear(); - layoutCache.windows.entries.Clear(); + else + ResetGUILayoutGroup(layoutCache.windows); GUILayoutUtility.current.topLevel = layoutCache.topLevel; GUILayoutUtility.current.layoutGroups.Clear(); GUILayoutUtility.current.layoutGroups.Push(GUILayoutUtility.current.topLevel); + GUILayoutUtility.current.windows = layoutCache.windows; return false; } GUILayoutUtility.current.topLevel = layoutCache.topLevel; @@ -49,5 +52,38 @@ static bool GUILayoutUtility_Begin_Prefix(int instanceID) GUILayoutUtility.current.windows = layoutCache.windows; return false; } + + static void ResetGUILayoutGroup(GUILayoutGroup layoutGroup) + { + layoutGroup.entries.Clear(); + layoutGroup.isVertical = true; + layoutGroup.resetCoords = false; + layoutGroup.spacing = 0f; + layoutGroup.sameSize = true; + layoutGroup.isWindow = false; + layoutGroup.windowID = -1; + layoutGroup.m_Cursor = 0; + layoutGroup.m_StretchableCountX = 100; + layoutGroup.m_StretchableCountY = 100; + layoutGroup.m_UserSpecifiedWidth = false; + layoutGroup.m_UserSpecifiedHeight = false; + layoutGroup.m_ChildMinWidth = 100f; + layoutGroup.m_ChildMaxWidth = 100f; + layoutGroup.m_ChildMinHeight = 100f; + layoutGroup.m_ChildMaxHeight = 100f; + layoutGroup.m_MarginLeft = 0; + layoutGroup.m_MarginRight = 0; + layoutGroup.m_MarginTop = 0; + layoutGroup.m_MarginBottom = 0; + layoutGroup.rect = new Rect(0f, 0f, 0f, 0f); + layoutGroup.consideredForMargin = true; + layoutGroup.m_Style = GUIStyle.none; + layoutGroup.stretchWidth = 1; + layoutGroup.stretchHeight = 0; + layoutGroup.minWidth = 0f; + layoutGroup.maxWidth = 0f; + layoutGroup.minHeight = 0f; + layoutGroup.maxHeight = 0f; + } } } diff --git a/KSPCommunityFixes/Properties/AssemblyInfo.cs b/KSPCommunityFixes/Properties/AssemblyInfo.cs index cbbb25e..0ddd8bc 100644 --- a/KSPCommunityFixes/Properties/AssemblyInfo.cs +++ b/KSPCommunityFixes/Properties/AssemblyInfo.cs @@ -30,7 +30,7 @@ // Revision // [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.32.0.0")] +[assembly: AssemblyFileVersion("1.32.1.0")] -[assembly: KSPAssembly("KSPCommunityFixes", 1, 32, 0)] +[assembly: KSPAssembly("KSPCommunityFixes", 1, 32, 1)] [assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)] diff --git a/README.md b/README.md index dbda172..be3bb08 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,9 @@ If doing so in the `Debug` configuration and if your KSP install is modified to ### Changelog +##### 1.32.1 +- **IMGUIOptimization** : fixed issue where the patch was breaking some mods UIs due to not resetting some internal state correctly. + ##### 1.32.0 - New KSP bugfix : [**TimeWarpOrbitShift**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/170) [KSP 1.8.0 - 1.12.5], fix active vessel orbit moving randomly when engaging timewarp while under heavy CPU load. - New KSP bugfix : [**ModuleAnimateGenericCrewModSpawnIVA**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/169) [KSP 1.8.0 - 1.12.5], fix IVA & crew portrait not spawning/despawning when ModuleAnimateGeneric is used to change the part crew capacity. Notably affect the stock inflatable airlock.