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,11 +4,11 @@ namespace Syntriax.Engine.Systems.Time;
|
||||
|
||||
public class TimerBehaviour : Behaviour, ITimer
|
||||
{
|
||||
public event IReadOnlyTimer.TimerEventHandler? OnStarted = null;
|
||||
public event IReadOnlyTimer.TimerDeltaEventHandler? OnDelta = null;
|
||||
public event IReadOnlyTimer.TimerEventHandler? OnStopped = null;
|
||||
public event IReadOnlyTimer.TimerEventHandler? OnPaused = null;
|
||||
public event IReadOnlyTimer.TimerEventHandler? OnResumed = null;
|
||||
public Event<IReadOnlyTimer> OnStarted { get; } = new();
|
||||
public Event<IReadOnlyTimer, IReadOnlyTimer.TimerDeltaArguments> OnDelta { get; } = new();
|
||||
public Event<IReadOnlyTimer> OnStopped { get; } = new();
|
||||
public Event<IReadOnlyTimer> OnPaused { get; } = new();
|
||||
public Event<IReadOnlyTimer> OnResumed { get; } = new();
|
||||
|
||||
public TimerState State { get; protected set; } = TimerState.Idle;
|
||||
public double StartTime { get; protected set; } = 0f;
|
||||
@@ -61,7 +61,7 @@ public class TimerBehaviour : Behaviour, ITimer
|
||||
double delta = Universe.Time.DeltaSpan.TotalSeconds;
|
||||
|
||||
Remaining -= delta;
|
||||
OnDelta?.Invoke(this, delta);
|
||||
OnDelta?.Invoke(this, new(delta));
|
||||
|
||||
if (Remaining <= .0f)
|
||||
Stop();
|
||||
|
||||
Reference in New Issue
Block a user