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:
2025-05-31 00:14:43 +03:00
parent 996e61d0ad
commit 61e2761580
58 changed files with 637 additions and 485 deletions

View File

@@ -4,11 +4,11 @@ namespace Syntriax.Engine.Systems.Time;
public class StopwatchBehaviour : Behaviour, IStopwatch
{
public event IReadOnlyStopwatch.StopwatchEventHandler? OnStarted = null;
public event IReadOnlyStopwatch.StopwatchDeltaEventHandler? OnDelta = null;
public event IReadOnlyStopwatch.StopwatchEventHandler? OnStopped = null;
public event IReadOnlyStopwatch.StopwatchEventHandler? OnPaused = null;
public event IReadOnlyStopwatch.StopwatchEventHandler? OnResumed = null;
public Event<IReadOnlyStopwatch> OnStarted { get; } = new();
public Event<IReadOnlyStopwatch, IReadOnlyStopwatch.StopwatchDeltaArguments> OnDelta { get; } = new();
public Event<IReadOnlyStopwatch> OnStopped { get; } = new();
public Event<IReadOnlyStopwatch> OnPaused { get; } = new();
public Event<IReadOnlyStopwatch> OnResumed { get; } = new();
public double Time { get; protected set; } = 0f;
public TimerState State { get; protected set; } = TimerState.Idle;
@@ -46,7 +46,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
double delta = Universe.Time.DeltaSpan.TotalSeconds;
Time += delta;
OnDelta?.Invoke(this, delta);
OnDelta?.Invoke(this, new(delta));
}
protected override void OnEnteredUniverse(IUniverse universe)