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

@@ -1,3 +1,5 @@
using Syntriax.Engine.Core;
namespace Syntriax.Engine.Physics2D;
/// <summary>
@@ -8,12 +10,12 @@ public interface IPhysicsEngine2D
/// <summary>
/// Event triggered when the <see cref="IPhysicsEngine2D"/> has done a single physics iteration.
/// </summary>
event PhysicsIterationEventHandler? OnPhysicsIteration;
Event<IPhysicsEngine2D, float> OnPhysicsIteration { get; }
/// <summary>
/// Event triggered when the <see cref="IPhysicsEngine2D"/> has done a full physics step/>.
/// </summary>
event PhysicsStepEventHandler? OnPhysicsStep;
Event<IPhysicsEngine2D, float> OnPhysicsStep { get; }
/// <summary>
/// The number of iterations the <see cref="IPhysicsEngine2D"/> performs per step.
@@ -33,6 +35,6 @@ public interface IPhysicsEngine2D
/// <param name="deltaTime">The time step.</param>
void StepIndividual(IRigidBody2D rigidBody, float deltaTime);
delegate void PhysicsIterationEventHandler(IPhysicsEngine2D sender, float iterationDeltaTime);
delegate void PhysicsStepEventHandler(IPhysicsEngine2D sender, float stepDeltaTime);
readonly record struct PhysicsIterationArguments(IPhysicsEngine2D sender, float iterationDeltaTime);
readonly record struct PhysicsStepArguments(IPhysicsEngine2D sender, float stepDeltaTime);
}