2019-08-01 22:06:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Encompass;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
|
|
|
|
public class OrderedRendererTest
|
|
|
|
|
{
|
|
|
|
|
struct AComponent : IComponent { }
|
|
|
|
|
struct BComponent : IComponent { }
|
|
|
|
|
struct CComponent : IComponent { }
|
|
|
|
|
|
|
|
|
|
struct TestDrawComponent : IComponent { }
|
|
|
|
|
|
|
|
|
|
class TestRenderer : OrderedRenderer<TestDrawComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent) { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool called = false;
|
|
|
|
|
class DeactivatedRenderer : TestRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent)
|
|
|
|
|
{
|
|
|
|
|
called = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool calledOnDraw = false;
|
|
|
|
|
static ValueTuple<Guid, TestDrawComponent> resultComponent;
|
|
|
|
|
|
|
|
|
|
class CalledRenderer : OrderedRenderer<TestDrawComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Render(Guid drawComponentID, TestDrawComponent testDrawComponent)
|
|
|
|
|
{
|
|
|
|
|
resultComponent = (drawComponentID, testDrawComponent);
|
|
|
|
|
calledOnDraw = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void RenderMethodCalledOnWorldDraw()
|
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
var renderer = worldBuilder.AddOrderedRenderer(new CalledRenderer());
|
|
|
|
|
|
|
|
|
|
AComponent aComponent;
|
|
|
|
|
CComponent cComponent;
|
|
|
|
|
TestDrawComponent testDrawComponent;
|
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
|
worldBuilder.SetComponent(entity, aComponent);
|
|
|
|
|
worldBuilder.SetComponent(entity, cComponent);
|
|
|
|
|
var testDrawComponentID = worldBuilder.SetDrawComponent(entity, testDrawComponent, 2);
|
2019-08-01 22:06:19 +00:00
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(calledOnDraw);
|
|
|
|
|
resultComponent.Should().BeEquivalentTo((testDrawComponentID, testDrawComponent));
|
|
|
|
|
}
|
2019-08-02 06:09:41 +00:00
|
|
|
|
|
|
|
|
|
[Reads(typeof(TestDrawComponent))]
|
|
|
|
|
class DestroyerEngine : Engine
|
|
|
|
|
{
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (componentID, component) in ReadComponents<TestDrawComponent>())
|
|
|
|
|
{
|
2019-08-21 22:13:48 +00:00
|
|
|
|
Destroy(GetEntityIDByComponentID<TestDrawComponent>(componentID));
|
2019-08-02 06:09:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[Test]
|
|
|
|
|
public void RenderMethodNotCalledAfterDestroy()
|
|
|
|
|
{
|
|
|
|
|
calledOnDraw = false;
|
|
|
|
|
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
worldBuilder.AddEngine(new DestroyerEngine());
|
|
|
|
|
var renderer = worldBuilder.AddOrderedRenderer(new CalledRenderer());
|
|
|
|
|
|
|
|
|
|
TestDrawComponent testDrawComponent;
|
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-08-21 22:13:48 +00:00
|
|
|
|
var testDrawComponentID = worldBuilder.SetDrawComponent(entity, testDrawComponent, 1);
|
2019-08-02 06:09:41 +00:00
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(calledOnDraw);
|
|
|
|
|
}
|
2019-08-01 22:06:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|