encompass-cs/test/WorldTest.cs

88 lines
2.7 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 { }
static List<object> drawOrder = new List<object>();
[Renders(typeof(TestDrawComponent), typeof(TestComponent))]
class TestEntityRenderer : EntityRenderer
{
public override void Render(Entity entity)
{
drawOrder.Add(entity);
}
}
class TestGeneralRenderer : GeneralRenderer
{
public override void Render()
{
drawOrder.Add(this);
}
}
[TestCase(true)]
[TestCase(false)]
public void DrawOrder(bool parallelUpdate)
{
drawOrder.Clear();
var worldBuilder = new WorldBuilder();
worldBuilder.AddEntityRenderer(new TestEntityRenderer());
var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
TestComponent testComponent;
TestDrawComponent testDrawComponent = default(TestDrawComponent);
var entity = worldBuilder.CreateEntity();
worldBuilder.AddComponent(entity, testComponent);
worldBuilder.AddDrawComponent(entity, testDrawComponent, 3);
TestDrawComponent testDrawComponentTwo = default(TestDrawComponent);
var entityTwo = worldBuilder.CreateEntity();
worldBuilder.AddComponent(entityTwo, testComponent);
worldBuilder.AddDrawComponent(entityTwo, testDrawComponentTwo, 1);
TestDrawComponent testDrawComponentThree = default(TestDrawComponent);
var entityThree = worldBuilder.CreateEntity();
worldBuilder.AddComponent(entityThree, testComponent);
worldBuilder.AddDrawComponent(entityThree, testDrawComponentThree, 5);
TestDrawComponent testDrawComponentFour = default(TestDrawComponent);
var entityFour = worldBuilder.CreateEntity();
worldBuilder.AddComponent(entityFour, testComponent);
worldBuilder.AddDrawComponent(entityFour, testDrawComponentFour, -5);
var world = worldBuilder.Build();
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
world.Draw();
drawOrder.Should().BeEquivalentTo(entityFour, entityTwo, entity, entityThree, testGeneralRenderer);
}
}
}