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,10 +1,24 @@
|
||||
using System;
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Tween;
|
||||
|
||||
public static class TweenQuaternionExtensions
|
||||
{
|
||||
public static ITween TweenQuaternion(this Quaternion initialQuaternion, ITweenManager tweenManager, float duration, Quaternion targetQuaternion, Action<Quaternion> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialQuaternion.SLerp(targetQuaternion, t)));
|
||||
private static readonly BoxedPool<Quaternion> boxedQuaternionPool = new(2);
|
||||
|
||||
public static ITween TweenQuaternion(this Quaternion initialQuaternion, ITweenManager tweenManager, float duration, Quaternion targetQuaternion, System.Action<Quaternion> setMethod)
|
||||
{
|
||||
Boxed<Quaternion> boxedInitial = boxedQuaternionPool.Get(initialQuaternion);
|
||||
Boxed<Quaternion> boxedTarget = boxedQuaternionPool.Get(targetQuaternion);
|
||||
|
||||
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.SLerp(boxedTarget.Value, t)));
|
||||
|
||||
tween.OnComplete(() =>
|
||||
{
|
||||
boxedQuaternionPool.Return(boxedInitial);
|
||||
boxedQuaternionPool.Return(boxedTarget);
|
||||
});
|
||||
|
||||
return tween;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user