2019-06-19 21:14:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
2019-06-20 19:38:19 +00:00
|
|
|
|
using FluentAssertions;
|
2019-06-19 21:14:44 +00:00
|
|
|
|
using Encompass;
|
2019-06-20 19:38:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
|
{
|
|
|
|
|
public class EntityRendererTest
|
|
|
|
|
{
|
|
|
|
|
struct AComponent : IComponent { }
|
|
|
|
|
struct BComponent : IComponent { }
|
|
|
|
|
struct CComponent : IComponent { }
|
|
|
|
|
|
2019-06-20 05:38:56 +00:00
|
|
|
|
struct TestDrawComponent : IComponent { }
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
[Renders(typeof(TestDrawComponent), typeof(AComponent), typeof(BComponent))]
|
|
|
|
|
class TestRenderer : EntityRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render(Entity entity) { }
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 20:46:26 +00:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void CheckAndTrackEntities(bool parallelUpdate)
|
2019-06-19 21:14:44 +00:00
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
AComponent aComponent;
|
|
|
|
|
BComponent bComponent;
|
|
|
|
|
TestDrawComponent testDrawComponent = default(TestDrawComponent);
|
|
|
|
|
|
|
|
|
|
var entityToTrack = worldBuilder.CreateEntity();
|
2019-07-17 18:24:21 +00:00
|
|
|
|
worldBuilder.AddComponent(entityToTrack, aComponent);
|
|
|
|
|
worldBuilder.AddComponent(entityToTrack, bComponent);
|
|
|
|
|
worldBuilder.AddComponent(entityToTrack, testDrawComponent);
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
var entityNotToTrack = worldBuilder.CreateEntity();
|
2019-07-17 18:24:21 +00:00
|
|
|
|
worldBuilder.AddComponent(entityNotToTrack, aComponent);
|
|
|
|
|
worldBuilder.AddComponent(entityNotToTrack, testDrawComponent);
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
var entityWithoutDrawComponent = worldBuilder.CreateEntity();
|
2019-07-17 18:24:21 +00:00
|
|
|
|
worldBuilder.AddComponent(entityWithoutDrawComponent, aComponent);
|
|
|
|
|
worldBuilder.AddComponent(entityWithoutDrawComponent, bComponent);
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
2019-07-28 20:46:26 +00:00
|
|
|
|
if (parallelUpdate)
|
|
|
|
|
{
|
|
|
|
|
world.ParallelUpdate(0.01);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
}
|
2019-06-19 21:14:44 +00:00
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
|
Assert.IsTrue(renderer.IsTracking(entityToTrack.ID));
|
|
|
|
|
Assert.IsFalse(renderer.IsTracking(entityNotToTrack.ID));
|
|
|
|
|
Assert.IsFalse(renderer.IsTracking(entityWithoutDrawComponent.ID));
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
|
|
|
|
static bool called = false;
|
|
|
|
|
class DeactivatedRenderer : TestRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render(Entity entity)
|
|
|
|
|
{
|
|
|
|
|
called = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 20:46:26 +00:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void InactiveDrawComponent(bool parallelUpdate)
|
2019-06-20 00:40:01 +00:00
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
|
|
|
|
AComponent aComponent;
|
|
|
|
|
BComponent bComponent;
|
|
|
|
|
TestDrawComponent testDrawComponent = default(TestDrawComponent);
|
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-07-17 18:24:21 +00:00
|
|
|
|
worldBuilder.AddComponent(entity, aComponent);
|
|
|
|
|
worldBuilder.AddComponent(entity, bComponent);
|
|
|
|
|
var testDrawComponentID = worldBuilder.AddDrawComponent(entity, testDrawComponent, 1);
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
|
worldBuilder.DeactivateComponent(testDrawComponentID);
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
|
var world = worldBuilder.Build();
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
2019-07-28 20:46:26 +00:00
|
|
|
|
if (parallelUpdate)
|
|
|
|
|
{
|
|
|
|
|
world.ParallelUpdate(0.01);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
}
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
|
Assert.IsFalse(renderer.IsTracking(entity.ID));
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
|
|
|
|
world.Draw();
|
|
|
|
|
|
|
|
|
|
Assert.IsFalse(called);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool calledOnDraw = false;
|
2019-06-27 23:55:12 +00:00
|
|
|
|
static IEnumerable<ValueTuple<Guid, TestDrawComponent>> resultComponents;
|
2019-06-20 00:40:01 +00:00
|
|
|
|
[Renders(typeof(TestDrawComponent), typeof(AComponent), typeof(CComponent))]
|
|
|
|
|
class CalledRenderer : EntityRenderer
|
|
|
|
|
{
|
|
|
|
|
public override void Render(Entity entity)
|
|
|
|
|
{
|
2019-07-17 18:24:21 +00:00
|
|
|
|
resultComponents = GetComponents<TestDrawComponent>(entity);
|
2019-06-20 00:40:01 +00:00
|
|
|
|
calledOnDraw = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 20:46:26 +00:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void RenderMethodCalledOnWorldDraw(bool parallelUpdate)
|
2019-06-20 00:40:01 +00:00
|
|
|
|
{
|
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 23:49:26 +00:00
|
|
|
|
var renderer = worldBuilder.AddEntityRenderer(new CalledRenderer());
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
|
|
|
|
AComponent aComponent;
|
|
|
|
|
CComponent cComponent;
|
2019-06-20 19:38:19 +00:00
|
|
|
|
TestDrawComponent testDrawComponent;
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
2019-07-17 18:24:21 +00:00
|
|
|
|
worldBuilder.AddComponent(entity, aComponent);
|
|
|
|
|
worldBuilder.AddComponent(entity, cComponent);
|
|
|
|
|
var testDrawComponentID = worldBuilder.AddDrawComponent(entity, testDrawComponent, 2);
|
2019-06-20 00:40:01 +00:00
|
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
2019-07-28 20:46:26 +00:00
|
|
|
|
if (parallelUpdate)
|
|
|
|
|
{
|
|
|
|
|
world.ParallelUpdate(0.01);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 00:40:01 +00:00
|
|
|
|
world.Draw();
|
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
|
Assert.IsTrue(renderer.IsTracking(entity.ID));
|
2019-06-20 00:40:01 +00:00
|
|
|
|
Assert.IsTrue(calledOnDraw);
|
2019-06-27 23:55:12 +00:00
|
|
|
|
resultComponents.Should().Contain(new ValueTuple<Guid, TestDrawComponent>(testDrawComponentID, testDrawComponent));
|
2019-06-20 00:40:01 +00:00
|
|
|
|
}
|
2019-06-19 21:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|