refactor: update & draw calls have been refactored into systems
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user