perf!: events refactored throughout all the project to use Event<> class
All delegate events are refactored to use the Event<TSender> and Event<TSender, TArgument> for performance issues regarding delegate events creating garbage, also this gives us better control on event invocation since C# Delegates did also create unnecessary garbage during Delegate.DynamicInvoke
This commit is contained in:
@@ -4,14 +4,14 @@ namespace Syntriax.Engine.Systems.Tween;
|
||||
|
||||
internal class Tween : ITween
|
||||
{
|
||||
public event ITween.TweenEventHandler? OnStarted = null;
|
||||
public event ITween.TweenEventHandler? OnPaused = null;
|
||||
public event ITween.TweenEventHandler? OnResumed = null;
|
||||
public event ITween.TweenEventHandler? OnCancelled = null;
|
||||
public event ITween.TweenEventHandler? OnCompleted = null;
|
||||
public event ITween.TweenEventHandler? OnEnded = null;
|
||||
public event ITween.TweenEventHandler? OnUpdated = null;
|
||||
public event ITween.TweenDeltaEventHandler? OnDeltaUpdated = null;
|
||||
public Event<ITween> OnStarted { get; } = new();
|
||||
public Event<ITween> OnPaused { get; } = new();
|
||||
public Event<ITween> OnResumed { get; } = new();
|
||||
public Event<ITween> OnCancelled { get; } = new();
|
||||
public Event<ITween> OnCompleted { get; } = new();
|
||||
public Event<ITween> OnEnded { get; } = new();
|
||||
public Event<ITween> OnUpdated { get; } = new();
|
||||
public Event<ITween, ITween.TweenDeltaArguments> OnDeltaUpdated { get; } = new();
|
||||
|
||||
private TweenState _state = TweenState.Idle;
|
||||
public TweenState State
|
||||
@@ -60,7 +60,7 @@ internal class Tween : ITween
|
||||
Progress = Counter / Duration;
|
||||
OnUpdated?.Invoke(this);
|
||||
|
||||
OnDeltaUpdated?.Invoke(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
|
||||
OnDeltaUpdated?.Invoke(this, new(Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress)));
|
||||
|
||||
if (_counter >= Duration)
|
||||
State = TweenState.Completed;
|
||||
@@ -74,6 +74,22 @@ internal class Tween : ITween
|
||||
State = TweenState.Idle;
|
||||
}
|
||||
|
||||
internal void Wipe()
|
||||
{
|
||||
OnStarted.Clear();
|
||||
OnPaused.Clear();
|
||||
OnResumed.Clear();
|
||||
OnCancelled.Clear();
|
||||
OnCompleted.Clear();
|
||||
OnEnded.Clear();
|
||||
OnUpdated.Clear();
|
||||
OnDeltaUpdated.Clear();
|
||||
|
||||
Easing = EaseLinear.Instance;
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
public Tween() { }
|
||||
public Tween(float duration)
|
||||
{
|
||||
|
Reference in New Issue
Block a user