feat: basic MonoGame integration implementations added
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.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 TriangleBatch triangleBatch = null!;
|
||||
private MonoGameCamera2DBehaviour camera2D = null!;
|
||||
private readonly ActiveBehaviourCollectorSorted<IDrawableTriangle> drawableShapes = new() { SortBy = SortByAscendingPriority() };
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
MonoGameWindowContainer windowContainer = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour<MonoGameWindowContainer>();
|
||||
camera2D = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour<MonoGameCamera2DBehaviour>();
|
||||
|
||||
triangleBatch = new(windowContainer.Window.GraphicsDevice);
|
||||
drawableShapes.Unassign();
|
||||
drawableShapes.Assign(BehaviourController.UniverseObject.Universe);
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
triangleBatch.Begin(camera2D.MatrixTransform);
|
||||
for (int i = 0; i < drawableShapes.Count; i++)
|
||||
drawableShapes[i].Draw(triangleBatch);
|
||||
triangleBatch.End();
|
||||
}
|
||||
|
||||
public void Begin(Matrix? view = null, Matrix? projection = null) => triangleBatch.Begin(view, projection);
|
||||
public void Draw(Triangle triangle, ColorRGBA colorRGBA) => triangleBatch.Draw(triangle, colorRGBA);
|
||||
public void End() => triangleBatch.End();
|
||||
}
|
Reference in New Issue
Block a user