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,46 +55,38 @@ namespace Encompass
entityManager.RegisterEntityTracker(engine as IEntityTracker);
}
var emitMessageAttribute = engine.GetType().GetCustomAttribute<Emits>(false);
if (emitMessageAttribute != null)
foreach (var emitMessageType in engine.emitMessageTypes)
{
foreach (var emitMessageType in engine.GetType().GetCustomAttribute<Emits>(false).emitMessageTypes)
if (!messageTypeToEmitters.ContainsKey(emitMessageType))
{
if (!messageTypeToEmitters.ContainsKey(emitMessageType))
{
messageTypeToEmitters.Add(emitMessageType, new HashSet<Engine>());
}
messageTypeToEmitters.Add(emitMessageType, new HashSet<Engine>());
}
messageTypeToEmitters[emitMessageType].Add(engine);
messageTypeToEmitters[emitMessageType].Add(engine);
if (messageTypeToReaders.ContainsKey(emitMessageType))
if (messageTypeToReaders.ContainsKey(emitMessageType))
{
foreach (var reader in messageTypeToReaders[emitMessageType])
{
foreach (var reader in messageTypeToReaders[emitMessageType])
{
engineGraph.AddEdge(engine, reader);
}
engineGraph.AddEdge(engine, reader);
}
}
}
var readMessageAttribute = engine.GetType().GetCustomAttribute<Reads>(false);
if (readMessageAttribute != null)
foreach (var readMessageType in engine.readMessageTypes)
{
foreach (var readMessageType in engine.GetType().GetCustomAttribute<Reads>(false).readMessageTypes)
if (!messageTypeToReaders.ContainsKey(readMessageType))
{
if (!messageTypeToReaders.ContainsKey(readMessageType))
{
messageTypeToReaders.Add(readMessageType, new HashSet<Engine>());
}
messageTypeToReaders.Add(readMessageType, new HashSet<Engine>());
}
messageTypeToReaders[readMessageType].Add(engine);
messageTypeToReaders[readMessageType].Add(engine);
if (messageTypeToEmitters.ContainsKey(readMessageType))
if (messageTypeToEmitters.ContainsKey(readMessageType))
{
foreach (var emitter in messageTypeToEmitters[readMessageType])
{
foreach (var emitter in messageTypeToEmitters[readMessageType])
{
engineGraph.AddEdge(emitter, engine);
}
engineGraph.AddEdge(emitter, engine);
}
}
}

View File

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