refactor: moved drawable triangles into systems project for platform agnosticism
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class DrawableShape : Behaviour2D, IDrawableTriangle, IPreDraw
|
||||
{
|
||||
private readonly Shape2D shape = new([]);
|
||||
private readonly List<Triangle> worldTriangles = [];
|
||||
private readonly Shape2D worldShape = new([]);
|
||||
protected ColorRGB color = new(255, 255, 255);
|
||||
|
||||
public void PreDraw() => UpdateWorldShape();
|
||||
|
||||
public void Draw(ITriangleBatch triangleBatch)
|
||||
{
|
||||
worldShape.ToTrianglesConvex(worldTriangles);
|
||||
|
||||
foreach (Triangle triangle in worldTriangles)
|
||||
triangleBatch.Draw(new(triangle.C, triangle.B, triangle.A), color);
|
||||
}
|
||||
|
||||
protected void UpdateWorldShape() => shape.Transform(Transform, worldShape);
|
||||
|
||||
public DrawableShape() => shape = Shape2D.Triangle;
|
||||
public DrawableShape(Shape2D shape) => this.shape = shape;
|
||||
public DrawableShape(Shape2D shape, ColorRGB color) { this.shape = shape; this.color = color; }
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class SpriteBatcher : Behaviour, IFirstFrameUpdate, IDraw
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
spriteBatch.Begin(transformMatrix: camera2D.MatrixTransform);
|
||||
spriteBatch.Begin(transformMatrix: camera2D.ViewMatrix.ToXnaMatrix());
|
||||
for (int i = 0; i < drawableSprites.Count; i++)
|
||||
drawableSprites[i].Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Integration.MonoGame;
|
||||
|
||||
public class TriangleBatcher : Behaviour, ITriangleBatch, IFirstFrameUpdate, IDraw
|
||||
{
|
||||
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<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
MonoGameWindowContainer windowContainer = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour<MonoGameWindowContainer>();
|
||||
camera2D = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour<MonoGameCamera2D>();
|
||||
|
||||
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