unparameterized sendmessage + ParallelUpdate + tests

pull/5/head
Evan Hemsley 2019-07-28 13:46:26 -07:00
parent 9f6352a8f6
commit 09dbf07305
11 changed files with 478 additions and 120 deletions

View File

@ -259,6 +259,19 @@ namespace Encompass
SendMessage(componentUpdateMessage);
}
// unparameterized version to enable dynamic dispatch
protected void SendMessage(IMessage message)
{
var type = message.GetType();
if (!sendTypes.Contains(type) || !type.IsValueType)
{
throw new IllegalSendException("Engine {0} tried to send undeclared Message {1}", GetType().Name, type.Name);
}
messageManager.AddMessage(message);
}
protected void SendMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
{
if (!sendTypes.Contains(typeof(TMessage)))

View File

@ -8,6 +8,18 @@ namespace Encompass
{
private readonly Dictionary<Type, List<IMessage>> messageTypeToMessages = new Dictionary<Type, List<IMessage>>();
internal void AddMessage(IMessage message)
{
var type = message.GetType();
if (!messageTypeToMessages.ContainsKey(type))
{
messageTypeToMessages.Add(type, new List<IMessage>());
}
messageTypeToMessages[type].Add(message);
}
internal void AddMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
{
if (!messageTypeToMessages.ContainsKey(typeof(TMessage)))

View File

@ -6,14 +6,14 @@ namespace Encompass
{
public class World
{
private readonly ILookup<int, Engine> engineGroups;
private readonly IOrderedEnumerable<IGrouping<int, Engine>> engineGroups;
private readonly EntityManager entityManager;
private readonly ComponentManager componentManager;
private readonly MessageManager messageManager;
private readonly RenderManager renderManager;
internal World(
ILookup<int, Engine> engineGroups,
IOrderedEnumerable<IGrouping<int, Engine>> engineGroups,
EntityManager entityManager,
ComponentManager componentManager,
MessageManager messageManager,
@ -29,7 +29,20 @@ namespace Encompass
public void Update(double dt)
{
foreach (var engineGroup in engineGroups.OrderBy(lookup => lookup.Key))
foreach (var engineGroup in engineGroups)
{
foreach (var engine in engineGroup)
{
engine.Update(dt);
}
}
PostUpdate();
}
public void ParallelUpdate(double dt)
{
foreach (var engineGroup in engineGroups)
{
try
{
@ -48,6 +61,11 @@ namespace Encompass
}
}
PostUpdate();
}
private void PostUpdate()
{
messageManager.ClearMessages();
entityManager.DestroyMarkedEntities();

View File

@ -264,7 +264,7 @@ namespace Encompass
}
var world = new World(
engineGraph.LongestPaths(worldEngine).Where(pair => pair.Item2 != 0).ToLookup(pair => pair.Item2, pair => pair.Item1),
engineGraph.LongestPaths(worldEngine).Where(pair => pair.Item2 != 0).ToLookup(pair => pair.Item2, pair => pair.Item1).OrderBy(lookup => lookup.Key),
entityManager,
componentManager,
messageManager,

View File

@ -57,8 +57,9 @@ namespace Tests
}
}
[Test]
public void AddComponent()
[TestCase(true)]
[TestCase(false)]
public void AddComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new AddComponentTestEngine());
@ -78,7 +79,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
struct AddMockComponentMessage : IMessage
@ -140,8 +148,9 @@ namespace Tests
}
}
[Test]
public void AddComponentAndReadSameFrame()
[TestCase(true)]
[TestCase(false)]
public void AddComponentAndReadSameFrame(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
@ -152,7 +161,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(hasComponentResult);
}
@ -199,8 +215,9 @@ namespace Tests
}
}
[Test]
public void GetComponents()
[TestCase(true)]
[TestCase(false)]
public void GetComponents(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
@ -237,11 +254,19 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
[Test]
public void GetComponent()
[TestCase(true)]
[TestCase(false)]
public void GetComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetMockComponentEngine());
@ -260,7 +285,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.AreEqual((componentID, mockComponent), gottenMockComponentIDPair);
}
@ -283,8 +315,9 @@ namespace Tests
}
}
[Test]
public void HasComponent()
[TestCase(true)]
[TestCase(false)]
public void HasComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new HasComponentTestEngine());
@ -303,7 +336,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
struct HasComponentWhenInactiveTestMessage : IMessage
@ -324,8 +364,9 @@ namespace Tests
}
}
[Test]
public void HasComponentWhenInactive()
[TestCase(true)]
[TestCase(false)]
public void HasComponentWhenInactive(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new HasComponentWhenInactiveTestEngine());
@ -345,7 +386,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
struct RemoveComponentTestMessage : IMessage
@ -409,8 +457,9 @@ namespace Tests
}
}
[Test]
public void RemoveComponent()
[TestCase(true)]
[TestCase(false)]
public void RemoveComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
@ -432,7 +481,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
struct ActivateComponentMessage : IMessage
@ -496,8 +552,9 @@ namespace Tests
}
}
[Test]
public void ActivateComponent()
[TestCase(true)]
[TestCase(false)]
public void ActivateComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
@ -521,7 +578,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
struct DeactivateComponentMessage : IMessage
@ -572,8 +636,9 @@ namespace Tests
}
}
[Test]
public void DeactivateComponent()
[TestCase(true)]
[TestCase(false)]
public void DeactivateComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
@ -595,7 +660,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
}
}

