refactor: switched from universe objects to behaviours on all managers like update, draw & physics etc.
This commit is contained in:
@@ -5,7 +5,7 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsCoroutineManager : UniverseObject
|
||||
public class PhysicsCoroutineManager : Behaviour
|
||||
{
|
||||
private readonly Event<IUniverse, IUniverse.UpdateArguments>.EventHandler delegateOnUpdate = null!;
|
||||
|
||||
@@ -23,9 +23,9 @@ public class PhysicsCoroutineManager : UniverseObject
|
||||
enumerators.Remove(enumerator);
|
||||
}
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
physicsEngine = universe.GetUniverseObject<IPhysicsEngine2D>();
|
||||
physicsEngine = universe.FindRequiredBehaviour<IPhysicsEngine2D>();
|
||||
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
||||
foundPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
||||
else
|
||||
@@ -44,11 +44,11 @@ public class PhysicsCoroutineManager : UniverseObject
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
if (physicsEngine is IPhysicsEngine2D existingPhysicsEngine)
|
||||
existingPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
||||
universe.OnUpdate.RemoveListener(OnUpdate);
|
||||
universe.OnUpdate.RemoveListener(delegateOnUpdate);
|
||||
}
|
||||
|
||||
private void OnUpdate(IUniverse sender, IUniverse.UpdateArguments args)
|
||||
@@ -56,11 +56,11 @@ public class PhysicsCoroutineManager : UniverseObject
|
||||
if (Universe is not IUniverse universe)
|
||||
return;
|
||||
|
||||
physicsEngine = universe.GetUniverseObject<IPhysicsEngine2D>();
|
||||
physicsEngine = universe.FindRequiredBehaviour<IPhysicsEngine2D>();
|
||||
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
||||
{
|
||||
foundPhysicsEngine.OnPhysicsStep.AddListener(OnPhysicsStep);
|
||||
universe.OnUpdate.RemoveListener(OnUpdate);
|
||||
universe.OnUpdate.RemoveListener(delegateOnUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
|
||||
public class PhysicsEngine2D : Behaviour, IPhysicsEngine2D
|
||||
{
|
||||
public Event<IPhysicsEngine2D, float> OnPhysicsIteration { get; } = new();
|
||||
public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new();
|
||||
@@ -174,7 +174,7 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
|
||||
rigidBody.Transform.Rotation += rigidBody.AngularVelocity * intervalDeltaTime;
|
||||
}
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
protected override void OnEnteredUniverse(IUniverse universe)
|
||||
{
|
||||
physicsPreUpdateCollector.Assign(universe);
|
||||
physicsUpdateCollector.Assign(universe);
|
||||
@@ -185,7 +185,7 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
|
||||
universe.OnPreUpdate.AddListener(OnEnginePreUpdate);
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
{
|
||||
physicsPreUpdateCollector.Unassign();
|
||||
physicsUpdateCollector.Unassign();
|
||||
|
Reference in New Issue
Block a user