diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 2d1157d..b4cd02f 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -55,46 +55,38 @@ namespace Encompass entityManager.RegisterEntityTracker(engine as IEntityTracker); } - var emitMessageAttribute = engine.GetType().GetCustomAttribute(false); - if (emitMessageAttribute != null) + foreach (var emitMessageType in engine.emitMessageTypes) { - foreach (var emitMessageType in engine.GetType().GetCustomAttribute(false).emitMessageTypes) + if (!messageTypeToEmitters.ContainsKey(emitMessageType)) { - if (!messageTypeToEmitters.ContainsKey(emitMessageType)) - { - messageTypeToEmitters.Add(emitMessageType, new HashSet()); - } + messageTypeToEmitters.Add(emitMessageType, new HashSet()); + } - 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(false); - if (readMessageAttribute != null) + foreach (var readMessageType in engine.readMessageTypes) { - foreach (var readMessageType in engine.GetType().GetCustomAttribute(false).readMessageTypes) + if (!messageTypeToReaders.ContainsKey(readMessageType)) { - if (!messageTypeToReaders.ContainsKey(readMessageType)) - { - messageTypeToReaders.Add(readMessageType, new HashSet()); - } + messageTypeToReaders.Add(readMessageType, new HashSet()); + } - 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); } } } diff --git a/test/SpawnerTest.cs b/test/SpawnerTest.cs index d4a3ce0..ed924d2 100644 --- a/test/SpawnerTest.cs +++ b/test/SpawnerTest.cs @@ -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 { 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)); } } }