View File

@ -42,8 +42,9 @@ namespace Tests
}
}
[Test]
public void ReadComponents()
[TestCase(true)]
[TestCase(false)]
public void ReadComponents(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadComponentsTestEngine());
@ -66,16 +67,23 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
var resultComponentValues = resultComponents.Select((kv) => kv.Item2);
resultComponentValues.Should().Contain(mockComponent);
resultComponentValues.Should().Contain(mockComponentB);
resultComponents.Should().NotContain((inactiveComponentAID, mockComponent));
}
[Test]
public void ReadComponent()
[TestCase(true)]
[TestCase(false)]
public void ReadComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadComponentTestEngine());
@ -90,13 +98,21 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01f);
}
Assert.AreEqual(mockComponent, resultComponent);
}
[Test]
public void ReadComponentWhenMultipleComponents()
[TestCase(true)]
[TestCase(false)]
public void ReadComponentWhenMultipleComponents(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadComponentTestEngine());
@ -115,8 +131,15 @@ namespace Tests
worldBuilder.AddComponent(entity, mockComponentB);
var world = worldBuilder.Build();
Assert.Throws<InvalidOperationException>(() => world.Update(0.01f));
if (parallelUpdate)
{
Assert.Throws<InvalidOperationException>(() => world.ParallelUpdate(0.01));
}
else
{
Assert.Throws<InvalidOperationException>(() => world.Update(0.01f));
}
}
[Reads(typeof(MockComponent))]
@ -135,8 +158,9 @@ namespace Tests
// this test needs to be improved...
[Test]
public void UpdateComponent()
[TestCase(true)]
[TestCase(false)]
public void UpdateComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
@ -153,8 +177,16 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
world.Update(0.01);
}
Assert.AreEqual(420, resultComponent.myInt);
Assert.AreEqual("blaze it", resultComponent.myString);
@ -175,8 +207,9 @@ namespace Tests
}
}
[Test]
public void UpdateUndeclaredComponent()
[TestCase(true)]
[TestCase(false)]
public void UpdateUndeclaredComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new UndeclaredUpdateComponentTestEngine());
@ -191,7 +224,14 @@ namespace Tests
var world = worldBuilder.Build();
Action updateWorld = () => world.Update(0.01);
if (parallelUpdate)
{
Action updateWorld = () => world.ParallelUpdate(0.01);
}
else
{
Action updateWorld = () => world.Update(0.01);
}
var ex = Assert.Throws<IllegalUpdateException>(() => world.Update(0.01f));
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredUpdateComponentTestEngine tried to update undeclared Component MockComponent"));
@ -223,8 +263,9 @@ namespace Tests
}
}
[Test]
public void EmitAndReadMessage()
[TestCase(true)]
[TestCase(false)]
public void EmitAndReadMessage(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new MessageEmitEngine());
@ -232,7 +273,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01f);
}
else
{
world.Update(0.01f);
}
Assert.AreEqual(resultMessages.First().myString, "howdy");
}
@ -259,29 +307,46 @@ namespace Tests
}
}
[Test]
public void ReadMessagesWhenNoneHaveBeenEmitted()
[TestCase(true)]
[TestCase(false)]
public void ReadMessagesWhenNoneHaveBeenEmitted(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadMessagesWhenNoneExistEngine());
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
emptyReadMessagesResult.Should().BeEmpty();
}
[Test]
public void EmitUndeclaredMessage()
[TestCase(true)]
[TestCase(false)]
public void EmitUndeclaredMessage(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new UndeclaredMessageEmitEngine());
var world = worldBuilder.Build();
var ex = Assert.Throws<IllegalSendException>(() => world.Update(0.01f));
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredMessageEmitEngine tried to send undeclared Message MockMessage"));
if (parallelUpdate)
{
var ex = Assert.Throws<IllegalSendException>(() => world.ParallelUpdate(0.01));
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredMessageEmitEngine tried to send undeclared Message MockMessage"));
}
else
{
var ex = Assert.Throws<IllegalSendException>(() => world.Update(0.01f));
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredMessageEmitEngine tried to send undeclared Message MockMessage"));
}
}
static bool someTest;
@ -307,8 +372,9 @@ namespace Tests
}
}
[Test]
public void SomeMessage()
[TestCase(true)]
[TestCase(false)]
public void SomeMessage(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new EmitMockMessageEngine());
@ -316,7 +382,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01f);
}
else
{
world.Update(0.01f);
}
Assert.That(someTest, Is.True);
}
@ -329,8 +402,9 @@ namespace Tests
}
}
[Test]
public void UndeclaredSomeMessage()
[TestCase(true)]
[TestCase(false)]
public void UndeclaredSomeMessage(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new EmitMockMessageEngine());
@ -338,7 +412,14 @@ namespace Tests
var world = worldBuilder.Build();
Assert.Throws<IllegalReadException>(() => world.Update(0.01f));
if (parallelUpdate)
{
Assert.Throws<IllegalReadException>(() => world.ParallelUpdate(0.01f));
}
else
{
Assert.Throws<IllegalReadException>(() => world.Update(0.01f));
}
}
class SomeComponentTestEngine : Engine
@ -349,8 +430,9 @@ namespace Tests
}
}
[Test]
public void SomeComponent()
[TestCase(true)]
[TestCase(false)]
public void SomeComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
@ -359,7 +441,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
}
static ValueTuple<Guid, MockComponent> pairA;
@ -378,8 +467,9 @@ namespace Tests
}
// Tests that components with identical values should be distinguishable by ID
[Test]
public void SameValueComponents()
[TestCase(true)]
[TestCase(false)]
public void SameValueComponents(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new SameValueComponentReadEngine());
@ -397,7 +487,15 @@ namespace Tests
worldBuilder.AddComponent(entity, componentB);
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.That(pairA, Is.Not.EqualTo(pairB));
Assert.That(pairA.Item2, Is.EqualTo(pairB.Item2));
@ -414,14 +512,23 @@ namespace Tests
}
}
[Test]
public void ReadComponentsOfTypeWhereNoneExist()
[TestCase(true)]
[TestCase(false)]
public void ReadComponentsOfTypeWhereNoneExist(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadEmptyMockComponentsEngine());
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.That(emptyComponentReadResult, Is.Empty);
}
@ -453,8 +560,9 @@ namespace Tests
}
}
[Test]
public void DestroyEntity()
[TestCase(true)]
[TestCase(false)]
public void DestroyEntity(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new DestroyerEngine());
@ -476,7 +584,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.That(results, Does.Not.Contain((componentID, mockComponent)));
Assert.That(results, Does.Not.Contain((componentBID, mockComponent)));
@ -498,8 +613,9 @@ namespace Tests
}
}
[Test]
public void DestroyEntityWhileRemovingComponent()
[TestCase(true)]
[TestCase(false)]
public void DestroyEntityWhileRemovingComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new DestroyAndAddComponentEngine());
@ -512,7 +628,14 @@ namespace Tests
var world = worldBuilder.Build();
Assert.DoesNotThrow(() => world.Update(0.01));
if (parallelUpdate)
{
Assert.DoesNotThrow(() => world.ParallelUpdate(0.01));
}
else
{
Assert.DoesNotThrow(() => world.Update(0.01));
}
}
static Entity entityFromComponentIDResult;
@ -527,8 +650,9 @@ namespace Tests
}
}
[Test]
public void GetEntityFromComponentID()
[TestCase(true)]
[TestCase(false)]
public void GetEntityFromComponentID(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetEntityFromComponentIDEngine());
@ -541,7 +665,15 @@ namespace Tests
worldBuilder.AddComponent(entity, component);
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.That(entity, Is.EqualTo(entityFromComponentIDResult));
}
@ -557,8 +689,10 @@ namespace Tests
mockComponentByIDResult = GetComponentByID<MockComponent>(componentID);
}
}
[Test]
public void GetComponentByID()
[TestCase(true)]
[TestCase(false)]
public void GetComponentByID(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetComponentByIDEngine());
@ -571,7 +705,15 @@ namespace Tests
worldBuilder.AddComponent(entity, component);
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.That(component, Is.EqualTo(mockComponentByIDResult));
}
@ -588,8 +730,9 @@ namespace Tests
}
}
[Test]
public void GetComponentByIDWithTypeMismatch()
[TestCase(true)]
[TestCase(false)]
public void GetComponentByIDWithTypeMismatch(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetComponentByIDWithTypeMismatchEngine());
@ -603,7 +746,14 @@ namespace Tests
var world = worldBuilder.Build();
Assert.Throws<ComponentTypeMismatchException>(() => world.Update(0.01f));
if (parallelUpdate)
{
Assert.Throws<ComponentTypeMismatchException>(() => world.ParallelUpdate(0.01));
}
else
{
Assert.Throws<ComponentTypeMismatchException>(() => world.Update(0.01));
}
}
struct EntityIDComponent : IComponent { public Guid entityID; }
@ -622,8 +772,9 @@ namespace Tests
}
}
[Test]
public void EntityExists()
[TestCase(true)]
[TestCase(false)]
public void EntityExists(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new HasEntityTestEngine());
@ -638,11 +789,25 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(hasEntity);
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsFalse(hasEntity);
}
@ -667,8 +832,9 @@ namespace Tests
}
}
[Test]
public void EngineUpdatesComponentMultipleTimes()
[TestCase(true)]
[TestCase(false)]
public void EngineUpdatesComponentMultipleTimes(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new RepeatUpdateEngine());
@ -687,7 +853,15 @@ namespace Tests
worldBuilder.SendMessage(mockComponentUpdateMessage);
var world = worldBuilder.Build();
Assert.Throws<RepeatUpdateComponentException>(() => world.Update(0.01));
if (parallelUpdate)
{
Assert.Throws<RepeatUpdateComponentException>(() => world.ParallelUpdate(0.01));
}
else
{
Assert.Throws<RepeatUpdateComponentException>(() => world.Update(0.01));
}
}
}
}

