refactor: update & draw calls have been refactored into systems
This commit is contained in:
6
Engine.Core/Systems/Abstract/IDraw.cs
Normal file
6
Engine.Core/Systems/Abstract/IDraw.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IDraw : IBehaviour
|
||||
{
|
||||
void Draw();
|
||||
}
|
6
Engine.Core/Systems/Abstract/IFirstFrameUpdate.cs
Normal file
6
Engine.Core/Systems/Abstract/IFirstFrameUpdate.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IFirstFrameUpdate : IBehaviour
|
||||
{
|
||||
void FirstActiveFrame();
|
||||
}
|
6
Engine.Core/Systems/Abstract/IPostDraw.cs
Normal file
6
Engine.Core/Systems/Abstract/IPostDraw.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IPostDraw : IBehaviour
|
||||
{
|
||||
void PostDraw();
|
||||
}
|
6
Engine.Core/Systems/Abstract/IPostUpdate.cs
Normal file
6
Engine.Core/Systems/Abstract/IPostUpdate.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IPostUpdate : IBehaviour
|
||||
{
|
||||
void PostUpdate();
|
||||
}
|
6
Engine.Core/Systems/Abstract/IPreDraw.cs
Normal file
6
Engine.Core/Systems/Abstract/IPreDraw.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IPreDraw : IBehaviour
|
||||
{
|
||||
void PreDraw();
|
||||
}
|
6
Engine.Core/Systems/Abstract/IPreUpdate.cs
Normal file
6
Engine.Core/Systems/Abstract/IPreUpdate.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IPreUpdate : IBehaviour
|
||||
{
|
||||
void PreUpdate();
|
||||
}
|
6
Engine.Core/Systems/Abstract/IUpdate.cs
Normal file
6
Engine.Core/Systems/Abstract/IUpdate.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public interface IUpdate : IBehaviour
|
||||
{
|
||||
void Update();
|
||||
}
|
49
Engine.Core/Systems/DrawManager.cs
Normal file
49
Engine.Core/Systems/DrawManager.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public class DrawManager : UniverseObject
|
||||
{
|
||||
private readonly BehaviourCollector<IPreDraw> preDrawEntities = new();
|
||||
private readonly BehaviourCollector<IDraw> drawEntities = new();
|
||||
private readonly BehaviourCollector<IPostDraw> postDrawEntities = new();
|
||||
|
||||
private void OnPreDraw(IUniverse sender)
|
||||
{
|
||||
for (int i = preDrawEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
preDrawEntities.Behaviours[i].PreDraw();
|
||||
}
|
||||
|
||||
private void OnDraw(IUniverse sender)
|
||||
{
|
||||
for (int i = drawEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
drawEntities.Behaviours[i].Draw();
|
||||
}
|
||||
|
||||
private void OnPostDraw(IUniverse sender)
|
||||
{
|
||||
for (int i = postDrawEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
postDrawEntities.Behaviours[i].PostDraw();
|
||||
}
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
{
|
||||
preDrawEntities.Assign(universe);
|
||||
drawEntities.Assign(universe);
|
||||
postDrawEntities.Assign(universe);
|
||||
|
||||
universe.OnPreDraw += OnPreDraw;
|
||||
universe.OnDraw += OnDraw;
|
||||
universe.OnPostDraw += OnPostDraw;
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
{
|
||||
preDrawEntities.Unassign();
|
||||
drawEntities.Unassign();
|
||||
postDrawEntities.Unassign();
|
||||
|
||||
universe.OnPreDraw -= OnPreDraw;
|
||||
universe.OnDraw -= OnDraw;
|
||||
universe.OnPostDraw -= OnPostDraw;
|
||||
}
|
||||
}
|
69
Engine.Core/Systems/UpdateManager.cs
Normal file
69
Engine.Core/Systems/UpdateManager.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public class UpdateManager : UniverseObject
|
||||
{
|
||||
private readonly BehaviourCollector<IFirstFrameUpdate> firstFrameUpdates = new();
|
||||
private readonly BehaviourCollector<IPreUpdate> preUpdateEntities = new();
|
||||
private readonly BehaviourCollector<IUpdate> updateEntities = new();
|
||||
private readonly BehaviourCollector<IPostUpdate> postUpdateEntities = new();
|
||||
|
||||
private readonly List<IFirstFrameUpdate> toCallFirstFrameUpdates = [];
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
{
|
||||
firstFrameUpdates.Assign(universe);
|
||||
preUpdateEntities.Assign(universe);
|
||||
updateEntities.Assign(universe);
|
||||
postUpdateEntities.Assign(universe);
|
||||
|
||||
universe.OnPreUpdate += OnPreUpdate;
|
||||
universe.OnUpdate += OnUpdate;
|
||||
universe.OnPostUpdate += OnPostUpdate;
|
||||
}
|
||||
|
||||
protected override void OnExitingUniverse(IUniverse universe)
|
||||
{
|
||||
firstFrameUpdates.Unassign();
|
||||
preUpdateEntities.Unassign();
|
||||
updateEntities.Unassign();
|
||||
postUpdateEntities.Unassign();
|
||||
|
||||
universe.OnPreUpdate -= OnPreUpdate;
|
||||
universe.OnUpdate -= OnUpdate;
|
||||
universe.OnPostUpdate -= OnPostUpdate;
|
||||
}
|
||||
|
||||
private void OnPreUpdate(IUniverse sender, UniverseTime engineTime)
|
||||
{
|
||||
for (int i = toCallFirstFrameUpdates.Count - 1; i >= 0; i--)
|
||||
toCallFirstFrameUpdates[i].FirstActiveFrame();
|
||||
|
||||
for (int i = preUpdateEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
preUpdateEntities.Behaviours[i].PreUpdate();
|
||||
}
|
||||
|
||||
private void OnUpdate(IUniverse sender, UniverseTime engineTime)
|
||||
{
|
||||
for (int i = updateEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
updateEntities.Behaviours[i].Update();
|
||||
}
|
||||
|
||||
private void OnPostUpdate(IUniverse sender, UniverseTime engineTime)
|
||||
{
|
||||
for (int i = postUpdateEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
postUpdateEntities.Behaviours[i].PostUpdate();
|
||||
}
|
||||
|
||||
private void OnFirstFrameCollected(IBehaviourCollector<IFirstFrameUpdate> sender, IFirstFrameUpdate behaviourCollected)
|
||||
{
|
||||
toCallFirstFrameUpdates.Add(behaviourCollected);
|
||||
}
|
||||
|
||||
public UpdateManager()
|
||||
{
|
||||
firstFrameUpdates.OnCollected += OnFirstFrameCollected;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user