perf: significant performance optimizations on ordered behaviour collectors by using a sorted dictionary
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
@@ -6,9 +7,10 @@ namespace Engine.Integration.MonoGame;
|
||||
public class LoadContentManager : Behaviour, IFirstFrameUpdate
|
||||
{
|
||||
// We use Ascending order because we are using reverse for loop to call them
|
||||
private static Comparer<IBehaviour> SortByAscendingPriority() => Comparer<IBehaviour>.Create((x, y) => x.Priority.CompareTo(y.Priority));
|
||||
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
|
||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||
|
||||
private readonly ActiveBehaviourCollectorOrdered<ILoadContent> loadContents = new() { SortBy = SortByAscendingPriority() };
|
||||
private readonly ActiveBehaviourCollectorOrdered<int, ILoadContent> loadContents = new(GetPriority(), SortByAscendingPriority());
|
||||
private readonly List<ILoadContent> toCallLoadContents = new(32);
|
||||
|
||||
private MonoGameWindowContainer monoGameWindowContainer = null!;
|
||||
|
@@ -6,12 +6,13 @@ namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class SpriteBatcher : BehaviourBase, IFirstFrameUpdate, IDraw
|
||||
{
|
||||
private static Comparer<IBehaviour> SortByPriority() => Comparer<IBehaviour>.Create((x, y) => y.Priority.CompareTo(x.Priority));
|
||||
private static Comparer<int> SortByPriority() => Comparer<int>.Create((x, y) => y.CompareTo(x));
|
||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||
|
||||
private ISpriteBatch spriteBatch = null!;
|
||||
private MonoGameCamera2D camera2D = null!;
|
||||
|
||||
private readonly ActiveBehaviourCollectorOrdered<IDrawableSprite> drawableSprites = new() { SortBy = SortByPriority() };
|
||||
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableSprite> drawableSprites = new(GetPriority(), SortByPriority());
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
|
@@ -8,11 +8,13 @@ namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class TriangleBatcher : BehaviourBase, ITriangleBatch, IFirstFrameUpdate, IDraw
|
||||
{
|
||||
private static Comparer<IBehaviour> SortByAscendingPriority() => Comparer<IBehaviour>.Create((x, y) => x.Priority.CompareTo(y.Priority));
|
||||
private static Comparer<int> SortByAscendingPriority() => Comparer<int>.Create((x, y) => x.CompareTo(y));
|
||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||
|
||||
private TriangleBatch triangleBatch = null!;
|
||||
private MonoGameCamera2D camera2D = null!;
|
||||
private readonly ActiveBehaviourCollectorOrdered<IDrawableTriangle> drawableShapes = new() { SortBy = SortByAscendingPriority() };
|
||||
|
||||
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
|
Reference in New Issue
Block a user