View File

@ -21,8 +21,9 @@ namespace Tests
public override void Render(Entity entity) { }
}
[Test]
public void CheckAndTrackEntities()
[TestCase(true)]
[TestCase(false)]
public void CheckAndTrackEntities(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
@ -46,7 +47,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(renderer.IsTracking(entityToTrack.ID));
Assert.IsFalse(renderer.IsTracking(entityNotToTrack.ID));
@ -62,8 +70,9 @@ namespace Tests
}
}
[Test]
public void InactiveDrawComponent()
[TestCase(true)]
[TestCase(false)]
public void InactiveDrawComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
@ -81,7 +90,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsFalse(renderer.IsTracking(entity.ID));
@ -102,8 +118,9 @@ namespace Tests
}
}
[Test]
public void RenderMethodCalledOnWorldDraw()
[TestCase(true)]
[TestCase(false)]
public void RenderMethodCalledOnWorldDraw(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer(new CalledRenderer());
@ -119,7 +136,15 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
world.Draw();
Assert.IsTrue(renderer.IsTracking(entity.ID));

View File

@ -23,8 +23,9 @@ namespace Tests
}
}
[Test]
public void SingletonComponent()
[TestCase(true)]
[TestCase(false)]
public void SingletonComponent(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
@ -36,14 +37,23 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
world.Draw();
Assert.That(result, Is.EqualTo(new ValueTuple<Guid, AComponent>(componentID, aComponent)));
}
[Test]
public void MultipleComponents()
[TestCase(true)]
[TestCase(false)]
public void MultipleComponents(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
@ -56,7 +66,14 @@ namespace Tests
var componentTwoID = worldBuilder.AddComponent(entity, aComponentTwo);
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.Throws<InvalidOperationException>(() => world.Draw());
}

View File

@ -37,8 +37,9 @@ namespace Tests
void Spawn(SpawnMessageA message);
}
[Test]
public void RunsSpawnMethodOnMessageRead()
[TestCase(true)]
[TestCase(false)]
public void RunsSpawnMethodOnMessageRead(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new MessageEmitter());
@ -46,7 +47,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(spawnResult);
}

View File

@ -254,8 +254,9 @@ namespace Tests
}
}
[Test]
public void EngineOrder()
[TestCase(true)]
[TestCase(false)]
public void EngineOrder(bool parallelUpdate)
{
var worldBuilder = new WorldBuilder();
@ -268,7 +269,14 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
var order = new List<Engine>();

View File

@ -33,9 +33,12 @@ namespace Tests
}
}
[Test]
public void DrawOrder()
[TestCase(true)]
[TestCase(false)]
public void DrawOrder(bool parallelUpdate)
{
drawOrder.Clear();
var worldBuilder = new WorldBuilder();
worldBuilder.AddEntityRenderer(new TestEntityRenderer());
var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
@ -67,7 +70,15 @@ namespace Tests
var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
world.Draw();
drawOrder.Should().BeEquivalentTo(entityFour, entityTwo, entity, entityThree, testGeneralRenderer);