From 9bb8fbda257effa3bf7fcb0c63ca03e3b07786cc Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+ehemsley@users.noreply.github.com> Date: Mon, 24 Jun 2019 12:26:19 -0700 Subject: [PATCH] change WorldBuilder.AddEngine to take an instantiated Engine --- encompass-cs/WorldBuilder.cs | 5 +---- test/DetectorTest.cs | 12 +++++------- test/EngineTest.cs | 32 ++++++++++++++++---------------- test/WorldBuilderTest.cs | 24 ++++++++++++------------ 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index abdfaeb..f1331fc 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -36,16 +36,13 @@ namespace Encompass return entityManager.CreateEntity(); } - public Engine AddEngine() where TEngine : Engine, new() + public Engine AddEngine(TEngine engine) where TEngine : Engine { - var engine = new TEngine(); - engine.AssignEntityManager(entityManager); engine.AssignComponentManager(componentManager); engine.AssignMessageManager(messageManager); engines.Add(engine); - engineGraph.AddVertex(engine); if (engine is IEntityTracker) diff --git a/test/DetectorTest.cs b/test/DetectorTest.cs index 36753fc..174ef2f 100644 --- a/test/DetectorTest.cs +++ b/test/DetectorTest.cs @@ -21,10 +21,8 @@ namespace Tests { var worldBuilder = new WorldBuilder(); - Action addEngine = () => worldBuilder.AddEngine(); - addEngine.Should() - .Throw() - .WithInnerException(); + Action addEngine = () => worldBuilder.AddEngine(new NoComponentTypesDetector()); + addEngine.Should().Throw(); } struct AComponent : IComponent { } @@ -46,7 +44,7 @@ namespace Tests public void CheckAndTrackEntities() { var worldBuilder = new WorldBuilder(); - var detector = worldBuilder.AddEngine(); + var detector = worldBuilder.AddEngine(new TestDetector()); var entityToTrack = worldBuilder.CreateEntity(); entityToTrack.AddComponent(new AComponent()); @@ -80,7 +78,7 @@ namespace Tests public void EntityUntrackedWhenComponentRemoved() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new TestDetector()); var entityToUntrack = worldBuilder.CreateEntity(); entityToUntrack.AddComponent(new AComponent()); @@ -102,7 +100,7 @@ namespace Tests public void DetectCalledPerTrackedEntityOnWorldUpdat() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new TestDetector()); var entityOne = worldBuilder.CreateEntity(); entityOne.AddComponent(new AComponent()); diff --git a/test/EngineTest.cs b/test/EngineTest.cs index 1c1a364..c57ce59 100644 --- a/test/EngineTest.cs +++ b/test/EngineTest.cs @@ -37,7 +37,7 @@ namespace Tests public void ReadComponents() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new ReadComponentsTestEngine()); var entity = worldBuilder.CreateEntity(); @@ -65,7 +65,7 @@ namespace Tests public void ReadComponent() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new ReadComponentTestEngine()); var entity = worldBuilder.CreateEntity(); @@ -86,7 +86,7 @@ namespace Tests public void ReadComponentWhenMultipleComponents() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new ReadComponentTestEngine()); var entity = worldBuilder.CreateEntity(); @@ -125,7 +125,7 @@ namespace Tests public void UpdateComponent() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new UpdateComponentTestEngine()); var entity = worldBuilder.CreateEntity(); @@ -161,7 +161,7 @@ namespace Tests public void UpdateUndeclaredComponent() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new UndeclaredUpdateComponentTestEngine()); var entity = worldBuilder.CreateEntity(); @@ -207,8 +207,8 @@ namespace Tests public void EmitAndReadMessage() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new MessageEmitEngine()); + worldBuilder.AddEngine(new MessageReadEngine()); var world = worldBuilder.Build(); @@ -232,7 +232,7 @@ namespace Tests public void EmitUndeclaredMessage() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new UndeclaredMessageEmitEngine()); var world = worldBuilder.Build(); @@ -267,8 +267,8 @@ namespace Tests public void Some() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new EmitMockMessageEngine()); + worldBuilder.AddEngine(new SomeTestEngine()); var world = worldBuilder.Build(); @@ -289,8 +289,8 @@ namespace Tests public void IllegalSome() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new EmitMockMessageEngine()); + worldBuilder.AddEngine(new UndeclaredSomeEngine()); var world = worldBuilder.Build(); @@ -316,7 +316,7 @@ namespace Tests public void SameValueComponents() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new SameValueComponentReadEngine()); MockComponent componentA; componentA.myInt = 20; @@ -351,7 +351,7 @@ namespace Tests public void ReadComponentsOfTypeWhereNoneExist() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new ReadEmptyMockComponentsEngine()); var world = worldBuilder.Build(); world.Update(0.01f); @@ -389,8 +389,8 @@ namespace Tests public void DestroyEntity() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new DestroyerEngine()); + worldBuilder.AddEngine(new ReaderEngine()); var entity = worldBuilder.CreateEntity(); var entityB = worldBuilder.CreateEntity(); diff --git a/test/WorldBuilderTest.cs b/test/WorldBuilderTest.cs index 6cfdefa..59efb82 100644 --- a/test/WorldBuilderTest.cs +++ b/test/WorldBuilderTest.cs @@ -39,8 +39,8 @@ namespace Tests public void EngineCycle() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new AEngine()); + worldBuilder.AddEngine(new BEngine()); Assert.Throws(() => worldBuilder.Build()); } @@ -101,10 +101,10 @@ namespace Tests public void EngineCycle() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new AEngine()); + worldBuilder.AddEngine(new BEngine()); + worldBuilder.AddEngine(new CEngine()); + worldBuilder.AddEngine(new DEngine()); Assert.Throws(() => worldBuilder.Build()); } @@ -130,8 +130,8 @@ namespace Tests public void MutationConflictException() { var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(); - worldBuilder.AddEngine(); + worldBuilder.AddEngine(new AEngine()); + worldBuilder.AddEngine(new BEngine()); Assert.Throws(() => worldBuilder.Build()); } @@ -193,10 +193,10 @@ namespace Tests { var worldBuilder = new WorldBuilder(); - var engineA = worldBuilder.AddEngine(); - var engineB = worldBuilder.AddEngine(); - var engineC = worldBuilder.AddEngine(); - var engineD = worldBuilder.AddEngine(); + var engineA = worldBuilder.AddEngine(new AEngine()); + var engineB = worldBuilder.AddEngine(new BEngine()); + var engineC = worldBuilder.AddEngine(new CEngine()); + var engineD = worldBuilder.AddEngine(new DEngine()); Assert.DoesNotThrow(() => worldBuilder.Build());