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
|
|
|
|
{
|
2021-03-12 08:25:25 +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
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
class TestRenderer : Renderer
|
2019-06-20 01:01:08 +00:00
|
|
|
|
{
|
2021-03-24 00:50:05 +00:00
|
|
|
|
public override void Render(double dt, double alpha)
|
2019-06-20 01:01:08 +00:00
|
|
|
|
{
|
2020-03-23 02:10:28 +00:00
|
|
|
|
ref readonly var entity = ref ReadEntity<AComponent>();
|
|
|
|
|
result = (GetComponent<AComponent>(entity), entity);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SingletonComponent()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2021-03-12 08:25:25 +00:00
|
|
|
|
worldBuilder.AddRenderer(new TestRenderer());
|
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);
|
2021-03-24 00:50:05 +00:00
|
|
|
|
world.Draw(0.01f, 0);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
2019-12-06 01:50:05 +00:00
|
|
|
|
world.Update(0.01);
|
2021-03-24 00:50:05 +00:00
|
|
|
|
world.Draw(0.01f, 0);
|
2019-12-06 01:50:05 +00:00
|
|
|
|
|
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();
|
2021-03-12 08:25:25 +00:00
|
|
|
|
worldBuilder.AddRenderer(new TestRenderer());
|
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);
|
2021-03-24 00:50:05 +00:00
|
|
|
|
world.Draw(0.01f, 0);
|
2019-06-20 01:01:08 +00:00
|
|
|
|
|
2019-12-06 01:50:05 +00:00
|
|
|
|
world.Update(0.01f);
|
2021-03-24 00:50:05 +00:00
|
|
|
|
world.Draw(0.01f, 0);
|
2019-08-01 23:48:02 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|