From 1845d5f766af7c54567265694ad35981d799ab54 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Fri, 19 Jul 2019 12:47:17 -0700 Subject: [PATCH] read new and existing component system --- encompass-cs/Attributes/Activates.cs | 2 +- encompass-cs/Attributes/Reads.cs | 14 +-- encompass-cs/Attributes/ReadsNew.cs | 28 +++++ encompass-cs/Attributes/Receives.cs | 27 +++++ encompass-cs/Attributes/Sends.cs | 2 +- encompass-cs/Engine.cs | 112 +++++++++++------- .../Engines/ComponentMessageEmitter.cs | 6 - .../Engines/NewComponentMessageEmitter.cs | 24 ++++ encompass-cs/Engines/Spawner.cs | 2 +- ...teException.cs => IllegalSendException.cs} | 4 +- ...ception.cs => IllegalSendTypeException.cs} | 4 +- encompass-cs/NewComponentMessage.cs | 11 ++ encompass-cs/WorldBuilder.cs | 52 +++++--- test/ComponentTest.cs | 32 +++-- test/EngineTest.cs | 12 +- test/WorldBuilderTest.cs | 20 ++-- 16 files changed, 241 insertions(+), 111 deletions(-) create mode 100644 encompass-cs/Attributes/ReadsNew.cs create mode 100644 encompass-cs/Attributes/Receives.cs create mode 100644 encompass-cs/Engines/NewComponentMessageEmitter.cs rename encompass-cs/Exceptions/{IllegalWriteException.cs => IllegalSendException.cs} (65%) rename encompass-cs/Exceptions/{IllegalWriteTypeException.cs => IllegalSendTypeException.cs} (63%) create mode 100644 encompass-cs/NewComponentMessage.cs diff --git a/encompass-cs/Attributes/Activates.cs b/encompass-cs/Attributes/Activates.cs index d35e72b..777ca8f 100644 --- a/encompass-cs/Attributes/Activates.cs +++ b/encompass-cs/Attributes/Activates.cs @@ -19,7 +19,7 @@ namespace Encompass throw new IllegalActivateTypeException("{0} must be a Component", activateType.Name); } - this.activateTypes.Add(typeof(ComponentMessage<>).MakeGenericType(activateType)); + this.activateTypes.Add(typeof(NewComponentMessage<>).MakeGenericType(activateType)); } } } diff --git a/encompass-cs/Attributes/Reads.cs b/encompass-cs/Attributes/Reads.cs index c060f15..a8892dc 100644 --- a/encompass-cs/Attributes/Reads.cs +++ b/encompass-cs/Attributes/Reads.cs @@ -14,22 +14,14 @@ namespace Encompass { foreach (var readType in readTypes) { - var isMessage = readType.GetInterfaces().Contains(typeof(IMessage)); var isComponent = readType.GetInterfaces().Contains(typeof(IComponent)); - if (!isMessage && !isComponent) + if (!isComponent) { - throw new IllegalReadTypeException("{0} must be a Message or Component", readType.Name); + throw new IllegalReadTypeException("{0} must be a Component", readType.Name); } - if (isComponent) - { - this.readTypes.Add(typeof(ComponentMessage<>).MakeGenericType(readType)); - } - else - { - this.readTypes.Add(readType); - } + this.readTypes.Add(typeof(ComponentMessage<>).MakeGenericType(readType)); } } } diff --git a/encompass-cs/Attributes/ReadsNew.cs b/encompass-cs/Attributes/ReadsNew.cs new file mode 100644 index 0000000..82f168f --- /dev/null +++ b/encompass-cs/Attributes/ReadsNew.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Encompass.Exceptions; + +namespace Encompass +{ + [AttributeUsage(AttributeTargets.Class)] + public class ReadsNew : Attribute + { + public readonly HashSet newComponentReadTypes = new HashSet(); + + public ReadsNew(params Type[] readTypes) + { + foreach (var readType in readTypes) + { + var isComponent = readType.GetInterfaces().Contains(typeof(IComponent)); + + if (!isComponent) + { + throw new IllegalReadTypeException("{0} must be a Component", readType.Name); + } + + this.newComponentReadTypes.Add(typeof(ComponentMessage<>).MakeGenericType(readType)); + } + } + } +} diff --git a/encompass-cs/Attributes/Receives.cs b/encompass-cs/Attributes/Receives.cs new file mode 100644 index 0000000..e8d0542 --- /dev/null +++ b/encompass-cs/Attributes/Receives.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Encompass.Exceptions; + +namespace Encompass +{ + [AttributeUsage(AttributeTargets.Class)] + public class Receives : Attribute + { + public readonly HashSet receiveTypes; + + public Receives(params Type[] receiveTypes) + { + foreach (var receiveType in receiveTypes) + { + var isMessage = receiveType.GetInterfaces().Contains(typeof(IMessage)); + if (!isMessage) + { + throw new IllegalSendTypeException("{0} must be a Message", receiveType.Name); + } + } + + this.receiveTypes = new HashSet(receiveTypes); + } + } +} diff --git a/encompass-cs/Attributes/Sends.cs b/encompass-cs/Attributes/Sends.cs index b9b5cea..7bb1a0e 100644 --- a/encompass-cs/Attributes/Sends.cs +++ b/encompass-cs/Attributes/Sends.cs @@ -17,7 +17,7 @@ namespace Encompass var isMessage = sendType.GetInterfaces().Contains(typeof(IMessage)); if (!isMessage) { - throw new IllegalWriteTypeException("{0} must be a Message", sendType.Name); + throw new IllegalSendTypeException("{0} must be a Message", sendType.Name); } } diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 093e0cd..1cee385 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -9,8 +9,7 @@ namespace Encompass public abstract class Engine { internal readonly HashSet sendTypes = new HashSet(); - internal readonly HashSet readTypes = new HashSet(); - internal readonly HashSet activateTypes = new HashSet(); + internal readonly HashSet receiveTypes = new HashSet(); internal readonly HashSet updateTypes = new HashSet(); private EntityManager entityManager; @@ -19,22 +18,34 @@ namespace Encompass protected Engine() { - var writesAttribute = GetType().GetCustomAttribute(false); - if (writesAttribute != null) + var sendsAttribute = GetType().GetCustomAttribute(false); + if (sendsAttribute != null) { - sendTypes = writesAttribute.sendTypes; - } - - var readsAttribute = GetType().GetCustomAttribute(false); - if (readsAttribute != null) - { - readTypes = readsAttribute.readTypes; + sendTypes = sendsAttribute.sendTypes; } var activatesAttribute = GetType().GetCustomAttribute(false); if (activatesAttribute != null) { - activateTypes = activatesAttribute.activateTypes; + sendTypes.UnionWith(activatesAttribute.activateTypes); + } + + var receivesAttribute = GetType().GetCustomAttribute(false); + if (receivesAttribute != null) + { + receiveTypes = receivesAttribute.receiveTypes; + } + + var readsAttribute = GetType().GetCustomAttribute(false); + if (readsAttribute != null) + { + receiveTypes.UnionWith(readsAttribute.readTypes); + } + + var readsNewAttribute = GetType().GetCustomAttribute(false); + if (readsNewAttribute != null) + { + receiveTypes.UnionWith(readsNewAttribute.newComponentReadTypes); } var updatesAttribute = GetType().GetCustomAttribute(false); @@ -107,14 +118,14 @@ namespace Encompass protected Guid AddComponent(Entity entity, TComponent component) where TComponent : struct, IComponent { - if (!activateTypes.Contains(typeof(ComponentMessage))) + if (!sendTypes.Contains(typeof(NewComponentMessage))) { throw new IllegalActivateException("Engine {0} tried to activate undeclared Component {1}", GetType().Name, typeof(TComponent).Name); } var componentID = componentManager.AddComponent(entity.ID, component); - ComponentMessage componentMessage; + NewComponentMessage componentMessage; componentMessage.entity = entity; componentMessage.componentID = componentID; componentMessage.component = component; @@ -125,25 +136,25 @@ namespace Encompass protected Guid AddDrawComponent(Entity entity, TComponent component, int layer = 0) where TComponent : struct, IComponent { - if (!activateTypes.Contains(typeof(ComponentMessage))) + if (!sendTypes.Contains(typeof(NewComponentMessage))) { throw new IllegalActivateException("Engine {0} tried to activate undeclared Component {1}", GetType().Name, typeof(TComponent).Name); } var componentID = componentManager.AddDrawComponent(entity.ID, component, layer); - ComponentMessage componentMessage; - componentMessage.entity = entity; - componentMessage.componentID = componentID; - componentMessage.component = component; - SendMessage(componentMessage); + NewComponentMessage newComponentMessage; + newComponentMessage.entity = entity; + newComponentMessage.componentID = componentID; + newComponentMessage.component = component; + SendMessage(newComponentMessage); return componentID; } protected void ActivateComponent(Guid componentID) where TComponent : struct, IComponent { - if (!activateTypes.Contains(typeof(ComponentMessage))) + if (!sendTypes.Contains(typeof(NewComponentMessage))) { throw new IllegalActivateException("Engine {0} tried to activate undeclared Component {1}", GetType().Name, typeof(TComponent).Name); } @@ -151,13 +162,13 @@ namespace Encompass var entity = GetEntity(componentManager.GetEntityIDByComponentID(componentID)); var component = GetComponentByID(componentID); - ComponentMessage componentMessage; - componentMessage.entity = entity; - componentMessage.componentID = componentID; - componentMessage.component = component; - SendMessage(componentMessage); + NewComponentMessage newComponentMessage; + newComponentMessage.entity = entity; + newComponentMessage.componentID = componentID; + newComponentMessage.component = component; + SendMessage(newComponentMessage); - componentManager.Activate(componentID); + componentManager.Activate(componentID); // TODO: actually delay this to end of frame, make sure to update after activate } protected void DeactivateComponent(Guid componentID) @@ -165,9 +176,9 @@ namespace Encompass componentManager.MarkForDeactivation(componentID); } - protected IEnumerable> GetComponents(Entity entity) where TComponent : struct, IComponent + private IEnumerable> ExistingComponentsOnEntity(Entity entity) where TComponent : struct, IComponent { - if (!readTypes.Contains(typeof(ComponentMessage))) + if (!receiveTypes.Contains(typeof(ComponentMessage))) { throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name); } @@ -175,6 +186,26 @@ namespace Encompass return ReadMessages>().Where((message) => message.entity == entity).Select((message) => (message.componentID, message.component)); } + private IEnumerable> NewComponentsOnEntity(Entity entity) where TComponent : struct, IComponent + { + if (!receiveTypes.Contains(typeof(NewComponentMessage))) + { + throw new IllegalReadException("Engine {0} tried to read undeclared new Component {1}", GetType().Name, typeof(TComponent).Name); + } + + return ReadMessages>().Where((message) => message.entity == entity).Select((message) => (message.componentID, message.component)); + } + + protected IEnumerable> GetComponentsIncludingNew(Entity entity) where TComponent : struct, IComponent + { + return ExistingComponentsOnEntity(entity).Union(NewComponentsOnEntity(entity)); + } + + protected IEnumerable> GetComponents(Entity entity) where TComponent : struct, IComponent + { + return ExistingComponentsOnEntity(entity); + } + protected ValueTuple GetComponent(Entity entity) where TComponent : struct, IComponent { return GetComponents(entity).First(); @@ -182,19 +213,14 @@ namespace Encompass protected bool HasComponent(Entity entity) where TComponent : struct, IComponent { - if (!readTypes.Contains(typeof(ComponentMessage))) - { - throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name); - } - - return ReadMessages>().Where((message) => message.entity == entity).Any(); + return GetComponents(entity).Any(); } internal void UpdateComponentInWorld(Guid componentID, TComponent newComponent) where TComponent : struct, IComponent { if (!updateTypes.Contains(typeof(TComponent))) { - throw new IllegalWriteException("Engine {0} tried to write undeclared Component {1}", this.GetType().Name, typeof(TComponent).Name); + throw new IllegalSendException("Engine {0} tried to write undeclared Component {1}", this.GetType().Name, typeof(TComponent).Name); } componentManager.AddUpdateComponentOperation(componentID, newComponent); @@ -209,7 +235,7 @@ namespace Encompass { if (!sendTypes.Contains(typeof(TMessage))) { - throw new IllegalWriteException("Engine {0} tried to write undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name); + throw new IllegalSendException("Engine {0} tried to write undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name); } messageManager.AddMessage(message); @@ -217,7 +243,7 @@ namespace Encompass protected IEnumerable ReadMessages() where TMessage : struct, IMessage { - if (!readTypes.Contains(typeof(TMessage))) + if (!receiveTypes.Contains(typeof(TMessage))) { throw new IllegalReadException("Engine {0} tried to read undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name); } @@ -230,9 +256,9 @@ namespace Encompass return ReadMessages().Single(); } - protected IEnumerable<(Guid, TComponent)> ReadComponents() where TComponent : struct, IComponent + protected IEnumerable> ReadComponents() where TComponent : struct, IComponent { - if (!readTypes.Contains(typeof(ComponentMessage))) + if (!receiveTypes.Contains(typeof(ComponentMessage))) { throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", this.GetType().Name, typeof(TComponent).Name); } @@ -240,14 +266,14 @@ namespace Encompass return ReadMessages>().Select((message) => (message.componentID, message.component)); } - protected (Guid, TComponent) ReadComponent() where TComponent : struct, IComponent + protected ValueTuple ReadComponent() where TComponent : struct, IComponent { return ReadComponents().Single(); } protected bool SomeMessage() where TMessage : struct, IMessage { - if (!readTypes.Contains(typeof(TMessage))) + if (!receiveTypes.Contains(typeof(TMessage))) { throw new IllegalReadException("Engine {0} tried to read undeclared Message {1}", GetType().Name, typeof(TMessage).Name); } @@ -257,7 +283,7 @@ namespace Encompass protected bool SomeComponent() where TComponent : struct, IComponent { - if (!readTypes.Contains(typeof(ComponentMessage))) + if (!receiveTypes.Contains(typeof(ComponentMessage))) { throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name); } diff --git a/encompass-cs/Engines/ComponentMessageEmitter.cs b/encompass-cs/Engines/ComponentMessageEmitter.cs index 8bd709e..3ba6bb7 100644 --- a/encompass-cs/Engines/ComponentMessageEmitter.cs +++ b/encompass-cs/Engines/ComponentMessageEmitter.cs @@ -6,12 +6,6 @@ namespace Encompass.Engines { public ComponentMessageEmitter() : base() { - var writesAttribute = GetType().GetCustomAttribute(false); - if (writesAttribute != null) - { - writesAttribute.sendTypes.Add(typeof(ComponentMessage)); - } - sendTypes.Add(typeof(ComponentMessage)); } diff --git a/encompass-cs/Engines/NewComponentMessageEmitter.cs b/encompass-cs/Engines/NewComponentMessageEmitter.cs new file mode 100644 index 0000000..8f87378 --- /dev/null +++ b/encompass-cs/Engines/NewComponentMessageEmitter.cs @@ -0,0 +1,24 @@ +using System.Reflection; + +namespace Encompass.Engines +{ + internal class NewComponentMessageEmitter : Engine where TComponent : struct, IComponent + { + public NewComponentMessageEmitter() : base() + { + sendTypes.Add(typeof(NewComponentMessage)); + } + + public override void Update(double dt) + { + foreach (var (entity, componentID, component) in ReadComponentsFromWorld()) + { + NewComponentMessage newComponentMessage; + newComponentMessage.entity = entity; + newComponentMessage.componentID = componentID; + newComponentMessage.component = component; + SendMessage(newComponentMessage); + } + } + } +} \ No newline at end of file diff --git a/encompass-cs/Engines/Spawner.cs b/encompass-cs/Engines/Spawner.cs index b4c1901..da359e7 100644 --- a/encompass-cs/Engines/Spawner.cs +++ b/encompass-cs/Engines/Spawner.cs @@ -12,7 +12,7 @@ namespace Encompass.Engines readsAttribute.readTypes.Add(typeof(TMessage)); } - readTypes.Add(typeof(TMessage)); + receiveTypes.Add(typeof(TMessage)); } public override void Update(double dt) diff --git a/encompass-cs/Exceptions/IllegalWriteException.cs b/encompass-cs/Exceptions/IllegalSendException.cs similarity index 65% rename from encompass-cs/Exceptions/IllegalWriteException.cs rename to encompass-cs/Exceptions/IllegalSendException.cs index 4c7db90..3043369 100644 --- a/encompass-cs/Exceptions/IllegalWriteException.cs +++ b/encompass-cs/Exceptions/IllegalSendException.cs @@ -2,9 +2,9 @@ using System; namespace Encompass.Exceptions { - public class IllegalWriteException : Exception + public class IllegalSendException : Exception { - public IllegalWriteException( + public IllegalSendException( string format, params object[] args ) : base(string.Format(format, args)) { } diff --git a/encompass-cs/Exceptions/IllegalWriteTypeException.cs b/encompass-cs/Exceptions/IllegalSendTypeException.cs similarity index 63% rename from encompass-cs/Exceptions/IllegalWriteTypeException.cs rename to encompass-cs/Exceptions/IllegalSendTypeException.cs index 3c720b6..a374349 100644 --- a/encompass-cs/Exceptions/IllegalWriteTypeException.cs +++ b/encompass-cs/Exceptions/IllegalSendTypeException.cs @@ -2,9 +2,9 @@ using System; namespace Encompass.Exceptions { - public class IllegalWriteTypeException : Exception + public class IllegalSendTypeException : Exception { - public IllegalWriteTypeException( + public IllegalSendTypeException( string format, params object[] args ) : base(string.Format(format, args)) { } diff --git a/encompass-cs/NewComponentMessage.cs b/encompass-cs/NewComponentMessage.cs new file mode 100644 index 0000000..e0ca1a6 --- /dev/null +++ b/encompass-cs/NewComponentMessage.cs @@ -0,0 +1,11 @@ +using System; + +namespace Encompass +{ + public struct NewComponentMessage : IMessage where TComponent : struct, IComponent + { + public Entity entity; + public Guid componentID; + public TComponent component; + } +} \ No newline at end of file diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 6cd32c8..bf376e8 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -23,6 +23,7 @@ namespace Encompass private readonly HashSet senders = new HashSet(); private readonly HashSet registeredComponentTypes = new HashSet(); + private readonly HashSet registeredNewComponentTypes = new HashSet(); public WorldBuilder() { @@ -66,6 +67,12 @@ namespace Encompass AddEngine((Engine)Activator.CreateInstance(typeof(ComponentMessageEmitter<>).MakeGenericType(componentType))); } + internal void RegisterNewComponentEmitter(Type componentType) + { + registeredNewComponentTypes.Add(componentType); + AddEngine((Engine)Activator.CreateInstance(typeof(NewComponentMessageEmitter<>).MakeGenericType(componentType))); + } + public Engine AddEngine(TEngine engine) where TEngine : Engine { engine.AssignEntityManager(entityManager); @@ -75,15 +82,10 @@ namespace Encompass engines.Add(engine); engineGraph.AddVertex(engine); - foreach (var activateType in engine.activateTypes) - { - engine.sendTypes.Add(activateType); - } - - var messageReadTypes = engine.readTypes; + var messageReceiveTypes = engine.receiveTypes; var messageSendTypes = engine.sendTypes; - foreach (var messageType in messageReadTypes.Intersect(messageSendTypes)) + foreach (var messageType in messageReceiveTypes.Intersect(messageSendTypes)) { // ComponentMessages can safely self-cycle // this does introduce a gotcha though: if you AddComponent and then HasComponent or GetComponent you will receive a false negative @@ -99,23 +101,43 @@ namespace Encompass senders.Add(engine); } - foreach (var readType in engine.readTypes) + foreach (var receiveType in engine.receiveTypes) { - if (readType.IsGenericType && readType.GetGenericTypeDefinition() == typeof(ComponentMessage<>)) + if (receiveType.IsGenericType) { - var componentType = readType.GetGenericArguments().Single(); - if (!registeredComponentTypes.Contains(componentType)) + var genericTypeDefinition = receiveType.GetGenericTypeDefinition(); + if (genericTypeDefinition == typeof(ComponentMessage<>) || genericTypeDefinition == typeof(NewComponentMessage<>)) { - RegisterComponent(componentType); + var componentType = receiveType.GetGenericArguments().Single(); + if (!registeredComponentTypes.Contains(componentType)) + { + RegisterComponent(componentType); + } } } - if (!typeToReaders.ContainsKey(readType)) + if (!typeToReaders.ContainsKey(receiveType)) { - typeToReaders.Add(readType, new HashSet()); + typeToReaders.Add(receiveType, new HashSet()); } - typeToReaders[readType].Add(engine); + typeToReaders[receiveType].Add(engine); + } + + foreach (var sendType in engine.sendTypes) + { + if (sendType.IsGenericType) + { + var genericTypeDefinition = sendType.GetGenericTypeDefinition(); + if (genericTypeDefinition == typeof(ComponentMessage<>) || genericTypeDefinition == typeof(NewComponentMessage<>)) + { + var componentType = sendType.GetGenericArguments().Single(); + if (!registeredNewComponentTypes.Contains(componentType)) + { + RegisterNewComponentEmitter(componentType); + } + } + } } return engine; diff --git a/test/ComponentTest.cs b/test/ComponentTest.cs index e92750f..1fed047 100644 --- a/test/ComponentTest.cs +++ b/test/ComponentTest.cs @@ -24,7 +24,8 @@ namespace Tests static IEnumerable<(Guid, MockComponent)> gottenMockComponentIDPairs = Enumerable.Empty<(Guid, MockComponent)>(); static (Guid, MockComponent) gottenMockComponentIDPair; - [Reads(typeof(EntityMessage), typeof(MockComponent))] + [Receives(typeof(EntityMessage))] + [Reads(typeof(MockComponent))] class GetMockComponentEngine : Engine { public override void Update(double dt) @@ -42,7 +43,8 @@ namespace Tests public MockComponent mockComponent; } - [Reads(typeof(AddComponentTestMessage), typeof(MockComponent))] + [Receives(typeof(AddComponentTestMessage))] + [Reads(typeof(MockComponent))] class AddComponentTestEngine : Engine { public override void Update(double dt) @@ -109,7 +111,7 @@ namespace Tests } [Activates(typeof(MockComponent))] - [Reads(typeof(AddMockComponentMessage))] + [Receives(typeof(AddMockComponentMessage))] class AddMockComponentEngine : Engine { public override void Update(double dt) @@ -152,7 +154,8 @@ namespace Tests world.Update(0.01); } - [Reads(typeof(EntityMessage), typeof(MockComponent))] + [Receives(typeof(EntityMessage))] + [Reads(typeof(MockComponent))] class GetMockComponentsEngine : Engine { private Entity entity; @@ -264,7 +267,8 @@ namespace Tests public Entity entity; } - [Reads(typeof(HasComponentTestMessage), typeof(MockComponent))] + [Receives(typeof(HasComponentTestMessage))] + [Reads(typeof(MockComponent))] class HasComponentTestEngine : Engine { public override void Update(double dt) @@ -304,7 +308,8 @@ namespace Tests public Entity entity; } - [Reads(typeof(HasComponentWhenInactiveTestMessage), typeof(MockComponent))] + [Receives(typeof(HasComponentWhenInactiveTestMessage))] + [Reads(typeof(MockComponent))] class HasComponentWhenInactiveTestEngine : Engine { public override void Update(double dt) @@ -346,7 +351,7 @@ namespace Tests public Guid componentID; } - [Reads(typeof(RemoveComponentTestMessage))] + [Receives(typeof(RemoveComponentTestMessage))] class RemoveComponentTestEngine : Engine { public override void Update(double dt) @@ -358,7 +363,7 @@ namespace Tests } } - [Reads(typeof(RemoveComponentTestMessage))] + [Receives(typeof(RemoveComponentTestMessage))] [Sends(typeof(CheckHasMockComponentMessage))] class DoRemoveCheckEngine : Engine { @@ -421,7 +426,7 @@ namespace Tests } [Activates(typeof(MockComponent))] - [Reads(typeof(ActivateComponentMessage))] + [Receives(typeof(ActivateComponentMessage))] class ActivateComponentEngine : Engine { public override void Update(double dt) @@ -439,7 +444,7 @@ namespace Tests public bool shouldHaveComponent; } - [Reads(typeof(ActivateComponentMessage))] + [Receives(typeof(ActivateComponentMessage))] [Sends(typeof(CheckHasMockComponentMessage))] class DoActivateCheckEngine : Engine { @@ -462,7 +467,8 @@ namespace Tests } } - [Reads(typeof(CheckHasMockComponentMessage), typeof(MockComponent))] + [Receives(typeof(CheckHasMockComponentMessage))] + [Reads(typeof(MockComponent))] class CheckHasMockComponentEngine : Engine { public override void Update(double dt) @@ -508,7 +514,7 @@ namespace Tests public Guid componentID; } - [Reads(typeof(DeactivateComponentMessage))] + [Receives(typeof(DeactivateComponentMessage))] class DeactivateComponentEngine : Engine { public override void Update(double dt) @@ -520,7 +526,7 @@ namespace Tests } } - [Reads(typeof(DeactivateComponentMessage))] + [Receives(typeof(DeactivateComponentMessage))] [Sends(typeof(CheckHasMockComponentMessage))] class DoDeactivateCheckEngine : Engine { diff --git a/test/EngineTest.cs b/test/EngineTest.cs index 5715380..172d763 100644 --- a/test/EngineTest.cs +++ b/test/EngineTest.cs @@ -191,7 +191,7 @@ namespace Tests var world = worldBuilder.Build(); - var ex = Assert.Throws(() => world.Update(0.01f)); + var ex = Assert.Throws(() => world.Update(0.01f)); Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredUpdateComponentTestEngine tried to write undeclared Component MockComponent")); } @@ -212,7 +212,7 @@ namespace Tests } } - [Reads(typeof(MockMessage))] + [Receives(typeof(MockMessage))] public class MessageReadEngine : Engine { public override void Update(double dt) @@ -248,7 +248,7 @@ namespace Tests static IEnumerable emptyReadMessagesResult; - [Reads(typeof(MockMessage))] + [Receives(typeof(MockMessage))] class ReadMessagesWhenNoneExistEngine : Engine { public override void Update(double dt) @@ -278,7 +278,7 @@ namespace Tests var world = worldBuilder.Build(); - var ex = Assert.Throws(() => world.Update(0.01f)); + var ex = Assert.Throws(() => world.Update(0.01f)); Assert.That(ex.Message, Is.EqualTo("Engine UndeclaredMessageEmitEngine tried to write undeclared Message MockMessage")); } @@ -296,7 +296,7 @@ namespace Tests } } - [Reads(typeof(MockMessage))] + [Receives(typeof(MockMessage))] class SomeMessageTestEngine : Engine { public override void Update(double dt) @@ -666,7 +666,7 @@ namespace Tests public MockComponent mockComponent; } - [Reads(typeof(MockComponentUpdateMessage))] + [Receives(typeof(MockComponentUpdateMessage))] [Updates(typeof(MockComponent))] class RepeatUpdateEngine : Engine { diff --git a/test/WorldBuilderTest.cs b/test/WorldBuilderTest.cs index d7753e9..6daa5f5 100644 --- a/test/WorldBuilderTest.cs +++ b/test/WorldBuilderTest.cs @@ -13,7 +13,7 @@ namespace Tests struct AMessage : IMessage { } struct BMessage : IMessage { } - [Reads(typeof(AMessage))] + [Receives(typeof(AMessage))] [Sends(typeof(BMessage))] class AEngine : Engine { @@ -24,7 +24,7 @@ namespace Tests } } - [Reads(typeof(BMessage))] + [Receives(typeof(BMessage))] [Sends(typeof(AMessage))] class BEngine : Engine { @@ -53,7 +53,7 @@ namespace Tests struct CMessage : IMessage { } struct DMessage : IMessage { } - [Reads(typeof(AMessage))] + [Receives(typeof(AMessage))] [Sends(typeof(BMessage))] class AEngine : Engine { @@ -64,7 +64,7 @@ namespace Tests } } - [Reads(typeof(BMessage))] + [Receives(typeof(BMessage))] [Sends(typeof(CMessage))] class BEngine : Engine { @@ -75,7 +75,7 @@ namespace Tests } } - [Reads(typeof(CMessage))] + [Receives(typeof(CMessage))] [Sends(typeof(DMessage))] class CEngine : Engine { @@ -86,7 +86,7 @@ namespace Tests } } - [Reads(typeof(DMessage))] + [Receives(typeof(DMessage))] [Sends(typeof(AMessage))] class DEngine : Engine { @@ -141,7 +141,7 @@ namespace Tests { struct AMessage : IMessage { } - [Reads(typeof(AMessage))] + [Receives(typeof(AMessage))] [Sends(typeof(AMessage))] class AEngine : Engine { @@ -200,7 +200,7 @@ namespace Tests { var worldBuilder = new WorldBuilder(); - Assert.Throws(() => worldBuilder.AddEngine(new MyEngine()), "ANonMessage must be a Message or Component"); + Assert.Throws(() => worldBuilder.AddEngine(new MyEngine()), "ANonMessage must be a Message or Component"); } } @@ -234,7 +234,7 @@ namespace Tests } } - [Reads(typeof(AMessage), typeof(BMessage))] + [Receives(typeof(AMessage), typeof(BMessage))] [Sends(typeof(DMessage))] class CEngine : Engine { @@ -244,7 +244,7 @@ namespace Tests } } - [Reads(typeof(DMessage))] + [Receives(typeof(DMessage))] class DEngine : Engine { public override void Update(double dt)