refactor: removed parameters on triangle batch calls on TriangleBatcher for multi window support
This commit is contained in:
@@ -19,8 +19,11 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat
|
|||||||
private BasicEffect basicEffect = null!;
|
private BasicEffect basicEffect = null!;
|
||||||
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None };
|
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None };
|
||||||
|
|
||||||
|
private ICamera camera = null!;
|
||||||
|
|
||||||
public void FirstActiveFrame()
|
public void FirstActiveFrame()
|
||||||
{
|
{
|
||||||
|
camera = Universe.FindRequiredBehaviour<ICamera>();
|
||||||
GraphicsDevice graphicsDevice = Universe.FindRequiredBehaviour<MonoGameWindowContainer>().Window.GraphicsDevice;
|
GraphicsDevice graphicsDevice = Universe.FindRequiredBehaviour<MonoGameWindowContainer>().Window.GraphicsDevice;
|
||||||
this.graphicsDevice = graphicsDevice;
|
this.graphicsDevice = graphicsDevice;
|
||||||
basicEffect = new(graphicsDevice);
|
basicEffect = new(graphicsDevice);
|
||||||
@@ -47,8 +50,8 @@ public class MonoGameTriangleBatch : Behaviour, ITriangleBatch, IFirstFrameUpdat
|
|||||||
{
|
{
|
||||||
Viewport viewport = graphicsDevice.Viewport;
|
Viewport viewport = graphicsDevice.Viewport;
|
||||||
|
|
||||||
this.view = (view ?? Matrix4x4.Identity).Transposed.ToXnaMatrix();
|
this.view = (view ?? camera.ViewMatrix).Transposed.ToXnaMatrix();
|
||||||
this.projection = (projection ?? Matrix4x4.CreateOrthographicViewCentered(viewport.Width, viewport.Height)).Transposed.ToXnaMatrix();
|
this.projection = (projection ?? camera.ProjectionMatrix).Transposed.ToXnaMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void End() => Flush();
|
public void End() => Flush();
|
||||||
|
|||||||
@@ -10,14 +10,10 @@ public class TriangleBatcher : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, I
|
|||||||
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
private static System.Func<IBehaviour, int> GetPriority() => (b) => b.Priority;
|
||||||
|
|
||||||
private readonly BehaviourCollector<ITriangleBatch> triangleBatches = new();
|
private readonly BehaviourCollector<ITriangleBatch> triangleBatches = new();
|
||||||
private ICamera camera = null!;
|
|
||||||
|
|
||||||
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableTriangle> drawableShapes = new(GetPriority(), SortByAscendingPriority());
|
||||||
|
|
||||||
public void FirstActiveFrame()
|
public void FirstActiveFrame()
|
||||||
{
|
{
|
||||||
camera = Universe.FindRequiredBehaviour<ICamera>();
|
|
||||||
|
|
||||||
drawableShapes.Assign(Universe);
|
drawableShapes.Assign(Universe);
|
||||||
triangleBatches.Assign(Universe);
|
triangleBatches.Assign(Universe);
|
||||||
}
|
}
|
||||||
@@ -27,7 +23,7 @@ public class TriangleBatcher : Behaviour, IFirstFrameUpdate, ILastFrameUpdate, I
|
|||||||
for (int i = 0; i < triangleBatches.Count; i++)
|
for (int i = 0; i < triangleBatches.Count; i++)
|
||||||
{
|
{
|
||||||
ITriangleBatch triangleBatch = triangleBatches[i];
|
ITriangleBatch triangleBatch = triangleBatches[i];
|
||||||
triangleBatch.Begin(camera.ViewMatrix, camera.ProjectionMatrix);
|
triangleBatch.Begin();
|
||||||
for (int j = 0; j < drawableShapes.Count; j++)
|
for (int j = 0; j < drawableShapes.Count; j++)
|
||||||
drawableShapes[j].Draw(triangleBatch);
|
drawableShapes[j].Draw(triangleBatch);
|
||||||
triangleBatch.End();
|
triangleBatch.End();
|
||||||
|
|||||||
Reference in New Issue
Block a user