76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
using NUnit.Framework;
|
|
using FluentAssertions;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
using Encompass;
|
|
|
|
namespace Tests
|
|
{
|
|
public class WorldTest
|
|
{
|
|
struct TestComponent : IComponent { }
|
|
struct TestDrawComponent : IComponent, IDrawComponent { }
|
|
|
|
static List<object> drawOrder = new List<object>();
|
|
|
|
class TestEntityRenderer : OrderedRenderer<TestDrawComponent>
|
|
{
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent)
|
|
{
|
|
drawOrder.Add(drawComponentID);
|
|
}
|
|
}
|
|
|
|
class TestGeneralRenderer : GeneralRenderer
|
|
{
|
|
public override void Render()
|
|
{
|
|
drawOrder.Add(this);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void DrawOrder()
|
|
{
|
|
var worldBuilder = new WorldBuilder();
|
|
worldBuilder.AddOrderedRenderer(new TestEntityRenderer());
|
|
var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
|
|
|
|
TestComponent testComponent;
|
|
TestDrawComponent testDrawComponent = default(TestDrawComponent);
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
worldBuilder.SetComponent(entity, testComponent);
|
|
var testDrawComponentOneID = worldBuilder.SetDrawComponent(entity, testDrawComponent, 3);
|
|
|
|
TestDrawComponent testDrawComponentTwo = default(TestDrawComponent);
|
|
|
|
var entityTwo = worldBuilder.CreateEntity();
|
|
worldBuilder.SetComponent(entityTwo, testComponent);
|
|
var testDrawComponentTwoID = worldBuilder.SetDrawComponent(entityTwo, testDrawComponentTwo, 1);
|
|
|
|
TestDrawComponent testDrawComponentThree = default(TestDrawComponent);
|
|
|
|
var entityThree = worldBuilder.CreateEntity();
|
|
worldBuilder.SetComponent(entityThree, testComponent);
|
|
var testDrawComponentThreeID = worldBuilder.SetDrawComponent(entityThree, testDrawComponentThree, 5);
|
|
|
|
TestDrawComponent testDrawComponentFour = default(TestDrawComponent);
|
|
|
|
var entityFour = worldBuilder.CreateEntity();
|
|
worldBuilder.SetComponent(entityFour, testComponent);
|
|
var testDrawComponentFourID = worldBuilder.SetDrawComponent(entityFour, testDrawComponentFour, -5);
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
world.Update(0.01f);
|
|
world.Draw();
|
|
|
|
drawOrder.Should().BeEquivalentTo(testDrawComponentFourID, testDrawComponentTwoID, testDrawComponentOneID, testDrawComponentThreeID, testGeneralRenderer);
|
|
}
|
|
}
|
|
}
|