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); 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 protected void SendMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
{ {
if (!sendTypes.Contains(typeof(TMessage))) 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>>(); 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 internal void AddMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
{ {
if (!messageTypeToMessages.ContainsKey(typeof(TMessage))) if (!messageTypeToMessages.ContainsKey(typeof(TMessage)))

View File

@ -6,14 +6,14 @@ namespace Encompass
{ {
public class World public class World
{ {
private readonly ILookup<int, Engine> engineGroups; private readonly IOrderedEnumerable<IGrouping<int, Engine>> engineGroups;
private readonly EntityManager entityManager; private readonly EntityManager entityManager;
private readonly ComponentManager componentManager; private readonly ComponentManager componentManager;
private readonly MessageManager messageManager; private readonly MessageManager messageManager;
private readonly RenderManager renderManager; private readonly RenderManager renderManager;
internal World( internal World(
ILookup<int, Engine> engineGroups, IOrderedEnumerable<IGrouping<int, Engine>> engineGroups,
EntityManager entityManager, EntityManager entityManager,
ComponentManager componentManager, ComponentManager componentManager,
MessageManager messageManager, MessageManager messageManager,
@ -29,7 +29,20 @@ namespace Encompass
public void Update(double dt) 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 try
{ {
@ -48,6 +61,11 @@ namespace Encompass
} }
} }
PostUpdate();
}
private void PostUpdate()
{
messageManager.ClearMessages(); messageManager.ClearMessages();
entityManager.DestroyMarkedEntities(); entityManager.DestroyMarkedEntities();

View File

@ -264,7 +264,7 @@ namespace Encompass
} }
var world = new World( 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, entityManager,
componentManager, componentManager,
messageManager, messageManager,

View File

@ -57,8 +57,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void AddComponent() [TestCase(false)]
public void AddComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new AddComponentTestEngine()); worldBuilder.AddEngine(new AddComponentTestEngine());
@ -78,7 +79,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
struct AddMockComponentMessage : IMessage struct AddMockComponentMessage : IMessage
@ -140,8 +148,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void AddComponentAndReadSameFrame() [TestCase(false)]
public void AddComponentAndReadSameFrame(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
@ -152,7 +161,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(hasComponentResult); Assert.IsTrue(hasComponentResult);
} }
@ -199,8 +215,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void GetComponents() [TestCase(false)]
public void GetComponents(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
@ -237,11 +254,19 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
[Test] [TestCase(true)]
public void GetComponent() [TestCase(false)]
public void GetComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetMockComponentEngine()); worldBuilder.AddEngine(new GetMockComponentEngine());
@ -260,7 +285,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.AreEqual((componentID, mockComponent), gottenMockComponentIDPair); Assert.AreEqual((componentID, mockComponent), gottenMockComponentIDPair);
} }
@ -283,8 +315,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void HasComponent() [TestCase(false)]
public void HasComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new HasComponentTestEngine()); worldBuilder.AddEngine(new HasComponentTestEngine());
@ -303,7 +336,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
struct HasComponentWhenInactiveTestMessage : IMessage struct HasComponentWhenInactiveTestMessage : IMessage
@ -324,8 +364,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void HasComponentWhenInactive() [TestCase(false)]
public void HasComponentWhenInactive(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new HasComponentWhenInactiveTestEngine()); worldBuilder.AddEngine(new HasComponentWhenInactiveTestEngine());
@ -345,7 +386,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
struct RemoveComponentTestMessage : IMessage struct RemoveComponentTestMessage : IMessage
@ -409,8 +457,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void RemoveComponent() [TestCase(false)]
public void RemoveComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
@ -432,7 +481,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
struct ActivateComponentMessage : IMessage struct ActivateComponentMessage : IMessage
@ -496,8 +552,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void ActivateComponent() [TestCase(false)]
public void ActivateComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
@ -521,7 +578,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
struct DeactivateComponentMessage : IMessage struct DeactivateComponentMessage : IMessage
@ -572,8 +636,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void DeactivateComponent() [TestCase(false)]
public void DeactivateComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
@ -595,7 +660,14 @@ namespace Tests
var world = worldBuilder.Build(); 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] [TestCase(true)]
public void ReadComponents() [TestCase(false)]
public void ReadComponents(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadComponentsTestEngine()); worldBuilder.AddEngine(new ReadComponentsTestEngine());
@ -66,16 +67,23 @@ namespace Tests
var world = worldBuilder.Build(); 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); var resultComponentValues = resultComponents.Select((kv) => kv.Item2);
resultComponentValues.Should().Contain(mockComponent); resultComponentValues.Should().Contain(mockComponent);
resultComponentValues.Should().Contain(mockComponentB); resultComponentValues.Should().Contain(mockComponentB);
resultComponents.Should().NotContain((inactiveComponentAID, mockComponent)); resultComponents.Should().NotContain((inactiveComponentAID, mockComponent));
} }
[Test] [TestCase(true)]
public void ReadComponent() [TestCase(false)]
public void ReadComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadComponentTestEngine()); worldBuilder.AddEngine(new ReadComponentTestEngine());
@ -90,13 +98,21 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01f);
}
Assert.AreEqual(mockComponent, resultComponent); Assert.AreEqual(mockComponent, resultComponent);
} }
[Test] [TestCase(true)]
public void ReadComponentWhenMultipleComponents() [TestCase(false)]
public void ReadComponentWhenMultipleComponents(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadComponentTestEngine()); worldBuilder.AddEngine(new ReadComponentTestEngine());
@ -115,8 +131,15 @@ namespace Tests
worldBuilder.AddComponent(entity, mockComponentB); worldBuilder.AddComponent(entity, mockComponentB);
var world = worldBuilder.Build(); 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))] [Reads(typeof(MockComponent))]
@ -135,8 +158,9 @@ namespace Tests
// this test needs to be improved... // this test needs to be improved...
[Test] [TestCase(true)]
public void UpdateComponent() [TestCase(false)]
public void UpdateComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
@ -153,8 +177,16 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
world.Update(0.01); {
world.ParallelUpdate(0.01);
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
world.Update(0.01);
}
Assert.AreEqual(420, resultComponent.myInt); Assert.AreEqual(420, resultComponent.myInt);
Assert.AreEqual("blaze it", resultComponent.myString); Assert.AreEqual("blaze it", resultComponent.myString);
@ -175,8 +207,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void UpdateUndeclaredComponent() [TestCase(false)]
public void UpdateUndeclaredComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new UndeclaredUpdateComponentTestEngine()); worldBuilder.AddEngine(new UndeclaredUpdateComponentTestEngine());
@ -191,7 +224,14 @@ namespace Tests
var world = worldBuilder.Build(); 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)); var ex = Assert.Throws<IllegalUpdateException>(() => world.Update(0.01f));
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredUpdateComponentTestEngine tried to update undeclared Component MockComponent")); Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredUpdateComponentTestEngine tried to update undeclared Component MockComponent"));
@ -223,8 +263,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void EmitAndReadMessage() [TestCase(false)]
public void EmitAndReadMessage(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new MessageEmitEngine()); worldBuilder.AddEngine(new MessageEmitEngine());
@ -232,7 +273,14 @@ namespace Tests
var world = worldBuilder.Build(); 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"); Assert.AreEqual(resultMessages.First().myString, "howdy");
} }
@ -259,29 +307,46 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void ReadMessagesWhenNoneHaveBeenEmitted() [TestCase(false)]
public void ReadMessagesWhenNoneHaveBeenEmitted(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadMessagesWhenNoneExistEngine()); worldBuilder.AddEngine(new ReadMessagesWhenNoneExistEngine());
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
emptyReadMessagesResult.Should().BeEmpty(); emptyReadMessagesResult.Should().BeEmpty();
} }
[Test] [TestCase(true)]
public void EmitUndeclaredMessage() [TestCase(false)]
public void EmitUndeclaredMessage(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new UndeclaredMessageEmitEngine()); worldBuilder.AddEngine(new UndeclaredMessageEmitEngine());
var world = worldBuilder.Build(); var world = worldBuilder.Build();
var ex = Assert.Throws<IllegalSendException>(() => world.Update(0.01f)); if (parallelUpdate)
Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredMessageEmitEngine tried to send undeclared Message MockMessage")); {
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; static bool someTest;
@ -307,8 +372,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void SomeMessage() [TestCase(false)]
public void SomeMessage(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new EmitMockMessageEngine()); worldBuilder.AddEngine(new EmitMockMessageEngine());
@ -316,7 +382,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f); if (parallelUpdate)
{
world.ParallelUpdate(0.01f);
}
else
{
world.Update(0.01f);
}
Assert.That(someTest, Is.True); Assert.That(someTest, Is.True);
} }
@ -329,8 +402,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void UndeclaredSomeMessage() [TestCase(false)]
public void UndeclaredSomeMessage(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new EmitMockMessageEngine()); worldBuilder.AddEngine(new EmitMockMessageEngine());
@ -338,7 +412,14 @@ namespace Tests
var world = worldBuilder.Build(); 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 class SomeComponentTestEngine : Engine
@ -349,8 +430,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void SomeComponent() [TestCase(false)]
public void SomeComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
@ -359,7 +441,14 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
} }
static ValueTuple<Guid, MockComponent> pairA; static ValueTuple<Guid, MockComponent> pairA;
@ -378,8 +467,9 @@ namespace Tests
} }
// Tests that components with identical values should be distinguishable by ID // Tests that components with identical values should be distinguishable by ID
[Test] [TestCase(true)]
public void SameValueComponents() [TestCase(false)]
public void SameValueComponents(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new SameValueComponentReadEngine()); worldBuilder.AddEngine(new SameValueComponentReadEngine());
@ -397,7 +487,15 @@ namespace Tests
worldBuilder.AddComponent(entity, componentB); worldBuilder.AddComponent(entity, componentB);
var world = worldBuilder.Build(); 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, Is.Not.EqualTo(pairB));
Assert.That(pairA.Item2, Is.EqualTo(pairB.Item2)); Assert.That(pairA.Item2, Is.EqualTo(pairB.Item2));
@ -414,14 +512,23 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void ReadComponentsOfTypeWhereNoneExist() [TestCase(false)]
public void ReadComponentsOfTypeWhereNoneExist(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new ReadEmptyMockComponentsEngine()); worldBuilder.AddEngine(new ReadEmptyMockComponentsEngine());
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f);
if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.That(emptyComponentReadResult, Is.Empty); Assert.That(emptyComponentReadResult, Is.Empty);
} }
@ -453,8 +560,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void DestroyEntity() [TestCase(false)]
public void DestroyEntity(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new DestroyerEngine()); worldBuilder.AddEngine(new DestroyerEngine());
@ -476,7 +584,14 @@ namespace Tests
var world = worldBuilder.Build(); 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((componentID, mockComponent)));
Assert.That(results, Does.Not.Contain((componentBID, mockComponent))); Assert.That(results, Does.Not.Contain((componentBID, mockComponent)));
@ -498,8 +613,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void DestroyEntityWhileRemovingComponent() [TestCase(false)]
public void DestroyEntityWhileRemovingComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new DestroyAndAddComponentEngine()); worldBuilder.AddEngine(new DestroyAndAddComponentEngine());
@ -512,7 +628,14 @@ namespace Tests
var world = worldBuilder.Build(); 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; static Entity entityFromComponentIDResult;
@ -527,8 +650,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void GetEntityFromComponentID() [TestCase(false)]
public void GetEntityFromComponentID(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetEntityFromComponentIDEngine()); worldBuilder.AddEngine(new GetEntityFromComponentIDEngine());
@ -541,7 +665,15 @@ namespace Tests
worldBuilder.AddComponent(entity, component); worldBuilder.AddComponent(entity, component);
var world = worldBuilder.Build(); 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)); Assert.That(entity, Is.EqualTo(entityFromComponentIDResult));
} }
@ -557,8 +689,10 @@ namespace Tests
mockComponentByIDResult = GetComponentByID<MockComponent>(componentID); mockComponentByIDResult = GetComponentByID<MockComponent>(componentID);
} }
} }
[Test]
public void GetComponentByID() [TestCase(true)]
[TestCase(false)]
public void GetComponentByID(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetComponentByIDEngine()); worldBuilder.AddEngine(new GetComponentByIDEngine());
@ -571,7 +705,15 @@ namespace Tests
worldBuilder.AddComponent(entity, component); worldBuilder.AddComponent(entity, component);
var world = worldBuilder.Build(); 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)); Assert.That(component, Is.EqualTo(mockComponentByIDResult));
} }
@ -588,8 +730,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void GetComponentByIDWithTypeMismatch() [TestCase(false)]
public void GetComponentByIDWithTypeMismatch(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new GetComponentByIDWithTypeMismatchEngine()); worldBuilder.AddEngine(new GetComponentByIDWithTypeMismatchEngine());
@ -603,7 +746,14 @@ namespace Tests
var world = worldBuilder.Build(); 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; } struct EntityIDComponent : IComponent { public Guid entityID; }
@ -622,8 +772,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void EntityExists() [TestCase(false)]
public void EntityExists(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new HasEntityTestEngine()); worldBuilder.AddEngine(new HasEntityTestEngine());
@ -638,11 +789,25 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsTrue(hasEntity); Assert.IsTrue(hasEntity);
world.Update(0.01); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
Assert.IsFalse(hasEntity); Assert.IsFalse(hasEntity);
} }
@ -667,8 +832,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void EngineUpdatesComponentMultipleTimes() [TestCase(false)]
public void EngineUpdatesComponentMultipleTimes(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new RepeatUpdateEngine()); worldBuilder.AddEngine(new RepeatUpdateEngine());
@ -687,7 +853,15 @@ namespace Tests
worldBuilder.SendMessage(mockComponentUpdateMessage); worldBuilder.SendMessage(mockComponentUpdateMessage);
var world = worldBuilder.Build(); 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) { } public override void Render(Entity entity) { }
} }
[Test] [TestCase(true)]
public void CheckAndTrackEntities() [TestCase(false)]
public void CheckAndTrackEntities(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer(new TestRenderer()); var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
@ -46,7 +47,14 @@ namespace Tests
var world = worldBuilder.Build(); 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.IsTrue(renderer.IsTracking(entityToTrack.ID));
Assert.IsFalse(renderer.IsTracking(entityNotToTrack.ID)); Assert.IsFalse(renderer.IsTracking(entityNotToTrack.ID));
@ -62,8 +70,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void InactiveDrawComponent() [TestCase(false)]
public void InactiveDrawComponent(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer(new TestRenderer()); var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
@ -81,7 +90,14 @@ namespace Tests
var world = worldBuilder.Build(); 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)); Assert.IsFalse(renderer.IsTracking(entity.ID));
@ -102,8 +118,9 @@ namespace Tests
} }
} }
[Test] [TestCase(true)]
public void RenderMethodCalledOnWorldDraw() [TestCase(false)]
public void RenderMethodCalledOnWorldDraw(bool parallelUpdate)
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer(new CalledRenderer()); var renderer = worldBuilder.AddEntityRenderer(new CalledRenderer());
@ -119,7 +136,15 @@ namespace Tests
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01f); if (parallelUpdate)
{
world.ParallelUpdate(0.01);
}
else
{
world.Update(0.01);
}
world.Draw(); world.Draw();
Assert.IsTrue(renderer.IsTracking(entity.ID)); Assert.IsTrue(renderer.IsTracking(entity.ID));

View File

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

View File

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

View File

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

View File

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