Skip to content

Commit

Permalink
GarbageTruck: optimize the getter method for BaseProcess.data (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosirnik authored Aug 16, 2021
1 parent a9545e5 commit 4b43a25
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/KK_Fix_GarbageTruck/GarbageTruck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using ILSetUtility.TimeUtility;
using Manager;
using UnityEngine;
using Illusion.Component.Correct;
using Illusion.Component.Correct.Process;

namespace IllusionFixes
{
Expand Down Expand Up @@ -314,6 +316,21 @@ public static bool CalculateBlendShape(FBSBase __instance, float ___correctOpenM
goto retry;
}
}

/// <summary>
/// Allocation-free reimplementation (this can be called ~60 times per frame).
/// </summary>
[HarmonyPrefix]
[HarmonyPatch(typeof(BaseProcess), nameof(BaseProcess.data), MethodType.Getter)]
private static bool GetDataNoAlloc(BaseProcess __instance, ref BaseData ____data, ref BaseData __result)
{
if (____data == null)
{
____data = __instance.GetComponent<BaseData>();
}
__result = ____data;
return false;
}
}
}
}

0 comments on commit 4b43a25

Please sign in to comment.