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 { }
|
2019-11-21 03:16:44 +00:00
|
|
|
|
struct TestDrawComponent : IComponent, IDrawableComponent
|
|
|
|
|
{
|
|
|
|
|
public int Layer { get; set; }
|
|
|
|
|
}
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
static List<object> drawOrder = new List<object>();
|
|
|
|
|
|
2019-08-01 22:06:19 +00:00
|
|
|
|
class TestEntityRenderer : OrderedRenderer<TestDrawComponent>
|
2019-06-20 03:37:46 +00:00
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
|
public override void Render(Entity entity, TestDrawComponent testDrawComponent)
|
2019-06-20 03:37:46 +00:00
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
|
drawOrder.Add(entity);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TestGeneralRenderer : GeneralRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render()
|
|
|
|
|
{
|
|
|
|
|
drawOrder.Add(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void DrawOrder()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-12-17 02:51:45 +00:00
|
|
|
|
worldBuilder.RegisterDrawLayer(1);
|
|
|
|
|
worldBuilder.RegisterDrawLayer(2);
|
|
|
|
|
worldBuilder.RegisterDrawLayer(3);
|
|
|
|
|
worldBuilder.RegisterDrawLayer(4);
|
|
|
|
|
worldBuilder.RegisterDrawLayer(7);
|
|
|
|
|
|
2019-08-01 22:06:19 +00:00
|
|
|
|
worldBuilder.AddOrderedRenderer(new TestEntityRenderer());
|
2019-06-24 23:49:26 +00:00
|
|
|
|
var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
TestComponent testComponent;
|
2019-11-21 03:16:44 +00:00
|
|
|
|
TestDrawComponent drawComponentThree = new TestDrawComponent { Layer = 3 };
|
|
|
|
|
var drawComponentTwo = new TestDrawComponent { Layer = 2 };
|
|
|
|
|
var drawComponentOne = new TestDrawComponent { Layer = 1 };
|
|
|
|
|
var drawComponentFour = new TestDrawComponent { Layer = 4 };
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
|
worldBuilder.SetComponent(entity, testComponent);
|
2019-11-21 03:16:44 +00:00
|
|
|
|
worldBuilder.SetComponent(entity, drawComponentThree);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
var entityTwo = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
|
worldBuilder.SetComponent(entityTwo, testComponent);
|
2019-11-21 03:16:44 +00:00
|
|
|
|
worldBuilder.SetComponent(entityTwo, drawComponentTwo);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
var entityThree = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
|
worldBuilder.SetComponent(entityThree, testComponent);
|
2019-11-21 03:16:44 +00:00
|
|
|
|
worldBuilder.SetComponent(entityThree, drawComponentThree);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
var entityFour = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
|
worldBuilder.SetComponent(entityFour, testComponent);
|
2019-11-21 03:16:44 +00:00
|
|
|
|
worldBuilder.SetComponent(entityFour, drawComponentFour);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
drawOrder.Should().BeEquivalentTo(entityFour, entityTwo, entity, entityThree, testGeneralRenderer);
|
2019-06-20 03:37:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|