diff --git a/Engine.Core/Systems/DrawManager.cs b/Engine.Core/Systems/DrawManager.cs index 0bcc78d..64c320a 100644 --- a/Engine.Core/Systems/DrawManager.cs +++ b/Engine.Core/Systems/DrawManager.cs @@ -4,11 +4,12 @@ namespace Syntriax.Engine.Core; public class DrawManager : UniverseObject { - private static Comparer SortByAscendingPriority() => Comparer.Create((x, y) => x.Priority.CompareTo(y.Priority)); + // We use Descending order because draw calls are running from last to first + private static Comparer SortByDescendingPriority() => Comparer.Create((x, y) => y.Priority.CompareTo(x.Priority)); - private readonly ActiveBehaviourCollectorSorted preDrawEntities = new() { SortBy = SortByAscendingPriority() }; - private readonly ActiveBehaviourCollectorSorted drawEntities = new() { SortBy = SortByAscendingPriority() }; - private readonly ActiveBehaviourCollectorSorted postDrawEntities = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorSorted preDrawEntities = new() { SortBy = SortByDescendingPriority() }; + private readonly ActiveBehaviourCollectorSorted drawEntities = new() { SortBy = SortByDescendingPriority() }; + private readonly ActiveBehaviourCollectorSorted postDrawEntities = new() { SortBy = SortByDescendingPriority() }; private void OnPreDraw(IUniverse sender) { diff --git a/Engine.Core/Systems/UpdateManager.cs b/Engine.Core/Systems/UpdateManager.cs index 80204e7..87bf73b 100644 --- a/Engine.Core/Systems/UpdateManager.cs +++ b/Engine.Core/Systems/UpdateManager.cs @@ -4,12 +4,13 @@ namespace Syntriax.Engine.Core; public class UpdateManager : UniverseObject { - private static Comparer SortByDescendingPriority() => Comparer.Create((x, y) => y.Priority.CompareTo(x.Priority)); + // We use Ascending order because draw calls are running from last to first + private static Comparer SortByAscendingPriority() => Comparer.Create((x, y) => x.Priority.CompareTo(y.Priority)); - private readonly ActiveBehaviourCollectorSorted firstFrameUpdates = new() { SortBy = SortByDescendingPriority() }; - private readonly ActiveBehaviourCollectorSorted preUpdateEntities = new() { SortBy = SortByDescendingPriority() }; - private readonly ActiveBehaviourCollectorSorted updateEntities = new() { SortBy = SortByDescendingPriority() }; - private readonly ActiveBehaviourCollectorSorted postUpdateEntities = new() { SortBy = SortByDescendingPriority() }; + private readonly ActiveBehaviourCollectorSorted firstFrameUpdates = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorSorted preUpdateEntities = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorSorted updateEntities = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorSorted postUpdateEntities = new() { SortBy = SortByAscendingPriority() }; private readonly List toCallFirstFrameUpdates = new(32);