encompass-cs/test/WorldTest.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2019-06-20 03:37:46 +00:00
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 { }
2019-06-20 03:37:46 +00:00
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)
2019-06-20 03:37:46 +00:00
{
drawOrder.Clear();
2019-06-20 03:37:46 +00:00
var worldBuilder = new WorldBuilder();
worldBuilder.AddEntityRenderer(new TestEntityRenderer());
var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
2019-06-20 03:37:46 +00:00
TestComponent testComponent;
TestDrawComponent testDrawComponent = default(TestDrawComponent);
var entity = worldBuilder.CreateEntity();
2019-07-17 18:24:21 +00:00
worldBuilder.AddComponent(entity, testComponent);
worldBuilder.AddDrawComponent(entity, testDrawComponent, 3);
2019-06-20 03:37:46 +00:00
TestDrawComponent testDrawComponentTwo = default(TestDrawComponent);
var entityTwo = worldBuilder.CreateEntity();
2019-07-17 18:24:21 +00:00
worldBuilder.AddComponent(entityTwo, testComponent);
worldBuilder.AddDrawComponent(entityTwo, testDrawComponentTwo, 1);
2019-06-20 03:37:46 +00:00
TestDrawComponent testDrawComponentThree = default(TestDrawComponent);
var entityThree = worldBuilder.CreateEntity();
2019-07-17 18:24:21 +00:00
worldBuilder.AddComponent(entityThree, testComponent);
worldBuilder.AddDrawComponent(entityThree, testDrawComponentThree, 5);
2019-06-20 03:37:46 +00:00
TestDrawComponent testDrawComponentFour = default(TestDrawComponent);
var entityFour = worldBuilder.CreateEntity();
2019-07-17 18:24:21 +00:00
worldBuilder.AddComponent(entityFour, testComponent);
worldBuilder.AddDrawComponent(entityFour, testDrawComponentFour, -5);
2019-06-20 03:37:46 +00:00
var world = worldBuilder.Build();
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
2019-06-20 03:37:46 +00:00
world.Draw();
drawOrder.Should().BeEquivalentTo(entityFour, entityTwo, entity, entityThree, testGeneralRenderer);
}
}
}