refactor: moved drawable triangles into systems project for platform agnosticism
This commit is contained in:
33
Engine.Systems/Graphics/TriangleBatcher.cs
Normal file
33
Engine.Systems/Graphics/TriangleBatcher.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Graphics;
|
||||
|
||||
public class TriangleBatcher : Behaviour, 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 ITriangleBatch triangleBatch = null!;
|
||||
private ICamera camera = null!;
|
||||
|
||||
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
||||
|
||||
public void FirstActiveFrame()
|
||||
{
|
||||
camera = Universe.FindRequiredBehaviour<ICamera>();
|
||||
|
||||
triangleBatch = Universe.FindRequiredBehaviour<ITriangleBatch>();
|
||||
drawableShapes.Unassign();
|
||||
drawableShapes.Assign(Universe);
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
triangleBatch.Begin(camera.ViewMatrix, camera.ProjectionMatrix);
|
||||
for (int i = 0; i < drawableShapes.Count; i++)
|
||||
drawableShapes[i].Draw(triangleBatch);
|
||||
triangleBatch.End();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user