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();
|
|
|
|
|
worldBuilder.AddComponent(entity, aComponent);
|
|
|
|
|
worldBuilder.AddComponent(entity, cComponent);
|
|
|
|
|
var testDrawComponentID = worldBuilder.AddDrawComponent(entity, testDrawComponent, 2);
|
|
|
|
|
|
|
|
|
|
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>())
|
|
|
|
|
{
|
|
|
|
|
Destroy(GetEntityIDByComponentID(componentID));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[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();
|
|
|
|
|
var testDrawComponentID = worldBuilder.AddDrawComponent(entity, testDrawComponent, 1);
|
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(calledOnDraw);
|
|
|
|
|
}
|
2019-08-01 22:06:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|