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,10 +4,10 @@ namespace Syntriax.Engine.Systems.StateMachine;
public interface IState : IEntity, INameable
{
event StateUpdateEventHandler? OnStateUpdate;
event StateTransitionedFromEventHandler? OnStateTransitionedFrom;
event StateTransitionedToEventHandler? OnStateTransitionedTo;
event StateTransitionReadyEventHandler? OnStateTransitionReady;
Event<IState> OnStateUpdate { get; }
Event<IState, StateTransitionedFromArguments> OnStateTransitionedFrom { get; }
Event<IState, StateTransitionedToArguments> OnStateTransitionedTo { get; }
Event<IState, StateTransitionReadyArguments> OnStateTransitionReady { get; }
IState? GetNextState();
@@ -15,8 +15,7 @@ public interface IState : IEntity, INameable
void TransitionTo(IState from);
void TransitionFrom(IState to);
delegate void StateUpdateEventHandler(IState sender);
delegate void StateTransitionedFromEventHandler(IState sender, IState toState);
delegate void StateTransitionedToEventHandler(IState sender, IState fromState);
delegate void StateTransitionReadyEventHandler(IState sender, IState toState);
readonly record struct StateTransitionedFromArguments(IState ToState);
readonly record struct StateTransitionedToArguments(IState FromState);
readonly record struct StateTransitionReadyArguments(IState ToState);
}