Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSP loader performance optimization #109

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
72c2bc4
Experimental implementation
gotmachine Aug 24, 2022
f5d86c7
Fix nested Persistent IConfigNode objects that each call LoadObjectFr…
NathanKell Aug 24, 2022
0cd1cf3
Updated readme
gotmachine Aug 24, 2022
ec4c0bd
Improve ConfigNode load/save perf (#88)
NathanKell Aug 26, 2022
1596a17
Bump version
NathanKell Aug 26, 2022
565302e
Mod upgrade pipeline (#91)
NathanKell Sep 6, 2022
bf772ff
More ConfigNode perf (#90)
NathanKell Sep 8, 2022
a9c84be
Default PersistentIConfigNode to enabled, update comment and readme.
NathanKell Sep 8, 2022
f695087
Fix missing attribute for MultipleModulePartAPI, refactor WriteValue …
NathanKell Sep 9, 2022
ac8dbda
Fix stock SaveUpgradePipeline bug where it blows up if a script doesn…
NathanKell Sep 10, 2022
a79478e
Add RestoreMaxPhysicsDT (#95)
JonnyOThan Sep 14, 2022
8ea741c
Set minVersion for RestoreMaxPhysicsDT to 1.8.0
NathanKell Sep 17, 2022
3b641b7
Bump version, add readme info for RestoreMaxPhysicsDT
NathanKell Sep 17, 2022
033825f
Create zh-cn.cfg (#99)
tinygrox Sep 23, 2022
9027095
Fix typo in Strategy.SendStateMessage. Readme updates.
NathanKell Sep 24, 2022
cb2e196
Fix a bug in ConfigNodePerf where it was not early-outing properly on…
NathanKell Sep 25, 2022
c239cdf
typo fix
NathanKell Sep 25, 2022
95ca4a7
Fix KSP issue #69 : 0-byte icon files can hang loading
gotmachine Nov 4, 2022
9f19ce3
ConfigNodePerf : Fix AmbigousMatchException when patching Game.Updated()
gotmachine Nov 4, 2022
35d3900
StockAlarmCustomFormatterDate : issue was fixed in KSP 1.12.4 so the …
gotmachine Nov 5, 2022
eaf850c
New performance patch : [ContractProgressEnumCache](https://github.co…
gotmachine Nov 5, 2022
e3be82e
1.24 version bump
gotmachine Nov 5, 2022
10bbf5e
Readme tweaks
gotmachine Nov 5, 2022
17e6435
Fix for issue #72 : prevent RoboticsDrift to apply on KSP versions pr…
gotmachine Nov 15, 2022
3e2f888
Implemented GameDatabase loader frame unlocking
gotmachine Dec 3, 2022
f25724d
Working implementation. Still todo :
gotmachine Dec 7, 2022
c787bdf
All done
gotmachine Dec 9, 2022
92ab653
FastLoader : code cleanup
gotmachine Dec 30, 2022
716d0e8
Reimplementation of the PNG texture cache in FastLoader
gotmachine Dec 31, 2022
e197945
New KSP bugfix (issue #107) : ChutePhantomSymmetry
gotmachine Dec 31, 2022
0010c74
Experimental implementation
gotmachine Aug 24, 2022
a62f4cb
readme update
gotmachine Dec 31, 2022
5e93a5b
FastLoader / texture cache : updated localization strings to match ne…
gotmachine Jan 1, 2023
4f4221e
Fix some bugs
gotmachine Jan 1, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// If you want to disable some KSPCF patches or customize your configuration,
// copy this file in your GameData folder and replace "PatchName" with the
// patch(s) you want to disable (add new lines to disable multiple patches).
// copy this file in your "GameData" folder and remove the ".extra" extension.
// Then edit the file and replace "PatchName" with the patch(s) you want to
// disable (add new lines to disable multiple patches).
// To see the full list of patch names, look at the Settings.cfg file or in
// the readme.

Expand Down
6 changes: 3 additions & 3 deletions GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"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": 21, "PATCH": 0, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 3},
"VERSION": {"MAJOR": 1, "MINOR": 24, "PATCH": 0, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 4},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 3}
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 4}
}
18 changes: 9 additions & 9 deletions GameData/KSPCommunityFixes/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Localization
en-us
{

// TextureLoaderOptimizations

#KSPCF_TextureLoaderOptimizations_SettingsTitle = Texture caching optimization
#KSPCF_TextureLoaderOptimizations_SettingsTooltip = Cache PNG textures on disk instead of converting them on every KSP launch.\nSpeedup loading time but increase disk space usage.\n<i>Changes will take effect after relaunching KSP</i>
#KSPCF_TextureLoaderOptimizations_PopupL1 = KSPCommunityFixes can cache converted PNG textures on disk to speed up loading time.
#KSPCF_TextureLoaderOptimizations_F_PopupL2 = In your current install, this should reduce future loading time by about <b><color=#FF8000><<1>> seconds</color></b>.
#KSPCF_TextureLoaderOptimizations_F_PopupL3 = However, this will use about <b><color=#FF8000><<1>> MB</color></b> of additional disk space, and potentially much more if you install additional mods.
#KSPCF_TextureLoaderOptimizations_PopupL4 = You can change this setting later in the in-game settings menu
#KSPCF_TextureLoaderOptimizations_PopupL5 = Do you want to enable this optimization ?
// KSPCFFastLoader

#KSPCF__SettingsTitle = Texture caching optimization
#KSPCF_KSPCFFastLoader_SettingsTooltip = Cache PNG textures on disk instead of converting them on every KSP launch.\nSpeedup loading time but increase disk space usage.\n<i>Changes will take effect after relaunching KSP</i>
#KSPCF_KSPCFFastLoader_PopupL1 = KSPCommunityFixes can cache converted PNG textures on disk to speed up loading time.
#KSPCF_KSPCFFastLoader_F_PopupL2 = In your current install, this should reduce future loading time by about <b><color=#FF8000><<1>> seconds</color></b>.
#KSPCF_KSPCFFastLoader_F_PopupL3 = However, this will use about <b><color=#FF8000><<1>> MB</color></b> of additional disk space, and potentially much more if you install additional mods.
#KSPCF_KSPCFFastLoader_PopupL4 = You can change this setting later in the in-game settings menu
#KSPCF_KSPCFFastLoader_PopupL5 = Do you want to enable this optimization ?

// KSPCommunityFixes

Expand Down
16 changes: 8 additions & 8 deletions GameData/KSPCommunityFixes/Localization/fr-fr.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ Localization
fr-fr
{

// TextureLoaderOptimizations
// KSPCFFastLoader


// Texture caching optimization
#KSPCF_TextureLoaderOptimizations_SettingsTitle = Optimisation des textures
#KSPCF_KSPCFFastLoader_SettingsTitle = Optimisation des textures

// Cache PNG textures on disk instead of converting them on every KSP launch.\nSpeedup loading time but increase disk space usage.\n<i>Changes will take effect after relaunching KSP</i>
#KSPCF_TextureLoaderOptimizations_SettingsTooltip = Enregistre les textures PNG sur le disque au lieu de les convertir a chaque lancement de KSP.\nAccélère le temps de chargement mais utilise plus d'espace disque.\n<i>Prendra effet au prochain lancement de KSP</i>
#KSPCF_KSPCFFastLoader_SettingsTooltip = Enregistre les textures PNG sur le disque au lieu de les convertir a chaque lancement de KSP.\nAccélère le temps de chargement mais utilise plus d'espace disque.\n<i>Prendra effet au prochain lancement de KSP</i>

// KSPCommunityFixes can cache converted PNG textures on disk to speed up loading time.
#KSPCF_TextureLoaderOptimizations_PopupL1 = KSPCommunityFixes peut mettre en cache les textures PNG converties sur le disque pour accélèrer le temps de chargement.
#KSPCF_KSPCFFastLoader_PopupL1 = KSPCommunityFixes peut mettre en cache les textures PNG converties sur le disque pour accélèrer le temps de chargement.

// In your current install, this should reduce future loading time by about <b><color=#FF8000><<1>> seconds</color></b>.
#KSPCF_TextureLoaderOptimizations_F_PopupL2 = Pour votre installation actuelle, cela devrait reduire le temps de chargement d'environ <b><color=#FF8000><<1>> secondes</color></b>.
#KSPCF_KSPCFFastLoader_F_PopupL2 = Pour votre installation actuelle, cela devrait reduire le temps de chargement d'environ <b><color=#FF8000><<1>> secondes</color></b>.

// However, this will use about <b><color=#FF8000><<1>> MB</color></b> of additional disk space, and potentially much more if you install additional mods.
#KSPCF_TextureLoaderOptimizations_F_PopupL3 = Toutefois, cela utilisera environ <b><color=#FF8000><<1>> Mo</color></b> d'espace disque supplémentaire, et possiblement beaucoup plus si vous installez d'autres mods.
#KSPCF_KSPCFFastLoader_F_PopupL3 = Toutefois, cela utilisera environ <b><color=#FF8000><<1>> Mo</color></b> d'espace disque supplémentaire, et possiblement beaucoup plus si vous installez d'autres mods.

// You can change this setting later in the in-game settings menu
#KSPCF_TextureLoaderOptimizations_PopupL4 = Vous pouvez changer cette option plus tard dans les paramètres (ESC en jeu)
#KSPCF_KSPCFFastLoader_PopupL4 = Vous pouvez changer cette option plus tard dans les paramètres (ESC en jeu)

// Do you want to enable this optimization ?
#KSPCF_TextureLoaderOptimizations_PopupL5 = Voulez vous activer cette optimisation ?
#KSPCF_KSPCFFastLoader_PopupL5 = Voulez vous activer cette optimisation ?

// KSPCommunityFixes

Expand Down
16 changes: 8 additions & 8 deletions GameData/KSPCommunityFixes/Localization/ru.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ Localization
ru
{

// TextureLoaderOptimizations
// KSPCFFastLoader


// Texture caching optimization
#KSPCF_TextureLoaderOptimizations_SettingsTitle = Оптимизация кэширования текстур
#KSPCF_KSPCFFastLoader_SettingsTitle = Оптимизация кэширования текстур

// Cache PNG textures on disk instead of converting them on every KSP launch.\nSpeedup loading time but increase disk space usage.\n<i>Changes will take effect after relaunching KSP</i>
#KSPCF_TextureLoaderOptimizations_SettingsTooltip = Кэшируйте текстуры PNG на диске вместо их преобразования при каждом запуске KSP.\nУскоряет время загрузки, но увеличивает использование дискового пространства.\n<i>Изменения вступят в силу после повторного запуска KSP</i>
#KSPCF_KSPCFFastLoader_SettingsTooltip = Кэшируйте текстуры PNG на диске вместо их преобразования при каждом запуске KSP.\nУскоряет время загрузки, но увеличивает использование дискового пространства.\n<i>Изменения вступят в силу после повторного запуска KSP</i>

// KSPCommunityFixes can cache converted PNG textures on disk to speed up loading time.
#KSPCF_TextureLoaderOptimizations_PopupL1 = Исправления сообщества KSP могут кэшировать преобразованные текстуры PNG на диске, чтобы ускорить время загрузки.
#KSPCF_KSPCFFastLoader_PopupL1 = Исправления сообщества KSP могут кэшировать преобразованные текстуры PNG на диске, чтобы ускорить время загрузки.

// In your current install, this should reduce future loading time by about <b><color=#FF8000><<1>> seconds</color></b>.
#KSPCF_TextureLoaderOptimizations_F_PopupL2 = В вашей текущей установке это должно сократить время загрузки в будущем примерно на <b><color=#FF8000><<1>> секунды</color></b>.
#KSPCF_KSPCFFastLoader_F_PopupL2 = В вашей текущей установке это должно сократить время загрузки в будущем примерно на <b><color=#FF8000><<1>> секунды</color></b>.

// However, this will use about <b><color=#FF8000><<1>> MB</color></b> of additional disk space, and potentially much more if you install additional mods.
#KSPCF_TextureLoaderOptimizations_F_PopupL3 = Однако для этого потребуется около <b><color=#FF8000><<1>> МБ</color></b> дополнительного дискового пространства, и, возможно, гораздо больше, если вы установите дополнительные моды.
#KSPCF_KSPCFFastLoader_F_PopupL3 = Однако для этого потребуется около <b><color=#FF8000><<1>> МБ</color></b> дополнительного дискового пространства, и, возможно, гораздо больше, если вы установите дополнительные моды.

// You can change this setting later in the in-game settings menu
#KSPCF_TextureLoaderOptimizations_PopupL4 = Вы можете изменить этот параметр позже в меню настроек в игре
#KSPCF_KSPCFFastLoader_PopupL4 = Вы можете изменить этот параметр позже в меню настроек в игре

// Do you want to enable this optimization ?
#KSPCF_TextureLoaderOptimizations_PopupL5 = Вы хотите включить эту оптимизацию?
#KSPCF_KSPCFFastLoader_PopupL5 = Вы хотите включить эту оптимизацию?

// KSPCommunityFixes

Expand Down
84 changes: 84 additions & 0 deletions GameData/KSPCommunityFixes/Localization/zh-cn.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Localization
{
zh-cn
{

// KSPCFFastLoader


// Texture caching optimization
#KSPCF_KSPCFFastLoader_SettingsTitle = 纹理缓存优化

// Cache PNG textures on disk instead of converting them on every KSP launch.\nSpeedup loading time but increase disk space usage.\n<i>Changes will take effect after relaunching KSP</i>
#KSPCF_KSPCFFastLoader_SettingsTooltip = 在硬盘上缓存转换后的 PNG 纹理文件,替代了游戏每次启动时进行的纹理转换过程.\n通过增加硬盘占用空间而减少加载时间(空间换时间).\n<i>重启KSP后生效</i>

// KSPCommunityFixes can cache converted PNG textures on disk to speed up loading time.
#KSPCF_KSPCFFastLoader_PopupL1 = KSPCommunityFixes 可以将已转换的 PNG 纹理文件在缓存硬盘上,加快游戏加载速度。

// In your current install, this should reduce future loading time by about <b><color=#FF8000><<1>> seconds</color></b>.
#KSPCF_KSPCFFastLoader_F_PopupL2 = 在你当前安装的游戏环境下, 此举可节省大约<b><color=#FF8000><<1>> 秒</color></b>的加载时间.

// However, this will use about <b><color=#FF8000><<1>> MB</color></b> of additional disk space, and potentially much more if you install additional mods.
#KSPCF_KSPCFFastLoader_F_PopupL3 = 然而, 此举同时将会占用 <b><color=#FF8000><<1>> MB</color></b> 的额外磁盘空间, 如果安装了其他mod,可能需要占用更多空间。

// You can change this setting later in the in-game settings menu
#KSPCF_KSPCFFastLoader_PopupL4 = 你可以在稍后进入游戏设置菜单中更改此项设置

// Do you want to enable this optimization ?
#KSPCF_KSPCFFastLoader_PopupL5 = 是否要应用此优化选项 ?

// KSPCommunityFixes


// KSP Community Fixes
#KSPCF_KSPCommunityFixes_KSPCF_Title = KSP Community Fixes

// AltimeterHorizontalPosition


// Altimeter pos (Left<->Right)
#KSPCF_AltimeterHorizontalPosition_SettingsTitle = 高度计位置 (左<->右)

// Set the horizontal position of the flight scene altimeter widget
#KSPCF_AltimeterHorizontalPosition_SettingsTooltip = 在飞行界面中设置高度计的水平位置

// NoIVA


// Keep all
#KSPCF_NoIVA_KeepAll = 全部启用

// Disable all
#KSPCF_NoIVA_DisableAll = 全部禁用

// Use placeholder
#KSPCF_NoIVA_UsePlaceholder = 半启用 // Use placeholder 这咋翻,只恨自己不是文学出身

// IVA (interior view)
#KSPCF_NoIVA_SettingsTitle = IVA (舱内视角)

// Disable IVA functionality: reduce RAM/VRAM usage and increase FPS.\n\t-Disable all : disable IVA\n\t-Use placeholder : disable IVA but keep crew portraits\n<i>Changes will take effect after relaunching KSP</i>
#KSPCF_NoIVA_SettingsTooltip = 禁用 IVA 功能: 减少 RAM/VRAM 使用并增加 FPS.\n\t-全部禁用 : 不显示IVA\n\t-半启用 : 禁用IVA 但保留右下角乘员头像\n<i>重启KSP后生效</i>

// DisableManeuverTool


// The stock maneuver tool can cause severe lag and stutter issues,\nespecially with Kopernicus modified systems.\nThis option allow to disable it entirely
#KSPCF_DisableManeuverTool_SettingsTooltip = 原版自带的机动工具可能会导致严重的掉帧和卡顿问题,\n特别是在安装了 Kopernicus 的情况下.\n此选项可将其完全禁用

// ReflectionTypeLoadExceptionHandler


// KSPCommunityFixes warning
#KSPCF_ReflectionTypeLoadExceptionHandler_KSPCFWarning = KSPCommunityFixes 警告

// The following plugin(s) failed to load :
#KSPCF_ReflectionTypeLoadExceptionHandler_PluginsLoadFailed = 下列插件(mod)加载失败 :

// <<1>> in <<2>>
#KSPCF_ReflectionTypeLoadExceptionHandler_F_PluginLoadFailed_name_in_location = <<1>> in <<2>>

// Load failed due to missing dependencies
#KSPCF_ReflectionTypeLoadExceptionHandler_PluginLoadFailed_missingDep = 缺少前置插件,加载失败
}
}
24 changes: 23 additions & 1 deletion GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ KSP_COMMUNITY_FIXES
// Avoids big spikes on the poles and incorrect biomes where the oles have disparate biomes.
MapSOCorrectWrapping = true

// Fix spread angle still being applied after decoupling symmetry-placed parachutes.
ChutePhantomSymmetry = true

// ##########################
// Obsolete bugfixes
// ##########################
Expand Down Expand Up @@ -287,6 +290,18 @@ KSP_COMMUNITY_FIXES
// and every time you delete a vessel in the Tracking Station
FewerSaves = false

// This tweak will skip writing indents when saving craft files and
// savegames (sfs files). This will speed up writing (and slightly
// speed up reading) at the cost of human readability.
SkipIndentsOnSavesAndCraftFiles = false

// After using physics warp, Unity's max physics dt will never be returned to the value specified in
// game settings which can degrade performance in some cases
RestoreMaxPhysicsDT = true

// Prevent performance drops when there are in-progress comet sample or rover construction contracts
ContractProgressEnumCache = true

// ##########################
// Modding
// ##########################
Expand All @@ -308,11 +323,18 @@ KSP_COMMUNITY_FIXES
// the `CreateObjectFromConfig()`, `LoadObjectFromConfig()` and `CreateConfigFromObject()` methods.
// Disabled by default, you can enable it with a MM patch.
// Also adds support for [Persistent] tags on System.Guid
PersistentIConfigNode = false
// Features a full rewrite of ReadObject/WriteObject for performance and lower GC impact
// and to fix some exisiting stock bugs.
PersistentIConfigNode = true

// Fix Admin Building not using HeadImage if that is defined for a Department
DepartmentHeadImage = true

// Stores mod versions in sfs and craft files, and uses those versions for the SaveUpgradePipeline,
// so mods can do versioning based on their own version numbers and not have to always run their
// upgrade scripts.
ModUpgradePipeline = false

// ##########################
// Localization tools
// ##########################
Expand Down
70 changes: 70 additions & 0 deletions KSPCommunityFixes/BugFixes/ChutePhantomSymmetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using static PartModule;

namespace KSPCommunityFixes.BugFixes
{
internal class ChutePhantomSymmetry : BasePatch
{
protected override Version VersionMin => new Version(1, 10, 0);

protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(ModuleParachute), nameof(ModuleParachute.OnStart)),
this));

patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Method(typeof(ModuleParachute), nameof(ModuleParachute.OnDestroy)),
this));
}

private static void ModuleParachute_OnStart_Postfix(ModuleParachute __instance, StartState state)
{
if (state == StartState.Editor)
return;

eventHandlers.Add(__instance, new EventHandler(__instance));
}

private static void ModuleParachute_OnDestroy_Postfix(ModuleParachute __instance)
{
if (eventHandlers.Remove(__instance, out EventHandler eventHandler))
eventHandler.OnDestroy();
}

private static Dictionary<ModuleParachute, EventHandler> eventHandlers = new Dictionary<ModuleParachute, EventHandler>(16);

private class EventHandler
{
private ModuleParachute instance;

public EventHandler(ModuleParachute instance)
{
this.instance = instance;
GameEvents.onPartDeCoupleNewVesselComplete.Add(OnEvent);
}

public void OnDestroy()
{
GameEvents.onPartDeCoupleNewVesselComplete.Remove(OnEvent);
}

private void OnEvent(Vessel oldVessel, Vessel newVessel)
{
if (newVessel.NotDestroyedRefNotEquals(instance.vessel))
return;

int count = instance.part.symmetryCounterparts?.Count ?? 0;

if (count > 0)
count++;

instance.symmetryCount = count;
}
}
}
}
Loading