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:
@@ -1,17 +1,31 @@
|
||||
using System;
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Tween;
|
||||
|
||||
public static class TweenProjection1DExtensions
|
||||
{
|
||||
public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, Action<Projection1D> setMethod)
|
||||
=> tweenManager.StartTween(duration,
|
||||
private static readonly BoxedPool<Projection1D> boxedProjection1DPool = new(2);
|
||||
|
||||
public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, System.Action<Projection1D> setMethod)
|
||||
{
|
||||
Boxed<Projection1D> boxedInitial = boxedProjection1DPool.Get(initialProjection1D);
|
||||
Boxed<Projection1D> boxedTarget = boxedProjection1DPool.Get(targetProjection1D);
|
||||
|
||||
ITween tween = tweenManager.StartTween(duration,
|
||||
t => setMethod?.Invoke(
|
||||
new Projection1D(
|
||||
initialProjection1D.Min.Lerp(targetProjection1D.Min, t),
|
||||
initialProjection1D.Max.Lerp(targetProjection1D.Max, t)
|
||||
boxedInitial.Value.Min.Lerp(boxedTarget.Value.Min, t),
|
||||
boxedInitial.Value.Max.Lerp(boxedTarget.Value.Max, t)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
tween.OnComplete(() =>
|
||||
{
|
||||
boxedProjection1DPool.Return(boxedInitial);
|
||||
boxedProjection1DPool.Return(boxedTarget);
|
||||
});
|
||||
|
||||
return tween;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user