feat: IPhysicsEngine2D Events
This commit is contained in:
parent
9c2b098821
commit
62e50aefc1
|
@ -5,6 +5,16 @@ namespace Syntriax.Engine.Physics2D.Abstract;
|
|||
/// </summary>
|
||||
public interface IPhysicsEngine2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IPhysicsEngine2D"/> has done a single physics iteration.
|
||||
/// </summary>
|
||||
event OnPhysicsIterationDelegate? OnPhysicsIteration;
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="IPhysicsEngine2D"/> has done a full physics step/>.
|
||||
/// </summary>
|
||||
event OnPhysicsStepDelegate? OnPhysicsStep;
|
||||
|
||||
/// <summary>
|
||||
/// The number of iterations the <see cref="IPhysicsEngine2D"/> performs per step.
|
||||
/// </summary>
|
||||
|
@ -15,4 +25,7 @@ public interface IPhysicsEngine2D
|
|||
/// </summary>
|
||||
/// <param name="deltaTime">The time step.</param>
|
||||
void Step(float deltaTime);
|
||||
|
||||
delegate void OnPhysicsIterationDelegate(IPhysicsEngine2D sender, float iterationDeltaTime);
|
||||
delegate void OnPhysicsStepDelegate(IPhysicsEngine2D sender, float stepDeltaTime);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
using Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
|
@ -8,6 +7,9 @@ namespace Syntriax.Engine.Physics2D;
|
|||
|
||||
public class PhysicsEngine2D : IPhysicsEngine2D
|
||||
{
|
||||
public event IPhysicsEngine2D.OnPhysicsIterationDelegate? OnPhysicsIteration = null;
|
||||
public event IPhysicsEngine2D.OnPhysicsStepDelegate? OnPhysicsStep = null;
|
||||
|
||||
private readonly List<IRigidBody2D> rigidBodies = new(32);
|
||||
private readonly List<ICollider2D> colliders = new(64);
|
||||
|
||||
|
@ -96,7 +98,9 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
|||
}
|
||||
}
|
||||
}
|
||||
OnPhysicsIteration?.Invoke(this, intervalDeltaTime);
|
||||
}
|
||||
OnPhysicsStep?.Invoke(this, deltaTime);
|
||||
}
|
||||
|
||||
private static void StepRigidBody(IRigidBody2D rigidBody, float intervalDeltaTime)
|
||||
|
|
|
@ -9,6 +9,8 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
|||
public event IAssignable.OnUnassignedDelegate? OnUnassigned = null;
|
||||
public event IAssignableGameManager.OnGameManagerAssignedDelegate? OnGameManagerAssigned = null;
|
||||
|
||||
public event IPhysicsEngine2D.OnPhysicsIterationDelegate? OnPhysicsIteration = null;
|
||||
public event IPhysicsEngine2D.OnPhysicsStepDelegate? OnPhysicsStep = null;
|
||||
|
||||
private int _iterationPerStep = 1;
|
||||
|
||||
|
@ -82,10 +84,14 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
OnPhysicsIteration?.Invoke(this, intervalDeltaTime);
|
||||
}
|
||||
|
||||
foreach (IPhysicsUpdate physicsUpdate in physicsUpdateCollector)
|
||||
physicsUpdate.PhysicsUpdate(deltaTime);
|
||||
|
||||
OnPhysicsStep?.Invoke(this, deltaTime);
|
||||
}
|
||||
|
||||
private static void StepRigidBody(IRigidBody2D rigidBody, float intervalDeltaTime)
|
||||
|
|
Loading…
Reference in New Issue