From 779fbbe6450fb3fb47e35adea2361d5834a254c8 Mon Sep 17 00:00:00 2001 From: gotmachine <24925209+gotmachine@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:25:07 +0200 Subject: [PATCH] FastLoader : Improved DDS loading performance by avoiding an extra copy of the DDS data --- .../KSPCommunityFixes/KSPCommunityFixes.version | 2 +- KSPCommunityFixes/Performance/FastLoader.cs | 14 +++++++++++++- KSPCommunityFixes/Properties/AssemblyInfo.cs | 4 ++-- README.md | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/GameData/KSPCommunityFixes/KSPCommunityFixes.version b/GameData/KSPCommunityFixes/KSPCommunityFixes.version index f956461..f4d51be 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": 34, "PATCH": 1, "BUILD": 0}, + "VERSION": {"MAJOR": 1, "MINOR": 35, "PATCH": 0, "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/Performance/FastLoader.cs b/KSPCommunityFixes/Performance/FastLoader.cs index 0523d47..c229336 100644 --- a/KSPCommunityFixes/Performance/FastLoader.cs +++ b/KSPCommunityFixes/Performance/FastLoader.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Reflection; using System.Reflection.Emit; +using System.Runtime.InteropServices; using System.Threading; using TMPro; using Unity.Collections; @@ -1312,7 +1313,18 @@ private TextureInfo LoadDDS() } else { - texture2D.LoadRawTextureData(binaryReader.ReadBytes((int)(binaryReader.BaseStream.Length - binaryReader.BaseStream.Position))); + int position = (int)binaryReader.BaseStream.Position; + GCHandle pinnedHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); + try + { + IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, position); + texture2D.LoadRawTextureData(ptr, dataLength - position); + } + finally + { + pinnedHandle.Free(); + } + texture2D.Apply(updateMipmaps: false, makeNoLongerReadable: true); } } diff --git a/KSPCommunityFixes/Properties/AssemblyInfo.cs b/KSPCommunityFixes/Properties/AssemblyInfo.cs index fb18da3..583c9b0 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.34.1.0")] +[assembly: AssemblyFileVersion("1.35.0.0")] -[assembly: KSPAssembly("KSPCommunityFixes", 1, 34, 1)] +[assembly: KSPAssembly("KSPCommunityFixes", 1, 35, 0)] [assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)] diff --git a/README.md b/README.md index 595aa4a..0a77aee 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,9 @@ If doing so in the `Debug` configuration and if your KSP install is modified to ### Changelog +##### 1.35.0 +- **FastLoader** : Improved DDS loading performance by avoiding an extra copy of the DDS data + ##### 1.34.1 - Disable BetterEditorUndoRedo when TweakScale/L is installed due to introducing a bug with part attachments in the editor.