change WorldBuilder.AddEngine to take an instantiated Engine
parent
b4347f4085
commit
9bb8fbda25
|
@ -36,16 +36,13 @@ namespace Encompass
|
|||
return entityManager.CreateEntity();
|
||||
}
|
||||
|
||||
public Engine AddEngine<TEngine>() where TEngine : Engine, new()
|
||||
public Engine AddEngine<TEngine>(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)
|
||||
|
|
|
@ -21,10 +21,8 @@ namespace Tests
|
|||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
|
||||
Action addEngine = () => worldBuilder.AddEngine<NoComponentTypesDetector>();
|
||||
addEngine.Should()
|
||||
.Throw<System.Reflection.TargetInvocationException>()
|
||||
.WithInnerException<DetectorWithoutComponentTypesException>();
|
||||
Action addEngine = () => worldBuilder.AddEngine(new NoComponentTypesDetector());
|
||||
addEngine.Should().Throw<DetectorWithoutComponentTypesException>();
|
||||
}
|
||||
|
||||
struct AComponent : IComponent { }
|
||||
|
@ -46,7 +44,7 @@ namespace Tests
|
|||
public void CheckAndTrackEntities()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
var detector = worldBuilder.AddEngine<TestDetector>();
|
||||
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<TestDetector>();
|
||||
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<TestDetector>();
|
||||
worldBuilder.AddEngine(new TestDetector());
|
||||
|
||||
var entityOne = worldBuilder.CreateEntity();
|
||||
entityOne.AddComponent(new AComponent());
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Tests
|
|||
public void ReadComponents()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<ReadComponentsTestEngine>();
|
||||
worldBuilder.AddEngine(new ReadComponentsTestEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace Tests
|
|||
public void ReadComponent()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<ReadComponentTestEngine>();
|
||||
worldBuilder.AddEngine(new ReadComponentTestEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
|
@ -86,7 +86,7 @@ namespace Tests
|
|||
public void ReadComponentWhenMultipleComponents()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<ReadComponentTestEngine>();
|
||||
worldBuilder.AddEngine(new ReadComponentTestEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
|
@ -125,7 +125,7 @@ namespace Tests
|
|||
public void UpdateComponent()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<UpdateComponentTestEngine>();
|
||||
worldBuilder.AddEngine(new UpdateComponentTestEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
|
@ -161,7 +161,7 @@ namespace Tests
|
|||
public void UpdateUndeclaredComponent()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<UndeclaredUpdateComponentTestEngine>();
|
||||
worldBuilder.AddEngine(new UndeclaredUpdateComponentTestEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
|
||||
|
@ -207,8 +207,8 @@ namespace Tests
|
|||
public void EmitAndReadMessage()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<MessageEmitEngine>();
|
||||
worldBuilder.AddEngine<MessageReadEngine>();
|
||||
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<UndeclaredMessageEmitEngine>();
|
||||
worldBuilder.AddEngine(new UndeclaredMessageEmitEngine());
|
||||
|
||||
var world = worldBuilder.Build();
|
||||
|
||||
|
@ -267,8 +267,8 @@ namespace Tests
|
|||
public void Some()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<EmitMockMessageEngine>();
|
||||
worldBuilder.AddEngine<SomeTestEngine>();
|
||||
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<EmitMockMessageEngine>();
|
||||
worldBuilder.AddEngine<UndeclaredSomeEngine>();
|
||||
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<SameValueComponentReadEngine>();
|
||||
worldBuilder.AddEngine(new SameValueComponentReadEngine());
|
||||
|
||||
MockComponent componentA;
|
||||
componentA.myInt = 20;
|
||||
|
@ -351,7 +351,7 @@ namespace Tests
|
|||
public void ReadComponentsOfTypeWhereNoneExist()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<ReadEmptyMockComponentsEngine>();
|
||||
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<DestroyerEngine>();
|
||||
worldBuilder.AddEngine<ReaderEngine>();
|
||||
worldBuilder.AddEngine(new DestroyerEngine());
|
||||
worldBuilder.AddEngine(new ReaderEngine());
|
||||
|
||||
var entity = worldBuilder.CreateEntity();
|
||||
var entityB = worldBuilder.CreateEntity();
|
||||
|
|
|
@ -39,8 +39,8 @@ namespace Tests
|
|||
public void EngineCycle()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<AEngine>();
|
||||
worldBuilder.AddEngine<BEngine>();
|
||||
worldBuilder.AddEngine(new AEngine());
|
||||
worldBuilder.AddEngine(new BEngine());
|
||||
|
||||
Assert.Throws<EngineCycleException>(() => worldBuilder.Build());
|
||||
}
|
||||
|
@ -101,10 +101,10 @@ namespace Tests
|
|||
public void EngineCycle()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<AEngine>();
|
||||
worldBuilder.AddEngine<BEngine>();
|
||||
worldBuilder.AddEngine<CEngine>();
|
||||
worldBuilder.AddEngine<DEngine>();
|
||||
worldBuilder.AddEngine(new AEngine());
|
||||
worldBuilder.AddEngine(new BEngine());
|
||||
worldBuilder.AddEngine(new CEngine());
|
||||
worldBuilder.AddEngine(new DEngine());
|
||||
|
||||
Assert.Throws<EngineCycleException>(() => worldBuilder.Build());
|
||||
}
|
||||
|
@ -130,8 +130,8 @@ namespace Tests
|
|||
public void MutationConflictException()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
worldBuilder.AddEngine<AEngine>();
|
||||
worldBuilder.AddEngine<BEngine>();
|
||||
worldBuilder.AddEngine(new AEngine());
|
||||
worldBuilder.AddEngine(new BEngine());
|
||||
|
||||
Assert.Throws<EngineMutationConflictException>(() => worldBuilder.Build());
|
||||
}
|
||||
|
@ -193,10 +193,10 @@ namespace Tests
|
|||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
|
||||
var engineA = worldBuilder.AddEngine<AEngine>();
|
||||
var engineB = worldBuilder.AddEngine<BEngine>();
|
||||
var engineC = worldBuilder.AddEngine<CEngine>();
|
||||
var engineD = worldBuilder.AddEngine<DEngine>();
|
||||
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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue