perf: DelegateExtensions.InvokeSafe marked obsolete for memory allocation reasons, soon to be removed
This commit is contained in:
@@ -53,12 +53,12 @@ public class State : BaseEntity, IState
|
||||
public void Update()
|
||||
{
|
||||
if (GetNextState() is IState transitionState)
|
||||
OnStateTransitionReady?.InvokeSafe(this, transitionState);
|
||||
OnStateUpdate?.InvokeSafe(this);
|
||||
OnStateTransitionReady?.Invoke(this, transitionState);
|
||||
OnStateUpdate?.Invoke(this);
|
||||
}
|
||||
|
||||
public void TransitionTo(IState from) => OnStateTransitionedTo?.InvokeSafe(this, from);
|
||||
public void TransitionFrom(IState to) => OnStateTransitionedFrom?.InvokeSafe(this, to);
|
||||
public void TransitionTo(IState from) => OnStateTransitionedTo?.Invoke(this, from);
|
||||
public void TransitionFrom(IState to) => OnStateTransitionedFrom?.Invoke(this, to);
|
||||
|
||||
public IState? GetNextState()
|
||||
{
|
||||
|
@@ -30,21 +30,21 @@ public abstract class StateBehaviourBase : Behaviour, IState
|
||||
public void Update()
|
||||
{
|
||||
OnUpdateState();
|
||||
OnStateUpdate?.InvokeSafe(this);
|
||||
OnStateUpdate?.Invoke(this);
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedToState(IState from) { }
|
||||
public void TransitionTo(IState from)
|
||||
{
|
||||
OnTransitionedToState(from);
|
||||
OnStateTransitionedTo?.InvokeSafe(this, from);
|
||||
OnStateTransitionedTo?.Invoke(this, from);
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedFromState(IState to) { }
|
||||
public void TransitionFrom(IState to)
|
||||
{
|
||||
OnTransitionedFromState(to);
|
||||
OnStateTransitionedFrom?.InvokeSafe(this, to);
|
||||
OnStateTransitionedFrom?.Invoke(this, to);
|
||||
}
|
||||
|
||||
public abstract IState? GetNextState();
|
||||
|
@@ -23,7 +23,7 @@ public class StateMachine : Behaviour
|
||||
_state = value;
|
||||
previousState.TransitionFrom(value);
|
||||
value.TransitionTo(_state);
|
||||
OnStateChanged?.InvokeSafe(this, previousState, value);
|
||||
OnStateChanged?.Invoke(this, previousState, value);
|
||||
|
||||
value.OnStateTransitionReady += OnStateTransitionReady;
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
|
||||
shouldBeTicking = false;
|
||||
|
||||
State = TimerState.Stopped;
|
||||
OnStopped?.InvokeSafe(this);
|
||||
OnStopped?.Invoke(this);
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
@@ -46,7 +46,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
|
||||
double delta = Universe.Time.DeltaSpan.TotalSeconds;
|
||||
|
||||
Time += delta;
|
||||
OnDelta?.InvokeSafe(this, delta);
|
||||
OnDelta?.Invoke(this, delta);
|
||||
}
|
||||
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
@@ -71,13 +71,13 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
|
||||
public virtual void Pause()
|
||||
{
|
||||
State = TimerState.Paused;
|
||||
OnPaused?.InvokeSafe(this);
|
||||
OnPaused?.Invoke(this);
|
||||
}
|
||||
|
||||
public virtual void Resume()
|
||||
{
|
||||
State = TimerState.Ticking;
|
||||
OnResumed?.InvokeSafe(this);
|
||||
OnResumed?.Invoke(this);
|
||||
}
|
||||
|
||||
private void StartStopwatch()
|
||||
@@ -85,7 +85,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
|
||||
hasStartedTickingBefore = true;
|
||||
|
||||
State = TimerState.Ticking;
|
||||
OnStarted?.InvokeSafe(this);
|
||||
OnStarted?.Invoke(this);
|
||||
}
|
||||
|
||||
protected override void OnFinalize()
|
||||
|
@@ -26,7 +26,7 @@ public class TickerBehaviour : StopwatchBehaviour, ITicker
|
||||
{
|
||||
nextTick += Period;
|
||||
TickCounter++;
|
||||
OnTick?.InvokeSafe(this);
|
||||
OnTick?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -50,7 +50,7 @@ public class TimerBehaviour : Behaviour, ITimer
|
||||
shouldBeTicking = false;
|
||||
|
||||
State = TimerState.Stopped;
|
||||
OnStopped?.InvokeSafe(this);
|
||||
OnStopped?.Invoke(this);
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
@@ -61,7 +61,7 @@ public class TimerBehaviour : Behaviour, ITimer
|
||||
double delta = Universe.Time.DeltaSpan.TotalSeconds;
|
||||
|
||||
Remaining -= delta;
|
||||
OnDelta?.InvokeSafe(this, delta);
|
||||
OnDelta?.Invoke(this, delta);
|
||||
|
||||
if (Remaining <= .0f)
|
||||
Stop();
|
||||
@@ -89,13 +89,13 @@ public class TimerBehaviour : Behaviour, ITimer
|
||||
public virtual void Pause()
|
||||
{
|
||||
State = TimerState.Paused;
|
||||
OnPaused?.InvokeSafe(this);
|
||||
OnPaused?.Invoke(this);
|
||||
}
|
||||
|
||||
public virtual void Resume()
|
||||
{
|
||||
State = TimerState.Ticking;
|
||||
OnResumed?.InvokeSafe(this);
|
||||
OnResumed?.Invoke(this);
|
||||
}
|
||||
|
||||
private void StartTimer()
|
||||
@@ -103,7 +103,7 @@ public class TimerBehaviour : Behaviour, ITimer
|
||||
hasStartedTickingBefore = true;
|
||||
|
||||
State = TimerState.Ticking;
|
||||
OnStarted?.InvokeSafe(this);
|
||||
OnStarted?.Invoke(this);
|
||||
}
|
||||
|
||||
protected override void OnFinalize()
|
||||
|
@@ -6,5 +6,5 @@ namespace Syntriax.Engine.Systems.Tween;
|
||||
public static class TweenAABBExtensions
|
||||
{
|
||||
public static ITween TweenAABB(this AABB initialAABB, ITweenManager tweenManager, float duration, AABB targetAABB, Action<AABB> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(new AABB(initialAABB.LowerBoundary.Lerp(targetAABB.LowerBoundary, t), initialAABB.UpperBoundary.Lerp(targetAABB.UpperBoundary, t))));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(new AABB(initialAABB.LowerBoundary.Lerp(targetAABB.LowerBoundary, t), initialAABB.UpperBoundary.Lerp(targetAABB.UpperBoundary, t))));
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ public static class TweenCircleExtensions
|
||||
{
|
||||
public static ITween TweenCircle(this Circle initialCircle, ITweenManager tweenManager, float duration, Circle targetCircle, System.Action<Circle> setMethod)
|
||||
=> tweenManager.StartTween(duration,
|
||||
t => setMethod?.InvokeSafe(
|
||||
t => setMethod?.Invoke(
|
||||
new Circle(
|
||||
initialCircle.Center.Lerp(targetCircle.Center, t),
|
||||
initialCircle.Diameter.Lerp(targetCircle.Diameter, t)
|
||||
|
@@ -5,11 +5,11 @@ namespace Syntriax.Engine.Systems.Tween;
|
||||
public static class TweenColorExtensions
|
||||
{
|
||||
public static ITween TweenColor(this ColorRGB initialColorRGB, ITweenManager tweenManager, float duration, ColorRGB targetColorRGB, System.Action<ColorRGB> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGB.Lerp(targetColorRGB, t)));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorRGB.Lerp(targetColorRGB, t)));
|
||||
|
||||
public static ITween TweenColor(this ColorRGBA initialColorRGBA, ITweenManager tweenManager, float duration, ColorRGBA targetColorRGBA, System.Action<ColorRGBA> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGBA.Lerp(targetColorRGBA, t)));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorRGBA.Lerp(targetColorRGBA, t)));
|
||||
|
||||
public static ITween TweenColor(this ColorHSV initialColorHSV, ITweenManager tweenManager, float duration, ColorHSV targetColorHSV, System.Action<ColorHSV> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorHSV.Lerp(targetColorHSV, t)));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorHSV.Lerp(targetColorHSV, t)));
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ public static class TweenLine2DEquationExtensions
|
||||
{
|
||||
public static ITween TweenLine2DEquation(this Line2DEquation initialLine2DEquation, ITweenManager tweenManager, float duration, Line2DEquation targetLine2DEquation, System.Action<Line2DEquation> setMethod)
|
||||
=> tweenManager.StartTween(duration,
|
||||
t => setMethod?.InvokeSafe(
|
||||
t => setMethod?.Invoke(
|
||||
new Line2DEquation(
|
||||
initialLine2DEquation.Slope.Lerp(targetLine2DEquation.Slope, t),
|
||||
initialLine2DEquation.OffsetY.Lerp(targetLine2DEquation.OffsetY, t)
|
||||
|
@@ -6,7 +6,7 @@ public static class TweenLine2DExtensions
|
||||
{
|
||||
public static ITween TweenLine2D(this Line2D initialLine2D, ITweenManager tweenManager, float duration, Line2D targetLine2D, System.Action<Line2D> setMethod)
|
||||
=> tweenManager.StartTween(duration,
|
||||
t => setMethod?.InvokeSafe(
|
||||
t => setMethod?.Invoke(
|
||||
new Line2D(
|
||||
initialLine2D.From.Lerp(targetLine2D.From, t),
|
||||
initialLine2D.To.Lerp(targetLine2D.To, t)
|
||||
|
@@ -7,7 +7,7 @@ public static class TweenProjection1DExtensions
|
||||
{
|
||||
public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, Action<Projection1D> setMethod)
|
||||
=> tweenManager.StartTween(duration,
|
||||
t => setMethod?.InvokeSafe(
|
||||
t => setMethod?.Invoke(
|
||||
new Projection1D(
|
||||
initialProjection1D.Min.Lerp(targetProjection1D.Min, t),
|
||||
initialProjection1D.Max.Lerp(targetProjection1D.Max, t)
|
||||
|
@@ -6,5 +6,5 @@ namespace Syntriax.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?.InvokeSafe(initialQuaternion.SLerp(targetQuaternion, t)));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialQuaternion.SLerp(targetQuaternion, t)));
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ public static class TweenTriangleExtensions
|
||||
{
|
||||
public static ITween TweenTriangle(this Triangle initialTriangle, ITweenManager tweenManager, float duration, Triangle targetTriangle, Action<Triangle> setMethod)
|
||||
=> tweenManager.StartTween(duration,
|
||||
t => setMethod?.InvokeSafe(
|
||||
t => setMethod?.Invoke(
|
||||
new Triangle(
|
||||
initialTriangle.A.Lerp(targetTriangle.A, t),
|
||||
initialTriangle.B.Lerp(targetTriangle.B, t),
|
||||
|
@@ -5,5 +5,5 @@ namespace Syntriax.Engine.Systems.Tween;
|
||||
public static class TweenVector2DExtensions
|
||||
{
|
||||
public static ITween TweenVector2D(this Vector2D initialVector2D, ITweenManager tweenManager, float duration, Vector2D targetVector2D, System.Action<Vector2D> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector2D.Lerp(targetVector2D, t)));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialVector2D.Lerp(targetVector2D, t)));
|
||||
}
|
||||
|
@@ -5,5 +5,5 @@ namespace Syntriax.Engine.Systems.Tween;
|
||||
public static class TweenVector3DExtensions
|
||||
{
|
||||
public static ITween TweenVector3D(this Vector3D initialVector3D, ITweenManager tweenManager, float duration, Vector3D targetVector3D, System.Action<Vector3D> setMethod)
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector3D.Lerp(targetVector3D, t)));
|
||||
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialVector3D.Lerp(targetVector3D, t)));
|
||||
}
|
||||
|
@@ -26,14 +26,14 @@ internal class Tween : ITween
|
||||
_state = value;
|
||||
switch (value)
|
||||
{
|
||||
case TweenState.Completed: OnCompleted?.InvokeSafe(this); OnEnded?.InvokeSafe(this); break;
|
||||
case TweenState.Cancelled: OnCancelled?.InvokeSafe(this); OnEnded?.InvokeSafe(this); break;
|
||||
case TweenState.Paused: OnPaused?.InvokeSafe(this); break;
|
||||
case TweenState.Completed: OnCompleted?.Invoke(this); OnEnded?.Invoke(this); break;
|
||||
case TweenState.Cancelled: OnCancelled?.Invoke(this); OnEnded?.Invoke(this); break;
|
||||
case TweenState.Paused: OnPaused?.Invoke(this); break;
|
||||
case TweenState.Playing:
|
||||
if (previousState == TweenState.Idle)
|
||||
OnStarted?.InvokeSafe(this);
|
||||
OnStarted?.Invoke(this);
|
||||
else
|
||||
OnResumed?.InvokeSafe(this);
|
||||
OnResumed?.Invoke(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -58,9 +58,9 @@ internal class Tween : ITween
|
||||
|
||||
_counter = value.Min(Duration).Max(0f);
|
||||
Progress = Counter / Duration;
|
||||
OnUpdated?.InvokeSafe(this);
|
||||
OnUpdated?.Invoke(this);
|
||||
|
||||
OnDeltaUpdated?.InvokeSafe(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
|
||||
OnDeltaUpdated?.Invoke(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
|
||||
|
||||
if (_counter >= Duration)
|
||||
State = TweenState.Completed;
|
||||
|
@@ -46,56 +46,56 @@ public static class TweenExtensions
|
||||
public static ITween OnStart(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnStarted += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnStarted += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnPause(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnPaused += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnPaused += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnResume(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnResumed += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnResumed += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnCancel(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnCancelled += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnCancelled += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnComplete(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnCompleted += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnCompleted += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnEnd(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnEnded += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnEnded += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnUpdate(this ITween tween, Action callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnUpdated += _ => callback.InvokeSafe();
|
||||
tweenConcrete.OnUpdated += _ => callback.Invoke();
|
||||
return tween;
|
||||
}
|
||||
|
||||
public static ITween OnDeltaUpdate(this ITween tween, Action<float> callback)
|
||||
{
|
||||
Tween tweenConcrete = (Tween)tween;
|
||||
tweenConcrete.OnDeltaUpdated += (_, delta) => callback.InvokeSafe(delta);
|
||||
tweenConcrete.OnDeltaUpdated += (_, delta) => callback.Invoke(delta);
|
||||
return tween;
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ public class TweenManager : UniverseObject, ITweenManager
|
||||
public ITween StartTween(float duration, ITweenManager.TweenSetCallback? setCallback = null)
|
||||
{
|
||||
Tween tween = new(duration);
|
||||
tween.OnUpdated += tween => setCallback?.InvokeSafe(tween.Value);
|
||||
tween.OnUpdated += tween => setCallback?.Invoke(tween.Value);
|
||||
runningCoroutines.Add(tween, coroutineManager.StartCoroutine(RunTween(tween)));
|
||||
return tween;
|
||||
}
|
||||
|
Reference in New Issue
Block a user