feat: IPhysicsUpdate
This commit is contained in:
parent
15984bcc06
commit
ffa0128813
|
@ -0,0 +1,15 @@
|
|||
using Syntriax.Engine.Core.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D.Abstract;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a <see cref="IBehaviour"/> that listens to physics simulation update phase.
|
||||
/// </summary>
|
||||
public interface IPhysicsUpdate : IBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the physics state of the object based on the elapsed time since the last update.
|
||||
/// </summary>
|
||||
/// <param name="delta">The time elapsed since the last physics update, typically in seconds.</param>
|
||||
void PhysicsUpdate(float delta);
|
||||
}
|
|
@ -17,6 +17,7 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
|||
|
||||
protected BehaviourCollector<IRigidBody2D> rigidBodyCollector = new();
|
||||
protected BehaviourCollector<ICollider2D> colliderCollector = new();
|
||||
protected BehaviourCollector<IPhysicsUpdate> physicsUpdateCollector = new();
|
||||
|
||||
|
||||
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; }
|
||||
|
@ -82,6 +83,9 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (IPhysicsUpdate physicsUpdate in physicsUpdateCollector)
|
||||
physicsUpdate.PhysicsUpdate(deltaTime);
|
||||
}
|
||||
|
||||
private static void StepRigidBody(IRigidBody2D rigidBody, float intervalDeltaTime)
|
||||
|
@ -98,6 +102,7 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
|||
if (GameManager is not null)
|
||||
return false;
|
||||
|
||||
physicsUpdateCollector.Assign(gameManager);
|
||||
colliderCollector.Assign(gameManager);
|
||||
rigidBodyCollector.Assign(gameManager);
|
||||
|
||||
|
@ -112,6 +117,7 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
|
|||
if (GameManager is null)
|
||||
return false;
|
||||
|
||||
physicsUpdateCollector.Unassign();
|
||||
colliderCollector.Unassign();
|
||||
rigidBodyCollector.Unassign();
|
||||
|
||||
|
|
Loading…
Reference in New Issue