refactor: switched from universe objects to behaviours on all managers like update, draw & physics etc.
This commit is contained in:
parent
24d1a1d764
commit
beecefec1c
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
public class CoroutineManager : UniverseObject
|
public class CoroutineManager : Behaviour
|
||||||
{
|
{
|
||||||
private readonly List<IEnumerator> enumerators = [];
|
private readonly List<IEnumerator> enumerators = [];
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ public class CoroutineManager : UniverseObject
|
|||||||
enumerators.Remove(enumerator);
|
enumerators.Remove(enumerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnEnteringUniverse(IUniverse universe)
|
protected override void OnEnteredUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
universe.OnUpdate.AddListener(OnUpdate);
|
universe.OnUpdate.AddListener(OnUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExitingUniverse(IUniverse universe)
|
protected override void OnExitedUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
universe.OnUpdate.RemoveListener(OnUpdate);
|
universe.OnUpdate.RemoveListener(OnUpdate);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
public class DrawManager : UniverseObject
|
public class DrawManager : Behaviour
|
||||||
{
|
{
|
||||||
// We use Descending order because draw calls are running from last to first
|
// We use Descending order because draw calls are running from last to first
|
||||||
private static Comparer<IBehaviour> SortByDescendingPriority() => Comparer<IBehaviour>.Create((x, y) => y.Priority.CompareTo(x.Priority));
|
private static Comparer<IBehaviour> SortByDescendingPriority() => Comparer<IBehaviour>.Create((x, y) => y.Priority.CompareTo(x.Priority));
|
||||||
@ -29,7 +29,7 @@ public class DrawManager : UniverseObject
|
|||||||
postDrawEntities[i].PostDraw();
|
postDrawEntities[i].PostDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnEnteringUniverse(IUniverse universe)
|
protected override void OnEnteredUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
preDrawEntities.Assign(universe);
|
preDrawEntities.Assign(universe);
|
||||||
drawEntities.Assign(universe);
|
drawEntities.Assign(universe);
|
||||||
@ -40,7 +40,7 @@ public class DrawManager : UniverseObject
|
|||||||
universe.OnPostDraw.AddListener(OnPostDraw);
|
universe.OnPostDraw.AddListener(OnPostDraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExitingUniverse(IUniverse universe)
|
protected override void OnExitedUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
preDrawEntities.Unassign();
|
preDrawEntities.Unassign();
|
||||||
drawEntities.Unassign();
|
drawEntities.Unassign();
|
||||||
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Core;
|
namespace Syntriax.Engine.Core;
|
||||||
|
|
||||||
public class UpdateManager : UniverseObject
|
public class UpdateManager : Behaviour
|
||||||
{
|
{
|
||||||
// We use Ascending order because draw calls are running from last to first
|
// We use Ascending order because draw calls are running from last to first
|
||||||
private static Comparer<IBehaviour> SortByAscendingPriority() => Comparer<IBehaviour>.Create((x, y) => x.Priority.CompareTo(y.Priority));
|
private static Comparer<IBehaviour> SortByAscendingPriority() => Comparer<IBehaviour>.Create((x, y) => x.Priority.CompareTo(y.Priority));
|
||||||
@ -14,7 +14,7 @@ public class UpdateManager : UniverseObject
|
|||||||
|
|
||||||
private readonly List<IFirstFrameUpdate> toCallFirstFrameUpdates = new(32);
|
private readonly List<IFirstFrameUpdate> toCallFirstFrameUpdates = new(32);
|
||||||
|
|
||||||
protected override void OnEnteringUniverse(IUniverse universe)
|
protected override void OnEnteredUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
firstFrameUpdates.Assign(universe);
|
firstFrameUpdates.Assign(universe);
|
||||||
preUpdateEntities.Assign(universe);
|
preUpdateEntities.Assign(universe);
|
||||||
@ -26,7 +26,7 @@ public class UpdateManager : UniverseObject
|
|||||||
universe.OnPostUpdate.AddListener(OnPostUpdate);
|
universe.OnPostUpdate.AddListener(OnPostUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExitingUniverse(IUniverse universe)
|
protected override void OnExitedUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
firstFrameUpdates.Unassign();
|
firstFrameUpdates.Unassign();
|
||||||
preUpdateEntities.Unassign();
|
preUpdateEntities.Unassign();
|
||||||
|
@ -5,7 +5,7 @@ using Syntriax.Engine.Core;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Physics2D;
|
namespace Syntriax.Engine.Physics2D;
|
||||||
|
|
||||||
public class PhysicsCoroutineManager : UniverseObject
|
public class PhysicsCoroutineManager : Behaviour
|
||||||
{
|
{
|
||||||
private readonly Event<IUniverse, IUniverse.UpdateArguments>.EventHandler delegateOnUpdate = null!;
|
private readonly Event<IUniverse, IUniverse.UpdateArguments>.EventHandler delegateOnUpdate = null!;
|
||||||
|
|
||||||
@ -23,9 +23,9 @@ public class PhysicsCoroutineManager : UniverseObject
|
|||||||
enumerators.Remove(enumerator);
|
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)
|
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
||||||
foundPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
foundPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
||||||
else
|
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)
|
if (physicsEngine is IPhysicsEngine2D existingPhysicsEngine)
|
||||||
existingPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
existingPhysicsEngine.OnPhysicsStep.RemoveListener(OnPhysicsStep);
|
||||||
universe.OnUpdate.RemoveListener(OnUpdate);
|
universe.OnUpdate.RemoveListener(delegateOnUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUpdate(IUniverse sender, IUniverse.UpdateArguments args)
|
private void OnUpdate(IUniverse sender, IUniverse.UpdateArguments args)
|
||||||
@ -56,11 +56,11 @@ public class PhysicsCoroutineManager : UniverseObject
|
|||||||
if (Universe is not IUniverse universe)
|
if (Universe is not IUniverse universe)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
physicsEngine = universe.GetUniverseObject<IPhysicsEngine2D>();
|
physicsEngine = universe.FindRequiredBehaviour<IPhysicsEngine2D>();
|
||||||
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
if (physicsEngine is IPhysicsEngine2D foundPhysicsEngine)
|
||||||
{
|
{
|
||||||
foundPhysicsEngine.OnPhysicsStep.AddListener(OnPhysicsStep);
|
foundPhysicsEngine.OnPhysicsStep.AddListener(OnPhysicsStep);
|
||||||
universe.OnUpdate.RemoveListener(OnUpdate);
|
universe.OnUpdate.RemoveListener(delegateOnUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ using Syntriax.Engine.Core;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Physics2D;
|
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> OnPhysicsIteration { get; } = new();
|
||||||
public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new();
|
public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new();
|
||||||
@ -174,7 +174,7 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
|
|||||||
rigidBody.Transform.Rotation += rigidBody.AngularVelocity * intervalDeltaTime;
|
rigidBody.Transform.Rotation += rigidBody.AngularVelocity * intervalDeltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnEnteringUniverse(IUniverse universe)
|
protected override void OnEnteredUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
physicsPreUpdateCollector.Assign(universe);
|
physicsPreUpdateCollector.Assign(universe);
|
||||||
physicsUpdateCollector.Assign(universe);
|
physicsUpdateCollector.Assign(universe);
|
||||||
@ -185,7 +185,7 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
|
|||||||
universe.OnPreUpdate.AddListener(OnEnginePreUpdate);
|
universe.OnPreUpdate.AddListener(OnEnginePreUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExitingUniverse(IUniverse universe)
|
protected override void OnExitedUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
physicsPreUpdateCollector.Unassign();
|
physicsPreUpdateCollector.Unassign();
|
||||||
physicsUpdateCollector.Unassign();
|
physicsUpdateCollector.Unassign();
|
||||||
|
@ -5,7 +5,7 @@ using Syntriax.Engine.Core;
|
|||||||
|
|
||||||
namespace Syntriax.Engine.Systems.Tween;
|
namespace Syntriax.Engine.Systems.Tween;
|
||||||
|
|
||||||
public class TweenManager : UniverseObject, ITweenManager
|
public class TweenManager : Behaviour, ITweenManager
|
||||||
{
|
{
|
||||||
private CoroutineManager coroutineManager = null!;
|
private CoroutineManager coroutineManager = null!;
|
||||||
|
|
||||||
@ -73,12 +73,12 @@ public class TweenManager : UniverseObject, ITweenManager
|
|||||||
Return((Tween)tween);
|
Return((Tween)tween);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnEnteringUniverse(IUniverse universe)
|
protected override void OnEnteredUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
coroutineManager = universe.GetRequiredUniverseObject<CoroutineManager>();
|
coroutineManager = universe.FindRequiredBehaviour<CoroutineManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnExitingUniverse(IUniverse universe)
|
protected override void OnExitedUniverse(IUniverse universe)
|
||||||
{
|
{
|
||||||
coroutineManager = null!;
|
coroutineManager = null!;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user