fix engine ordering issue with Spawner

pull/5/head
Evan Hemsley 2019-06-28 22:57:18 -07:00
parent dc99f58334
commit 8d39c27b7f
2 changed files with 29 additions and 29 deletions

View File

@ -55,10 +55,7 @@ namespace Encompass
entityManager.RegisterEntityTracker(engine as IEntityTracker); entityManager.RegisterEntityTracker(engine as IEntityTracker);
} }
var emitMessageAttribute = engine.GetType().GetCustomAttribute<Emits>(false); foreach (var emitMessageType in engine.emitMessageTypes)
if (emitMessageAttribute != null)
{
foreach (var emitMessageType in engine.GetType().GetCustomAttribute<Emits>(false).emitMessageTypes)
{ {
if (!messageTypeToEmitters.ContainsKey(emitMessageType)) if (!messageTypeToEmitters.ContainsKey(emitMessageType))
{ {
@ -75,12 +72,8 @@ namespace Encompass
} }
} }
} }
}
var readMessageAttribute = engine.GetType().GetCustomAttribute<Reads>(false); foreach (var readMessageType in engine.readMessageTypes)
if (readMessageAttribute != null)
{
foreach (var readMessageType in engine.GetType().GetCustomAttribute<Reads>(false).readMessageTypes)
{ {
if (!messageTypeToReaders.ContainsKey(readMessageType)) if (!messageTypeToReaders.ContainsKey(readMessageType))
{ {
@ -97,7 +90,6 @@ namespace Encompass
} }
} }
} }
}
return engine; return engine;
} }

View File

@ -14,6 +14,15 @@ namespace Tests
static Entity resultEntity; static Entity resultEntity;
[Emits(typeof(SpawnMessageA))]
class MessageEmitter : Engine
{
public override void Update(double dt)
{
EmitMessage(new SpawnMessageA());
}
}
class TestSpawner : Spawner<SpawnMessageA> class TestSpawner : Spawner<SpawnMessageA>
{ {
protected override void Spawn(SpawnMessageA message) protected override void Spawn(SpawnMessageA message)
@ -27,10 +36,9 @@ namespace Tests
public void RunsSpawnMethodOnMessageRead() public void RunsSpawnMethodOnMessageRead()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new MessageEmitter());
worldBuilder.AddEngine(new TestSpawner()); worldBuilder.AddEngine(new TestSpawner());
worldBuilder.EmitMessage(new SpawnMessageA());
var world = worldBuilder.Build(); var world = worldBuilder.Build();
world.Update(0.01); world.Update(0.01);
@ -41,7 +49,7 @@ namespace Tests
world.Update(0.01); world.Update(0.01);
Assert.That(resultEntity.id, Is.EqualTo(id)); Assert.That(resultEntity.id, Is.Not.EqualTo(id));
} }
} }
} }