2019-06-20 01:01:08 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Encompass;
|
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
2019-06-27 23:55:12 +00:00
|
|
|
|
public static class GeneralRendererTest
|
2019-06-20 01:01:08 +00:00
|
|
|
|
{
|
2020-03-20 22:45:58 +00:00
|
|
|
|
struct AComponent { }
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
|
|
|
|
public class SingletonRead
|
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
|
static (AComponent, Entity) result;
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
|
|
|
|
class TestRenderer : GeneralRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render()
|
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
|
result = ReadComponentIncludingEntity<AComponent>();
|
2019-06-20 01:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SingletonComponent()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
|
|
|
|
AComponent aComponent;
|
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-11-21 03:01:29 +00:00
|
|
|
|
worldBuilder.SetComponent(entity, aComponent);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
2019-12-06 01:50:05 +00:00
|
|
|
|
world.Update(0.01);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
Assert.That(result, Is.EqualTo((aComponent, entity)));
|
2019-06-20 01:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MultipleComponents()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
|
|
|
|
AComponent aComponent;
|
|
|
|
|
AComponent aComponentTwo;
|
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-11-21 03:01:29 +00:00
|
|
|
|
worldBuilder.SetComponent(entity, aComponent);
|
2019-08-11 00:34:00 +00:00
|
|
|
|
|
|
|
|
|
var entityB = worldBuilder.CreateEntity();
|
2019-11-21 03:01:29 +00:00
|
|
|
|
worldBuilder.SetComponent(entityB, aComponentTwo);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
2019-12-06 01:50:05 +00:00
|
|
|
|
world.Draw();
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
2019-12-06 01:50:05 +00:00
|
|
|
|
world.Update(0.01f);
|
2019-08-01 23:48:02 +00:00
|
|
|
|
world.Draw();
|
|
|
|
|
|
2019-11-21 03:01:29 +00:00
|
|
|
|
Assert.That(result, Is.EqualTo((aComponent, entity)).Or.EqualTo((aComponentTwo, entityB)));
|
2019-06-20 01:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|