Syntriax.Engine/Engine.Core/Abstract/IBehaviourCollector.cs
Syntriax 61e2761580 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
2025-05-31 00:32:58 +03:00

43 lines
1.8 KiB
C#

namespace Syntriax.Engine.Core;
/// <summary>
/// Represents a collector for the class type of <typeparamref name="T"/>.
/// Provides mechanisms for tracking additions and removals, and notifies subscribers when such events occur on the assigned <see cref="IUniverse"/>.
/// </summary>
/// <typeparam name="T">The type of objects tracked by the collector.</typeparam>
public interface IBehaviourCollector<T> : IHasUniverse where T : class
{
/// <summary>
/// Event triggered when an object of type <typeparamref name="T"/> is added to the collector.
/// </summary>
Event<IBehaviourCollector<T>, BehaviourCollectedArguments> OnCollected { get; }
/// <summary>
/// Event triggered when an object of type <typeparamref name="T"/> is removed from the collector.
/// </summary>
Event<IBehaviourCollector<T>, BehaviourRemovedArguments> OnRemoved { get; }
/// <summary>
/// Amount of <typeparamref name="T"/> collected.
/// </summary>
int Count { get; }
/// <summary>
/// Get a <typeparamref name="T"/> collected by it's index.
/// </summary>
T this[System.Index index] { get; }
/// <summary>
/// Delegate for handling the <see cref="OnCollected"/> event.
/// </summary>
/// <param name="sender">The instance of the <see cref="IBehaviourCollector{T}"/> that triggered the event.</param>
/// <param name="behaviourCollected">The object of type <typeparamref name="T"/> that was added to the collector.</param>
readonly record struct BehaviourCollectedArguments(T BehaviourCollected);
/// <summary>
/// Delegate for handling the <see cref="OnRemoved"/> event.
/// </summary>
/// <param name="BehaviourRemoved">The object of type <typeparamref name="T"/> that was removed from the collector.</param>
readonly record struct BehaviourRemovedArguments(T BehaviourRemoved);
}