Skip to content

Commit

Permalink
Reduce/fix lag when reloading textures
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Nov 28, 2021
1 parent 300a2d7 commit 4bf2072
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Core_OverlayMods/Skin/KoiSkinOverlayController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ExtensibleSaveFormat;
using KKAPI;
Expand Down Expand Up @@ -279,6 +280,11 @@ public static void UpdateTexture(ChaControl cc, TexType type)
{
if (cc == null) return;
if (cc.customTexCtrlBody == null || cc.customTexCtrlFace == null) return;

// Prevent lag when reloading textures at the cost of extra memory usage for the no longer used textures (until something else collects garbage)
var prevGcClear = Util.EnableCharaLoadGC;
Util.EnableCharaLoadGC = false;

#if KK || KKS || EC
switch (type)
{
Expand Down Expand Up @@ -342,6 +348,8 @@ public static void UpdateTexture(ChaControl cc, TexType type)
break;
}
#endif

Util.EnableCharaLoadGC = prevGcClear;
}

public static void ApplyOverlay(RenderTexture mainTex, Texture2D blitTex)
Expand Down
22 changes: 22 additions & 0 deletions Core_OverlayMods/Skin/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using KKAPI.Utilities;
using Manager;
using UnityEngine;

namespace KoiSkinOverlayX
Expand Down Expand Up @@ -103,5 +104,26 @@ public static RenderTexture CreateRT(int origWidth, int origHeight)
RenderTexture.active = rta;
return rt;
}

public static bool EnableCharaLoadGC
{
#if KKS
get => Character.enableCharaLoadGCClear;
set => Character.enableCharaLoadGCClear = value;
#else
get
{
if (Character.IsInstance())
return Character.Instance.enableCharaLoadGCClear;
else
return true;
}
set
{
if (Character.IsInstance())
Character.Instance.enableCharaLoadGCClear = value;
}
#endif
}
}
}

0 comments on commit 4bf2072

Please sign in to comment.