From b1970d93f919b6fcaf4f2140892e041d68f6c8fc Mon Sep 17 00:00:00 2001 From: Syntriax Date: Fri, 23 May 2025 22:39:32 +0300 Subject: [PATCH] refactor: draw & update managers to use active & sorted by priority collector --- Engine.Core/Systems/DrawManager.cs | 8 +++++--- Engine.Core/Systems/UpdateManager.cs | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Engine.Core/Systems/DrawManager.cs b/Engine.Core/Systems/DrawManager.cs index bad774c..d924f37 100644 --- a/Engine.Core/Systems/DrawManager.cs +++ b/Engine.Core/Systems/DrawManager.cs @@ -3,9 +3,11 @@ namespace Syntriax.Engine.Core; public class DrawManager : UniverseObject { - private readonly BehaviourCollector preDrawEntities = new(); - private readonly BehaviourCollector drawEntities = new(); - private readonly BehaviourCollector postDrawEntities = new(); + private static System.Comparison SortByPriority() => (x, y) => y.Priority.CompareTo(x.Priority); + + private readonly ActiveBehaviourCollectorSorted preDrawEntities = new() { SortBy = SortByPriority() }; + private readonly ActiveBehaviourCollectorSorted drawEntities = new() { SortBy = SortByPriority() }; + private readonly ActiveBehaviourCollectorSorted postDrawEntities = new() { SortBy = SortByPriority() }; private void OnPreDraw(IUniverse sender) { diff --git a/Engine.Core/Systems/UpdateManager.cs b/Engine.Core/Systems/UpdateManager.cs index a2371f5..7e27e6d 100644 --- a/Engine.Core/Systems/UpdateManager.cs +++ b/Engine.Core/Systems/UpdateManager.cs @@ -5,10 +5,12 @@ namespace Syntriax.Engine.Core; public class UpdateManager : UniverseObject { - private readonly BehaviourCollector firstFrameUpdates = new(); - private readonly BehaviourCollector preUpdateEntities = new(); - private readonly BehaviourCollector updateEntities = new(); - private readonly BehaviourCollector postUpdateEntities = new(); + private static System.Comparison SortByPriority() => (x, y) => y.Priority.CompareTo(x.Priority); + + private readonly ActiveBehaviourCollectorSorted firstFrameUpdates = new() { SortBy = SortByPriority() }; + private readonly ActiveBehaviourCollectorSorted preUpdateEntities = new() { SortBy = SortByPriority() }; + private readonly ActiveBehaviourCollectorSorted updateEntities = new() { SortBy = SortByPriority() }; + private readonly ActiveBehaviourCollectorSorted postUpdateEntities = new() { SortBy = SortByPriority() }; private readonly List toCallFirstFrameUpdates = [];