using System.Collections.Generic; using Apos.Shapes; using Syntriax.Engine.Core; using Syntriax.Engine.Integration.MonoGame; namespace Pong.Behaviours; public class ShapeBatcher : BehaviourBase, IFirstFrameUpdate, IDraw { private static Comparer SortByPriority() => Comparer.Create((x, y) => y.Priority.CompareTo(x.Priority)); private ShapeBatch shapeBatch = null!; private MonoGameCamera2DBehaviour camera2D = null!; private readonly ActiveBehaviourCollectorSorted drawableShapes = new() { SortBy = SortByPriority() }; public void FirstActiveFrame() { MonoGameWindowContainer windowContainer = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour(); camera2D = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour(); shapeBatch = new(windowContainer.Window.GraphicsDevice, windowContainer.Window.Content); drawableShapes.Unassign(); drawableShapes.Assign(Universe); } public void Draw() { shapeBatch.Begin(camera2D.MatrixTransform); for (int i = drawableShapes.Count - 1; i >= 0; i--) drawableShapes[i].Draw(shapeBatch); shapeBatch.End(); } }