Skip to content

Commit

Permalink
FastLoader : Improved DDS loading performance by avoiding an extra co…
Browse files Browse the repository at this point in the history
…py of the DDS data
  • Loading branch information
gotmachine committed Apr 4, 2024
1 parent e7cd641 commit 779fbbe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
14 changes: 13 additions & 1 deletion KSPCommunityFixes/Performance/FastLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 779fbbe

Please sign in to comment.