From e3d4899112716ba476fa66e0dbc78c9f923d5e3e Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 11 Oct 2025 16:00:47 +0300 Subject: [PATCH] refactor: renamed behaviour collectors from sorted to ordered --- ...orSorted.cs => ActiveBehaviourCollectorOrdered.cs} | 11 +++-------- ...ollectorSorted.cs => BehaviourCollectorOrdered.cs} | 11 +++-------- Engine.Core/Systems/DrawManager.cs | 6 +++--- Engine.Core/Systems/UniverseEntranceManager.cs | 4 ++-- Engine.Core/Systems/UpdateManager.cs | 8 ++++---- .../Behaviours/LoadContentManager.cs | 2 +- .../Behaviours/SpriteBatcher.cs | 2 +- .../Behaviours/TriangleBatcher.cs | 2 +- Engine.Physics2D/PhysicsEngine2D.cs | 8 ++++---- 9 files changed, 22 insertions(+), 32 deletions(-) rename Engine.Core/Collectors/{ActiveBehaviourCollectorSorted.cs => ActiveBehaviourCollectorOrdered.cs} (82%) rename Engine.Core/Collectors/{BehaviourCollectorSorted.cs => BehaviourCollectorOrdered.cs} (83%) diff --git a/Engine.Core/Collectors/ActiveBehaviourCollectorSorted.cs b/Engine.Core/Collectors/ActiveBehaviourCollectorOrdered.cs similarity index 82% rename from Engine.Core/Collectors/ActiveBehaviourCollectorSorted.cs rename to Engine.Core/Collectors/ActiveBehaviourCollectorOrdered.cs index 7db7945..5c20423 100644 --- a/Engine.Core/Collectors/ActiveBehaviourCollectorSorted.cs +++ b/Engine.Core/Collectors/ActiveBehaviourCollectorOrdered.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Engine.Core; -public class ActiveBehaviourCollectorSorted : ActiveBehaviourCollector where T : class, IBehaviour +public class ActiveBehaviourCollectorOrdered : ActiveBehaviourCollector where T : class, IBehaviour { private readonly Event.EventHandler delegateOnPriorityChanged = null!; @@ -53,15 +53,10 @@ public class ActiveBehaviourCollectorSorted : ActiveBehaviourCollector whe AddBehaviour(behaviour); } - public ActiveBehaviourCollectorSorted() + public ActiveBehaviourCollectorOrdered() => delegateOnPriorityChanged = OnPriorityChanged; + public ActiveBehaviourCollectorOrdered(IUniverse universe, Comparison sortBy) : base(universe) { delegateOnPriorityChanged = OnPriorityChanged; - } - - public ActiveBehaviourCollectorSorted(IUniverse universe, Comparison sortBy) : base(universe) - { - delegateOnPriorityChanged = OnPriorityChanged; - SortBy = Comparer.Create(sortBy); } } diff --git a/Engine.Core/Collectors/BehaviourCollectorSorted.cs b/Engine.Core/Collectors/BehaviourCollectorOrdered.cs similarity index 83% rename from Engine.Core/Collectors/BehaviourCollectorSorted.cs rename to Engine.Core/Collectors/BehaviourCollectorOrdered.cs index 811bb63..bbf445b 100644 --- a/Engine.Core/Collectors/BehaviourCollectorSorted.cs +++ b/Engine.Core/Collectors/BehaviourCollectorOrdered.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Engine.Core; -public class BehaviourCollectorSorted : BehaviourCollector where T : class +public class BehaviourCollectorOrdered : BehaviourCollector where T : class { private readonly Event.EventHandler delegateOnPriorityChanged = null!; @@ -53,15 +53,10 @@ public class BehaviourCollectorSorted : BehaviourCollector where T : class AddBehaviour(behaviour); } - public BehaviourCollectorSorted() + public BehaviourCollectorOrdered() => delegateOnPriorityChanged = OnPriorityChanged; + public BehaviourCollectorOrdered(IUniverse universe, Comparison sortBy) : base(universe) { delegateOnPriorityChanged = OnPriorityChanged; - } - - public BehaviourCollectorSorted(IUniverse universe, Comparison sortBy) : base(universe) - { - delegateOnPriorityChanged = OnPriorityChanged; - SortBy = Comparer.Create(sortBy); } } diff --git a/Engine.Core/Systems/DrawManager.cs b/Engine.Core/Systems/DrawManager.cs index b385c68..719147c 100644 --- a/Engine.Core/Systems/DrawManager.cs +++ b/Engine.Core/Systems/DrawManager.cs @@ -7,9 +7,9 @@ public class DrawManager : Behaviour // 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 = SortByDescendingPriority() }; - private readonly ActiveBehaviourCollectorSorted drawEntities = new() { SortBy = SortByDescendingPriority() }; - private readonly ActiveBehaviourCollectorSorted postDrawEntities = new() { SortBy = SortByDescendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered preDrawEntities = new() { SortBy = SortByDescendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered drawEntities = new() { SortBy = SortByDescendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered postDrawEntities = new() { SortBy = SortByDescendingPriority() }; private void OnPreDraw(IUniverse sender) { diff --git a/Engine.Core/Systems/UniverseEntranceManager.cs b/Engine.Core/Systems/UniverseEntranceManager.cs index 0f32115..a421913 100644 --- a/Engine.Core/Systems/UniverseEntranceManager.cs +++ b/Engine.Core/Systems/UniverseEntranceManager.cs @@ -7,8 +7,8 @@ public class UniverseEntranceManager : Behaviour // We use Ascending order because we are using reverse for loop to call them private static Comparer SortByAscendingPriority() => Comparer.Create((x, y) => x.Priority.CompareTo(y.Priority)); - private readonly ActiveBehaviourCollectorSorted enterUniverses = new() { SortBy = SortByAscendingPriority() }; - private readonly ActiveBehaviourCollectorSorted exitUniverses = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered enterUniverses = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered exitUniverses = new() { SortBy = SortByAscendingPriority() }; private readonly List toCallEnterUniverses = new(32); private readonly List toCallExitUniverses = new(32); diff --git a/Engine.Core/Systems/UpdateManager.cs b/Engine.Core/Systems/UpdateManager.cs index 1ee0257..3712c26 100644 --- a/Engine.Core/Systems/UpdateManager.cs +++ b/Engine.Core/Systems/UpdateManager.cs @@ -8,11 +8,11 @@ public class UpdateManager : Behaviour // We use Ascending order because we are using reverse for loop to call them private static Comparer SortByAscendingPriority() => Comparer.Create((x, y) => x.Priority.CompareTo(y.Priority)); - private readonly ActiveBehaviourCollectorSorted firstFrameUpdates = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered firstFrameUpdates = new() { SortBy = SortByAscendingPriority() }; private readonly ActiveBehaviourCollector lastFrameUpdates = new(); - private readonly ActiveBehaviourCollectorSorted preUpdateEntities = new() { SortBy = SortByAscendingPriority() }; - private readonly ActiveBehaviourCollectorSorted updateEntities = new() { SortBy = SortByAscendingPriority() }; - private readonly ActiveBehaviourCollectorSorted postUpdateEntities = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered preUpdateEntities = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered updateEntities = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered postUpdateEntities = new() { SortBy = SortByAscendingPriority() }; private readonly List toCallFirstFrameUpdates = new(32); diff --git a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/LoadContentManager.cs b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/LoadContentManager.cs index a8eec5b..4377086 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/LoadContentManager.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/LoadContentManager.cs @@ -8,7 +8,7 @@ public class LoadContentManager : Behaviour, IFirstFrameUpdate // We use Ascending order because we are using reverse for loop to call them private static Comparer SortByAscendingPriority() => Comparer.Create((x, y) => x.Priority.CompareTo(y.Priority)); - private readonly ActiveBehaviourCollectorSorted loadContents = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered loadContents = new() { SortBy = SortByAscendingPriority() }; private readonly List toCallLoadContents = new(32); private MonoGameWindowContainer monoGameWindowContainer = null!; diff --git a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatcher.cs b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatcher.cs index e2e1cd6..73b2a72 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatcher.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/SpriteBatcher.cs @@ -11,7 +11,7 @@ public class SpriteBatcher : BehaviourBase, IFirstFrameUpdate, IDraw private ISpriteBatch spriteBatch = null!; private MonoGameCamera2D camera2D = null!; - private readonly ActiveBehaviourCollectorSorted drawableSprites = new() { SortBy = SortByPriority() }; + private readonly ActiveBehaviourCollectorOrdered drawableSprites = new() { SortBy = SortByPriority() }; public void FirstActiveFrame() { diff --git a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/TriangleBatcher.cs b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/TriangleBatcher.cs index 1fafe41..666a2a6 100644 --- a/Engine.Integration/Engine.Integration.MonoGame/Behaviours/TriangleBatcher.cs +++ b/Engine.Integration/Engine.Integration.MonoGame/Behaviours/TriangleBatcher.cs @@ -12,7 +12,7 @@ public class TriangleBatcher : BehaviourBase, ITriangleBatch, IFirstFrameUpdate, private TriangleBatch triangleBatch = null!; private MonoGameCamera2D camera2D = null!; - private readonly ActiveBehaviourCollectorSorted drawableShapes = new() { SortBy = SortByAscendingPriority() }; + private readonly ActiveBehaviourCollectorOrdered drawableShapes = new() { SortBy = SortByAscendingPriority() }; public void FirstActiveFrame() { diff --git a/Engine.Physics2D/PhysicsEngine2D.cs b/Engine.Physics2D/PhysicsEngine2D.cs index 8b75a22..52c91eb 100644 --- a/Engine.Physics2D/PhysicsEngine2D.cs +++ b/Engine.Physics2D/PhysicsEngine2D.cs @@ -18,10 +18,10 @@ public class PhysicsEngine2D : Behaviour, IPreUpdate, IPhysicsEngine2D protected readonly IRaycastResolver2D raycastResolver = null!; private static Comparer SortByPriority() => Comparer.Create((x, y) => y.Priority.CompareTo(x.Priority)); - protected ActiveBehaviourCollectorSorted physicsPreUpdateCollector = new() { SortBy = SortByPriority() }; - protected ActiveBehaviourCollectorSorted physicsUpdateCollector = new() { SortBy = SortByPriority() }; - protected ActiveBehaviourCollectorSorted physicsIterationCollector = new() { SortBy = SortByPriority() }; - protected ActiveBehaviourCollectorSorted physicsPostUpdateCollector = new() { SortBy = SortByPriority() }; + protected ActiveBehaviourCollectorOrdered physicsPreUpdateCollector = new() { SortBy = SortByPriority() }; + protected ActiveBehaviourCollectorOrdered physicsUpdateCollector = new() { SortBy = SortByPriority() }; + protected ActiveBehaviourCollectorOrdered physicsIterationCollector = new() { SortBy = SortByPriority() }; + protected ActiveBehaviourCollectorOrdered physicsPostUpdateCollector = new() { SortBy = SortByPriority() }; protected BehaviourCollector rigidBodyCollector = new(); protected BehaviourCollector colliderCollector = new();