From ffa0128813abbb9f79ea99cc0e116fa0af5577e7 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 26 Sep 2024 18:55:15 +0300 Subject: [PATCH] feat: IPhysicsUpdate --- Engine.Physics2D/Abstract/IPhysicsUpdate.cs | 15 +++++++++++++++ Engine.Physics2D/PhysicsEngine2DCollector.cs | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 Engine.Physics2D/Abstract/IPhysicsUpdate.cs diff --git a/Engine.Physics2D/Abstract/IPhysicsUpdate.cs b/Engine.Physics2D/Abstract/IPhysicsUpdate.cs new file mode 100644 index 0000000..c5ac3cf --- /dev/null +++ b/Engine.Physics2D/Abstract/IPhysicsUpdate.cs @@ -0,0 +1,15 @@ +using Syntriax.Engine.Core.Abstract; + +namespace Syntriax.Engine.Physics2D.Abstract; + +/// +/// Represents a that listens to physics simulation update phase. +/// +public interface IPhysicsUpdate : IBehaviour +{ + /// + /// Updates the physics state of the object based on the elapsed time since the last update. + /// + /// The time elapsed since the last physics update, typically in seconds. + void PhysicsUpdate(float delta); +} diff --git a/Engine.Physics2D/PhysicsEngine2DCollector.cs b/Engine.Physics2D/PhysicsEngine2DCollector.cs index 0cc60ab..c7eb131 100644 --- a/Engine.Physics2D/PhysicsEngine2DCollector.cs +++ b/Engine.Physics2D/PhysicsEngine2DCollector.cs @@ -17,6 +17,7 @@ public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager protected BehaviourCollector rigidBodyCollector = new(); protected BehaviourCollector colliderCollector = new(); + protected BehaviourCollector 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();