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,12 +4,11 @@ namespace Syntriax.Engine.Systems.StateMachine;
|
||||
|
||||
public abstract class StateBehaviourBase : Behaviour, IState
|
||||
{
|
||||
public event IState.StateUpdateEventHandler? OnStateUpdate = null;
|
||||
public event IState.StateTransitionedFromEventHandler? OnStateTransitionedFrom = null;
|
||||
public event IState.StateTransitionedToEventHandler? OnStateTransitionedTo = null;
|
||||
public event INameable.NameChangedEventHandler? OnNameChanged = null;
|
||||
|
||||
public abstract event IState.StateTransitionReadyEventHandler? OnStateTransitionReady;
|
||||
public Event<IState> OnStateUpdate { get; } = new();
|
||||
public Event<IState, IState.StateTransitionedFromArguments> OnStateTransitionedFrom { get; } = new();
|
||||
public Event<IState, IState.StateTransitionedToArguments> OnStateTransitionedTo { get; } = new();
|
||||
public Event<IState, IState.StateTransitionReadyArguments> OnStateTransitionReady { get; } = new();
|
||||
public Event<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new();
|
||||
|
||||
private string _name = string.Empty;
|
||||
public string Name
|
||||
@@ -22,7 +21,7 @@ public abstract class StateBehaviourBase : Behaviour, IState
|
||||
|
||||
string previousName = _name;
|
||||
_name = value;
|
||||
OnNameChanged?.Invoke(this, previousName);
|
||||
OnNameChanged?.Invoke(this, new(previousName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,14 +36,14 @@ public abstract class StateBehaviourBase : Behaviour, IState
|
||||
public void TransitionTo(IState from)
|
||||
{
|
||||
OnTransitionedToState(from);
|
||||
OnStateTransitionedTo?.Invoke(this, from);
|
||||
OnStateTransitionedTo?.Invoke(this, new(from));
|
||||
}
|
||||
|
||||
protected virtual void OnTransitionedFromState(IState to) { }
|
||||
public void TransitionFrom(IState to)
|
||||
{
|
||||
OnTransitionedFromState(to);
|
||||
OnStateTransitionedFrom?.Invoke(this, to);
|
||||
OnStateTransitionedFrom?.Invoke(this, new(to));
|
||||
}
|
||||
|
||||
public abstract IState? GetNextState();
|
||||
|
Reference in New Issue
Block a user