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:
@@ -5,7 +5,7 @@ namespace Syntriax.Engine.Core.Serialization;
|
||||
|
||||
public class EntityRegistry
|
||||
{
|
||||
public event EntityRegisteredEventHandler? OnEntityRegistered = null!;
|
||||
public Event<EntityRegistry, EntityRegisteredArguments> OnEntityRegistered = null!;
|
||||
|
||||
private readonly Dictionary<string, Action<IEntity>?> assignCallbacks = [];
|
||||
private readonly Dictionary<string, IEntity> registeredEntities = [];
|
||||
@@ -14,7 +14,7 @@ public class EntityRegistry
|
||||
public void Add(IEntity entity)
|
||||
{
|
||||
if (registeredEntities.TryAdd(entity.Id, entity))
|
||||
OnEntityRegistered?.Invoke(this, entity);
|
||||
OnEntityRegistered?.Invoke(this, new(entity));
|
||||
}
|
||||
|
||||
public void QueueAssign(string id, Action<IEntity> setMethod)
|
||||
@@ -35,5 +35,5 @@ public class EntityRegistry
|
||||
registeredEntities.Clear();
|
||||
}
|
||||
|
||||
public delegate void EntityRegisteredEventHandler(EntityRegistry sender, IEntity entity);
|
||||
public readonly record struct EntityRegisteredArguments(IEntity Entity);
|
||||
}
|
||||
|
Reference in New Issue
Block a user