perf: improved garbage created by tweens slightly
They still do generate a lot of garbage but with boxed value pools I made the boxes reusable, it still does generate garbage through the delegate creation, gotta find a solution for them later
This commit is contained in:
@@ -4,6 +4,9 @@ namespace Engine.Systems.Tween;
|
||||
|
||||
public static class TweenColorExtensions
|
||||
{
|
||||
private static readonly BoxedPool<ColorHSV> boxedColorHSVPool = new(2);
|
||||
private static readonly BoxedPool<ColorHSVA> boxedColorHSVAPool = new(2);
|
||||
|
||||
public static ITween TweenColor(this ColorRGB initialColorRGB, ITweenManager tweenManager, float duration, ColorRGB targetColorRGB, System.Action<ColorRGB> setMethod)
|
||||
=> TweenColor((ColorHSV)initialColorRGB, tweenManager, duration, (ColorHSV)targetColorRGB, color => setMethod?.Invoke(color));
|
||||
|
||||
@@ -11,8 +14,34 @@ public static class TweenColorExtensions
|
||||
=> TweenColor((ColorHSVA)initialColorRGBA, tweenManager, duration, (ColorHSVA)targetColorRGBA, color => setMethod?.Invoke(color));
|
||||
|
||||
public static ITween TweenColor(this ColorHSV initialColorHSV, ITweenManager tweenManager, float duration, ColorHSV targetColorHSV, System.Action<ColorHSV> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorHSV.Lerp(targetColorHSV, t)));
|
||||
{
|
||||
Boxed<ColorHSV> boxedInitial = boxedColorHSVPool.Get(initialColorHSV);
|
||||
Boxed<ColorHSV> boxedTarget = boxedColorHSVPool.Get(targetColorHSV);
|
||||
|
||||
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t)));
|
||||
|
||||
tween.OnComplete(() =>
|
||||
{
|
||||
boxedColorHSVPool.Return(boxedInitial);
|
||||
boxedColorHSVPool.Return(boxedTarget);
|
||||
});
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween TweenColor(this ColorHSVA initialColorHSVA, ITweenManager tweenManager, float duration, ColorHSVA targetColorHSVA, System.Action<ColorHSVA> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorHSVA.Lerp(targetColorHSVA, t)));
|
||||
{
|
||||
Boxed<ColorHSVA> boxedInitial = boxedColorHSVAPool.Get(initialColorHSVA);
|
||||
Boxed<ColorHSVA> boxedTarget = boxedColorHSVAPool.Get(targetColorHSVA);
|
||||
|
||||
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t)));
|
||||
|
||||
tween.OnComplete(() =>
|
||||
{
|
||||
boxedColorHSVAPool.Return(boxedInitial);
|
||||
boxedColorHSVAPool.Return(boxedTarget);
|
||||
});
|
||||
|
||||
return tween;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user