diff --git a/encompass-cs/Attributes/ReadsImmediate.cs b/encompass-cs/Attributes/ReadsImmediate.cs new file mode 100644 index 0000000..e47d4ba --- /dev/null +++ b/encompass-cs/Attributes/ReadsImmediate.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Encompass.Exceptions; + +namespace Encompass +{ + [AttributeUsage(AttributeTargets.Class)] + public class ReadsImmediate : Attribute + { + public readonly HashSet readImmediateTypes = new HashSet(); + + public ReadsImmediate(params Type[] readImmediateTypes) + { + foreach (var readImmediateType in readImmediateTypes) + { + var isComponent = readImmediateType.GetInterfaces().Contains(typeof(IComponent)); + + if (!isComponent) + { + throw new IllegalReadTypeException("{0} must be a Component", readImmediateType.Name); + } + + this.readImmediateTypes.Add(readImmediateType); + } + } + } +} diff --git a/encompass-cs/Attributes/ReadsPending.cs b/encompass-cs/Attributes/ReadsPending.cs deleted file mode 100644 index e7e8653..0000000 --- a/encompass-cs/Attributes/ReadsPending.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Encompass.Exceptions; - -namespace Encompass -{ - [AttributeUsage(AttributeTargets.Class)] - public class ReadsPending : Attribute - { - public readonly HashSet readPendingTypes = new HashSet(); - - public ReadsPending(params Type[] readPendingTypes) - { - foreach (var readPendingType in readPendingTypes) - { - var isComponent = readPendingType.GetInterfaces().Contains(typeof(IComponent)); - - if (!isComponent) - { - throw new IllegalReadTypeException("{0} must be a Component", readPendingType.Name); - } - - this.readPendingTypes.Add(readPendingType); - } - } - } -} \ No newline at end of file diff --git a/encompass-cs/Attributes/WritesImmediate.cs b/encompass-cs/Attributes/WritesImmediate.cs new file mode 100644 index 0000000..66a46a6 --- /dev/null +++ b/encompass-cs/Attributes/WritesImmediate.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Encompass.Exceptions; + +namespace Encompass +{ + [AttributeUsage(AttributeTargets.Class)] + public class WritesImmediate : Attribute + { + public readonly HashSet writeImmediateTypes = new HashSet(); + + public WritesImmediate(params Type[] writeImmediateTypes) + { + foreach (var writeImmediateType in writeImmediateTypes) + { + var isComponent = writeImmediateType.GetInterfaces().Contains(typeof(IComponent)); + if (!isComponent) + { + throw new IllegalWriteImmediateTypeException("{0} must be a Component", writeImmediateType.Name); + } + + this.writeImmediateTypes.Add(writeImmediateType); + } + } + } +} diff --git a/encompass-cs/Attributes/WritesPending.cs b/encompass-cs/Attributes/WritesPending.cs deleted file mode 100644 index ea5a370..0000000 --- a/encompass-cs/Attributes/WritesPending.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Encompass.Exceptions; - -namespace Encompass -{ - public class WritesPending : Attribute - { - public readonly HashSet writePendingTypes = new HashSet(); - - public WritesPending(params Type[] writePendingTypes) - { - foreach (var writePendingType in writePendingTypes) - { - var isComponent = writePendingType.GetInterfaces().Contains(typeof(IComponent)); - if (!isComponent) - { - throw new IllegalWritePendingTypeException("{0} must be a Component", writePendingType.Name); - } - - this.writePendingTypes.Add(writePendingType); - } - } - } -} \ No newline at end of file diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index 959157b..c8c0cc9 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -87,9 +87,9 @@ namespace Encompass entitiesMarkedForRemoval.Clear(); } - public bool RemovePending(Entity entity, int priority) where TComponent : struct, IComponent + public bool RemoveImmediate(Entity entity, int priority) where TComponent : struct, IComponent { - if (componentUpdateManager.RemovePending(entity, priority)) + if (componentUpdateManager.RemoveImmediate(entity, priority)) { drawLayerManager.UnRegisterComponentWithLayer(entity.ID); return true; diff --git a/encompass-cs/ComponentUpdateManager.cs b/encompass-cs/ComponentUpdateManager.cs index 3f0173b..a2d9849 100644 --- a/encompass-cs/ComponentUpdateManager.cs +++ b/encompass-cs/ComponentUpdateManager.cs @@ -7,8 +7,7 @@ namespace Encompass internal class ComponentUpdateManager { private readonly ComponentStore existingComponentStore; - private readonly ComponentStore pendingComponentStore; - private readonly Dictionary> typeToEntityToPendingComponentPriority = new Dictionary>(128); + private readonly ComponentStore immediateComponentStore; public Dictionary TypeToIndex { get; } public ComponentStore UpToDateComponentStore { get; private set; } @@ -16,7 +15,7 @@ namespace Encompass public ComponentUpdateManager(Dictionary typeToIndex) { existingComponentStore = new ComponentStore(typeToIndex); - pendingComponentStore = new ComponentStore(typeToIndex); + immediateComponentStore = new ComponentStore(typeToIndex); UpToDateComponentStore = new ComponentStore(typeToIndex); TypeToIndex = typeToIndex; } @@ -24,20 +23,15 @@ namespace Encompass public void RegisterComponentType() where TComponent : struct, IComponent { existingComponentStore.RegisterComponentType(); - pendingComponentStore.RegisterComponentType(); + immediateComponentStore.RegisterComponentType(); UpToDateComponentStore.RegisterComponentType(); } internal void Clear() { existingComponentStore.ClearAll(); - pendingComponentStore.ClearAll(); + immediateComponentStore.ClearAll(); UpToDateComponentStore.ClearAll(); - - foreach (var dictionary in typeToEntityToPendingComponentPriority.Values) - { - dictionary.Clear(); - } } internal void SetStartingComponentStore(ComponentStore componentStore) @@ -47,26 +41,26 @@ namespace Encompass internal void AddExistingComponent(Entity entity, TComponent component) where TComponent : struct, IComponent { - RegisterExistingOrPendingComponentMessage(entity, component); + RegisterExistingOrImmediateComponentMessage(entity, component); existingComponentStore.Set(entity.ID, component); } - internal bool AddPendingComponent(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent + internal bool AddImmediateComponent(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent { - if (pendingComponentStore.Set(entity.ID, component, priority)) + if (immediateComponentStore.Set(entity.ID, component, priority)) { - RegisterExistingOrPendingComponentMessage(entity, component); + RegisterExistingOrImmediateComponentMessage(entity, component); return true; } return false; } - internal bool RemovePending(Entity entity, int priority) where TComponent : struct, IComponent + internal bool RemoveImmediate(Entity entity, int priority) where TComponent : struct, IComponent { UpToDateComponentStore.Remove(entity.ID, priority); - return pendingComponentStore.Remove(entity.ID, priority); + return immediateComponentStore.Remove(entity.ID, priority); } internal bool Remove(Entity entity, int priority) where TComponent : struct, IComponent @@ -74,7 +68,7 @@ namespace Encompass return UpToDateComponentStore.Remove(entity.ID, priority); } - private void RegisterExistingOrPendingComponentMessage(Entity entity, TComponent component) where TComponent : struct, IComponent + private void RegisterExistingOrImmediateComponentMessage(Entity entity, TComponent component) where TComponent : struct, IComponent { UpToDateComponentStore.Set(entity.ID, component); } @@ -86,7 +80,7 @@ namespace Encompass // general component reads by type - internal IEnumerable<(TComponent, int)> ReadExistingAndPendingComponentsByType() where TComponent : struct, IComponent + internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType() where TComponent : struct, IComponent { return UpToDateComponentStore.All(); } @@ -96,17 +90,17 @@ namespace Encompass return existingComponentStore.All(); } - internal IEnumerable<(TComponent, int)> ReadPendingComponentsByType() where TComponent : struct, IComponent + internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType() where TComponent : struct, IComponent { - return pendingComponentStore.All(); + return immediateComponentStore.All(); } // singular component reads by type - internal (TComponent, int) ReadFirstExistingOrPendingComponentByType() where TComponent : struct, IComponent + internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType() where TComponent : struct, IComponent { - if (!SomeExistingOrPendingComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } - var enumerator = ReadExistingAndPendingComponentsByType().GetEnumerator(); + if (!SomeExistingOrImmediateComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } + var enumerator = ReadExistingAndImmediateComponentsByType().GetEnumerator(); enumerator.MoveNext(); return enumerator.Current; } @@ -119,17 +113,17 @@ namespace Encompass return enumerator.Current; } - internal (TComponent, int) ReadFirstPendingComponentByType() where TComponent : struct, IComponent + internal (TComponent, int) ReadFirstImmediateComponentByType() where TComponent : struct, IComponent { - if (!SomePendingComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } - var enumerator = ReadPendingComponentsByType().GetEnumerator(); + if (!SomeImmediateComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } + var enumerator = ReadImmediateComponentsByType().GetEnumerator(); enumerator.MoveNext(); return enumerator.Current; } // check if some component of type exists in the world - internal bool SomeExistingOrPendingComponent() where TComponent : struct, IComponent + internal bool SomeExistingOrImmediateComponent() where TComponent : struct, IComponent { return UpToDateComponentStore.Any(); } @@ -139,9 +133,9 @@ namespace Encompass return existingComponentStore.Any(); } - internal bool SomePendingComponent() where TComponent : struct, IComponent + internal bool SomeImmediateComponent() where TComponent : struct, IComponent { - return pendingComponentStore.Any(); + return immediateComponentStore.Any(); } // read components by entity and type @@ -151,19 +145,19 @@ namespace Encompass return existingComponentStore.Get(entity.ID); } - internal TComponent ReadPendingComponentByEntityAndType(Entity entity) where TComponent : struct, IComponent + internal TComponent ReadImmediateComponentByEntityAndType(Entity entity) where TComponent : struct, IComponent { - return pendingComponentStore.Get(entity.ID); + return immediateComponentStore.Get(entity.ID); } // check if entity has component of type - internal bool HasExistingOrPendingComponent(Entity entity) where TComponent : struct, IComponent + internal bool HasExistingOrImmediateComponent(Entity entity) where TComponent : struct, IComponent { return UpToDateComponentStore.Has(entity.ID); } - internal bool HasExistingOrPendingComponent(Entity entity, Type type) + internal bool HasExistingOrImmediateComponent(Entity entity, Type type) { return UpToDateComponentStore.Has(type, entity.ID); } @@ -178,17 +172,17 @@ namespace Encompass return existingComponentStore.Has(type, entity.ID); } - internal bool HasPendingComponent(Entity entity) where TComponent : struct, IComponent + internal bool HasImmediateComponent(Entity entity) where TComponent : struct, IComponent { - return pendingComponentStore.Has(entity.ID); + return immediateComponentStore.Has(entity.ID); } - internal bool HasPendingComponent(Entity entity, Type type) + internal bool HasImmediateComponent(Entity entity, Type type) { - return pendingComponentStore.Has(type, entity.ID); + return immediateComponentStore.Has(type, entity.ID); } - internal ComponentBitSet PendingBits { get { return pendingComponentStore.ComponentBitSet; } } + internal ComponentBitSet ImmediateBits { get { return immediateComponentStore.ComponentBitSet; } } internal ComponentBitSet ExistingBits { get { return existingComponentStore.ComponentBitSet; } } } } diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 4a1033f..8d32f2d 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -17,11 +17,11 @@ namespace Encompass internal Guid ID; internal readonly HashSet readTypes = new HashSet(); - internal readonly HashSet readPendingTypes = new HashSet(); + internal readonly HashSet readImmediateTypes = new HashSet(); internal readonly HashSet sendTypes = new HashSet(); internal readonly HashSet receiveTypes = new HashSet(); internal readonly HashSet writeTypes = new HashSet(); - internal readonly HashSet writePendingTypes = new HashSet(); + internal readonly HashSet writeImmediateTypes = new HashSet(); internal readonly HashSet queryWithTypes = new HashSet(); internal readonly HashSet queryWithoutTypes = new HashSet(); internal readonly Dictionary writePriorities = new Dictionary(); @@ -51,10 +51,10 @@ namespace Encompass sendTypes = sendsAttribute.sendTypes; } - var activatesAttribute = GetType().GetCustomAttribute(false); + var activatesAttribute = GetType().GetCustomAttribute(false); if (activatesAttribute != null) { - writePendingTypes = activatesAttribute.writePendingTypes; + writeImmediateTypes = activatesAttribute.writeImmediateTypes; } var defaultWritePriorityAttribute = GetType().GetCustomAttribute(false); @@ -82,10 +82,10 @@ namespace Encompass readTypes = readsAttribute.readTypes; } - var readsPendingAttribute = GetType().GetCustomAttribute(false); - if (readsPendingAttribute != null) + var readsImmediateAttribute = GetType().GetCustomAttribute(false); + if (readsImmediateAttribute != null) { - readPendingTypes = readsPendingAttribute.readPendingTypes; + readImmediateTypes = readsImmediateAttribute.readImmediateTypes; } var queryWithAttribute = GetType().GetCustomAttribute(false); @@ -196,19 +196,19 @@ namespace Encompass private IEnumerable<(TComponent, int)> ReadComponentsHelper() where TComponent : struct, IComponent { - var pendingRead = readPendingTypes.Contains(typeof(TComponent)); + var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent)); - if (existingRead && pendingRead) + if (existingRead && immediateRead) { - return componentUpdateManager.ReadExistingAndPendingComponentsByType(); + return componentUpdateManager.ReadExistingAndImmediateComponentsByType(); } else if (existingRead) { return componentUpdateManager.ReadExistingComponentsByType(); } - else if (pendingRead) + else if (immediateRead) { - return componentUpdateManager.ReadPendingComponentsByType(); + return componentUpdateManager.ReadImmediateComponentsByType(); } else { @@ -248,19 +248,19 @@ namespace Encompass private (TComponent, int) ReadComponentHelper() where TComponent : struct, IComponent { - var pendingRead = readPendingTypes.Contains(typeof(TComponent)); + var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent)); - if (existingRead && pendingRead) + if (existingRead && immediateRead) { - return componentUpdateManager.ReadFirstExistingOrPendingComponentByType(); + return componentUpdateManager.ReadFirstExistingOrImmediateComponentByType(); } else if (existingRead) { return componentUpdateManager.ReadFirstExistingComponentByType(); } - else if (pendingRead) + else if (immediateRead) { - return componentUpdateManager.ReadFirstPendingComponentByType(); + return componentUpdateManager.ReadFirstImmediateComponentByType(); } else { @@ -290,19 +290,19 @@ namespace Encompass /// protected bool SomeComponent() where TComponent : struct, IComponent { - var pendingRead = readPendingTypes.Contains(typeof(TComponent)); + var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent)); - if (existingRead && pendingRead) + if (existingRead && immediateRead) { - return componentUpdateManager.SomeExistingOrPendingComponent(); + return componentUpdateManager.SomeExistingOrImmediateComponent(); } else if (existingRead) { return componentUpdateManager.SomeExistingComponent(); } - else if (pendingRead) + else if (immediateRead) { - return componentUpdateManager.SomePendingComponent(); + return componentUpdateManager.SomeImmediateComponent(); } else { @@ -312,13 +312,13 @@ namespace Encompass private TComponent GetComponentHelper(Entity entity) where TComponent : struct, IComponent { - var pendingRead = readPendingTypes.Contains(typeof(TComponent)); + var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent)); - if (existingRead && pendingRead) + if (existingRead && immediateRead) { - if (componentUpdateManager.HasPendingComponent(entity)) + if (componentUpdateManager.HasImmediateComponent(entity)) { - return componentUpdateManager.ReadPendingComponentByEntityAndType(entity); + return componentUpdateManager.ReadImmediateComponentByEntityAndType(entity); } else if (componentUpdateManager.HasExistingComponent(entity)) { @@ -333,9 +333,9 @@ namespace Encompass { return componentUpdateManager.ReadExistingComponentByEntityAndType(entity); } - else if (pendingRead) + else if (immediateRead) { - return componentUpdateManager.ReadPendingComponentByEntityAndType(entity); + return componentUpdateManager.ReadImmediateComponentByEntityAndType(entity); } else { @@ -365,20 +365,20 @@ namespace Encompass /// protected bool HasComponent(Entity entity) where TComponent : struct, IComponent { - var pendingRead = readPendingTypes.Contains(typeof(TComponent)); + var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent)); - if (pendingRead && existingRead) + if (immediateRead && existingRead) { - return componentUpdateManager.HasExistingOrPendingComponent(entity); + return componentUpdateManager.HasExistingOrImmediateComponent(entity); } else if (existingRead) { return componentUpdateManager.HasExistingComponent(entity); } - else if (pendingRead) + else if (immediateRead) { - return componentUpdateManager.HasPendingComponent(entity); + return componentUpdateManager.HasImmediateComponent(entity); } else { @@ -394,20 +394,20 @@ namespace Encompass /// protected bool HasComponent(Entity entity, Type type) { - var pendingRead = readPendingTypes.Contains(type); + var immediateRead = readImmediateTypes.Contains(type); var existingRead = readTypes.Contains(type); - if (pendingRead && existingRead) + if (immediateRead && existingRead) { - return componentUpdateManager.HasExistingOrPendingComponent(entity, type); + return componentUpdateManager.HasExistingOrImmediateComponent(entity, type); } else if (existingRead) { return componentUpdateManager.HasExistingComponent(entity, type); } - else if (pendingRead) + else if (immediateRead) { - return componentUpdateManager.HasPendingComponent(entity, type); + return componentUpdateManager.HasImmediateComponent(entity, type); } else { @@ -431,9 +431,9 @@ namespace Encompass } bool written; - if (writePendingTypes.Contains(typeof(TComponent))) + if (writeImmediateTypes.Contains(typeof(TComponent))) { - written = AddPendingComponent(entity, component, priority); + written = AddImmediateComponent(entity, component, priority); } else { @@ -485,9 +485,9 @@ namespace Encompass componentUpdateManager.AddExistingComponent(entity, component); } - internal bool AddPendingComponent(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent + internal bool AddImmediateComponent(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent { - return componentUpdateManager.AddPendingComponent(entity, component, priority); + return componentUpdateManager.AddImmediateComponent(entity, component, priority); } /// @@ -577,9 +577,9 @@ namespace Encompass throw new IllegalWriteException("Engine {0} tried to remove undeclared Component {1}. Declare with Writes attribute.", GetType().Name, typeof(TComponent).Name); } - if (writePendingTypes.Contains(typeof(TComponent))) + if (writeImmediateTypes.Contains(typeof(TComponent))) { - componentManager.RemovePending(entity, priority); + componentManager.RemoveImmediate(entity, priority); } else { @@ -649,7 +649,7 @@ namespace Encompass protected IEnumerable QueryEntities() { - foreach (var entity in entityQuery.FilterEntities(entityManager.Entities, componentUpdateManager.PendingBits, componentUpdateManager.ExistingBits)) + foreach (var entity in entityQuery.FilterEntities(entityManager.Entities, componentUpdateManager.ImmediateBits, componentUpdateManager.ExistingBits)) { yield return entity; } @@ -672,10 +672,10 @@ namespace Encompass withoutMask = withoutMask.Set(componentUpdateManager.TypeToIndex[type]); } - var pendingMask = BitSetBuilder.Zeroes(); - foreach (var type in readPendingTypes) + var immediateMask = BitSetBuilder.Zeroes(); + foreach (var type in readImmediateTypes) { - pendingMask = pendingMask.Set(componentUpdateManager.TypeToIndex[type]); + immediateMask = immediateMask.Set(componentUpdateManager.TypeToIndex[type]); } var existingMask = BitSetBuilder.Zeroes(); @@ -685,9 +685,9 @@ namespace Encompass } entityQuery = new EntitySetQuery( - withMask.And(pendingMask), + withMask.And(immediateMask), withMask.And(existingMask), - withoutMask.And(pendingMask), + withoutMask.And(immediateMask), withoutMask.And(existingMask), withMask.Not() ); diff --git a/encompass-cs/EntitySetQuery.cs b/encompass-cs/EntitySetQuery.cs index c13323b..afcd9ae 100644 --- a/encompass-cs/EntitySetQuery.cs +++ b/encompass-cs/EntitySetQuery.cs @@ -6,35 +6,35 @@ namespace Encompass { internal struct EntitySetQuery { - private BitSet WithPendingMask { get; } + private BitSet WithImmediateMask { get; } private BitSet WithExistingMask { get; } - private BitSet WithoutPendingMask { get; } + private BitSet WithoutImmediateMask { get; } private BitSet WithoutExistingMask { get; } private BitSet NotWithMask { get; } - internal EntitySetQuery(BitSet withPendingMask, BitSet withExistingMask, BitSet withoutPendingMask, BitSet withoutExistingMask, BitSet notWithMask) + internal EntitySetQuery(BitSet withImmediateMask, BitSet withExistingMask, BitSet withoutImmediateMask, BitSet withoutExistingMask, BitSet notWithMask) { - WithPendingMask = withPendingMask; + WithImmediateMask = withImmediateMask; WithExistingMask = withExistingMask; - WithoutPendingMask = withoutPendingMask; + WithoutImmediateMask = withoutImmediateMask; WithoutExistingMask = withoutExistingMask; NotWithMask = notWithMask; } - public IEnumerable FilterEntities(IEnumerable entities, ComponentBitSet pendingBitLookup, ComponentBitSet existingBitLookup) + public IEnumerable FilterEntities(IEnumerable entities, ComponentBitSet immediateBitLookup, ComponentBitSet existingBitLookup) { foreach (var entity in entities) { - var pendingBits = pendingBitLookup.EntityBitArray(entity.ID); + var immediateBits = immediateBitLookup.EntityBitArray(entity.ID); var existingBits = existingBitLookup.EntityBitArray(entity.ID); - var pending = WithPendingMask.And(pendingBits); + var immediate = WithImmediateMask.And(immediateBits); var existing = WithExistingMask.And(existingBits); - var withCheck = pending.Or(existing).Or(NotWithMask); + var withCheck = immediate.Or(existing).Or(NotWithMask); - var pendingForbidden = WithoutPendingMask.And(pendingBits).Not(); + var immediateForbidden = WithoutImmediateMask.And(immediateBits).Not(); var existingForbidden = WithoutExistingMask.And(existingBits).Not(); - var withoutCheck = pendingForbidden.And(existingForbidden); + var withoutCheck = immediateForbidden.And(existingForbidden); if (withCheck.And(withoutCheck).AllTrue()) { yield return entity; } } diff --git a/encompass-cs/Exceptions/IllegalWritePendingException.cs b/encompass-cs/Exceptions/IllegalWriteImmediateException.cs similarity index 56% rename from encompass-cs/Exceptions/IllegalWritePendingException.cs rename to encompass-cs/Exceptions/IllegalWriteImmediateException.cs index 3983c23..3d991af 100644 --- a/encompass-cs/Exceptions/IllegalWritePendingException.cs +++ b/encompass-cs/Exceptions/IllegalWriteImmediateException.cs @@ -1,10 +1,10 @@ -using System; +using System; namespace Encompass.Exceptions { - public class IllegalWritePendingException : Exception + public class IllegalWriteImmediateException : Exception { - public IllegalWritePendingException( + public IllegalWriteImmediateException( string format, params object[] args ) : base(string.Format(format, args)) { } diff --git a/encompass-cs/Exceptions/IllegalWritePendingTypeException.cs b/encompass-cs/Exceptions/IllegalWritePendingTypeException.cs index 19554be..3d388f0 100644 --- a/encompass-cs/Exceptions/IllegalWritePendingTypeException.cs +++ b/encompass-cs/Exceptions/IllegalWritePendingTypeException.cs @@ -2,9 +2,9 @@ using System; namespace Encompass.Exceptions { - public class IllegalWritePendingTypeException : Exception + public class IllegalWriteImmediateTypeException : Exception { - public IllegalWritePendingTypeException( + public IllegalWriteImmediateTypeException( string format, params object[] args ) : base(string.Format(format, args)) { } diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 2a1c782..e18bec1 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -141,9 +141,9 @@ namespace Encompass RegisterMessageTypes(engine.receiveTypes.Union(engine.sendTypes)); - foreach (var writePendingType in engine.writePendingTypes.Intersect(engine.readPendingTypes)) + foreach (var writeImmediateType in engine.writeImmediateTypes.Intersect(engine.readImmediateTypes)) { - throw new EngineSelfCycleException("Engine {0} both writes and reads pending Component {1}", engine.GetType().Name, writePendingType.Name); + throw new EngineSelfCycleException("Engine {0} both writes and reads immediate Component {1}", engine.GetType().Name, writeImmediateType.Name); } foreach (var messageType in messageReceiveTypes.Intersect(messageSendTypes)) @@ -151,17 +151,17 @@ namespace Encompass throw new EngineSelfCycleException("Engine {0} both receives and sends Message {1}", engine.GetType().Name, messageType.Name); } - if (messageSendTypes.Count > 0 || engine.writePendingTypes.Count > 0) + if (messageSendTypes.Count > 0 || engine.writeImmediateTypes.Count > 0) { senders.Add(engine); } - foreach (var componentType in engine.readTypes.Union(engine.writeTypes).Union(engine.readPendingTypes)) + foreach (var componentType in engine.readTypes.Union(engine.writeTypes).Union(engine.readImmediateTypes)) { AddComponentTypeToRegister(componentType); } - foreach (var receiveType in engine.receiveTypes.Union(engine.readPendingTypes)) + foreach (var receiveType in engine.receiveTypes.Union(engine.readImmediateTypes)) { if (!typeToReaders.ContainsKey(receiveType)) { @@ -214,7 +214,7 @@ namespace Encompass { foreach (var senderEngine in senders) { - foreach (var messageType in senderEngine.sendTypes.Union(senderEngine.writePendingTypes)) + foreach (var messageType in senderEngine.sendTypes.Union(senderEngine.writeImmediateTypes)) { if (typeToReaders.ContainsKey(messageType)) { diff --git a/test/ComponentTest.cs b/test/ComponentTest.cs index c7c1c78..ce2fd5a 100644 --- a/test/ComponentTest.cs +++ b/test/ComponentTest.cs @@ -97,7 +97,7 @@ namespace Tests } [Reads(typeof(MockComponent))] - [WritesPending(typeof(MockComponent))] + [WritesImmediate(typeof(MockComponent))] [Writes(typeof(MockComponent))] class OverwriteEngine : Engine { @@ -110,7 +110,7 @@ namespace Tests } } - [ReadsPending(typeof(MockComponent))] + [ReadsImmediate(typeof(MockComponent))] [Reads(typeof(MockComponent))] class ReadMockComponentEngine : Engine { @@ -193,7 +193,7 @@ namespace Tests } } - [WritesPending(typeof(MockComponent))] + [WritesImmediate(typeof(MockComponent))] [Receives(typeof(AddMockComponentMessage))] [Writes(typeof(MockComponent))] class AddMockComponentEngine : Engine @@ -207,7 +207,7 @@ namespace Tests } } - [ReadsPending(typeof(MockComponent))] + [ReadsImmediate(typeof(MockComponent))] class HasMockComponentEngine : Engine { private Entity entity; @@ -464,8 +464,8 @@ namespace Tests } [Receives(typeof(CheckHasMockComponentMessage))] - [ReadsPending(typeof(MockComponent))] - class CheckHasPendingMockComponentEngine : Engine + [ReadsImmediate(typeof(MockComponent))] + class CheckHasImmediateMockComponentEngine : Engine { public override void Update(double dt) { diff --git a/test/EngineTest.cs b/test/EngineTest.cs index 3fc6a9a..fe174c8 100644 --- a/test/EngineTest.cs +++ b/test/EngineTest.cs @@ -625,7 +625,7 @@ namespace Tests } [Reads(typeof(MockComponent))] - [WritesPending(typeof(MockComponent))] + [WritesImmediate(typeof(MockComponent))] [Writes(typeof(MockComponent))] class AddAndRemoveMockComponentEngine : Engine { @@ -641,8 +641,8 @@ namespace Tests static Entity entityResult; - [ReadsPending(typeof(MockComponent))] - class GetEntityFromPendingReadComponents : Engine + [ReadsImmediate(typeof(MockComponent))] + class GetEntityFromImmediateReadComponents : Engine { public override void Update(double dt) { @@ -651,11 +651,11 @@ namespace Tests } [Test] - public void GetEntityFromPendingComponentID() + public void GetEntityFromImmediateComponentID() { var worldBuilder = new WorldBuilder(); worldBuilder.AddEngine(new AddAndRemoveMockComponentEngine()); - worldBuilder.AddEngine(new GetEntityFromPendingReadComponents()); + worldBuilder.AddEngine(new GetEntityFromImmediateReadComponents()); var entity = worldBuilder.CreateEntity(); worldBuilder.SetComponent(entity, new MockComponent()); @@ -756,7 +756,7 @@ namespace Tests } [Receives(typeof(MockMessage))] - [WritesPending(typeof(MockComponent))] + [WritesImmediate(typeof(MockComponent))] [Writes(typeof(MockComponent), 1)] class ActivateComponentEngine : Engine { @@ -770,7 +770,7 @@ namespace Tests } } - [ReadsPending(typeof(MockComponent))] + [ReadsImmediate(typeof(MockComponent))] [Writes(typeof(MockComponent), 0)] class RemoveComponentEngine : Engine { @@ -1251,9 +1251,9 @@ namespace Tests } [Reads(typeof(MockComponent))] - [WritesPending(typeof(MockComponentB))] + [WritesImmediate(typeof(MockComponentB))] [Writes(typeof(MockComponentB), 0)] - class AddPendingComponentEngine : Engine + class AddImmediateComponentEngine : Engine { public override void Update(double dt) { @@ -1264,13 +1264,13 @@ namespace Tests } } - [ReadsPending(typeof(MockComponentB))] + [ReadsImmediate(typeof(MockComponentB))] [QueryWith(typeof(MockComponentB))] - class EntityQueryWithPendingComponentsEngine : Engine + class EntityQueryWithImmediateComponentsEngine : Engine { private List entities; - public EntityQueryWithPendingComponentsEngine(List entities) + public EntityQueryWithImmediateComponentsEngine(List entities) { this.entities = entities; } @@ -1283,7 +1283,7 @@ namespace Tests } [Test] - public void EntitiesWithPendingComponents() + public void EntitiesWithImmediateComponents() { var worldBuilder = new WorldBuilder(); @@ -1293,8 +1293,8 @@ namespace Tests worldBuilder.SetComponent(entity, new MockComponent()); var queriedEntities = new List(); - worldBuilder.AddEngine(new AddPendingComponentEngine()); - worldBuilder.AddEngine(new EntityQueryWithPendingComponentsEngine(queriedEntities)); + worldBuilder.AddEngine(new AddImmediateComponentEngine()); + worldBuilder.AddEngine(new EntityQueryWithImmediateComponentsEngine(queriedEntities)); var world = worldBuilder.Build(); @@ -1303,13 +1303,13 @@ namespace Tests queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entity }); } - [ReadsPending(typeof(MockComponentB))] + [ReadsImmediate(typeof(MockComponentB))] [QueryWithout(typeof(MockComponentB))] - class EntityQueryWithoutPendingComponentsEngine : Engine + class EntityQueryWithoutImmediateComponentsEngine : Engine { private List entities; - public EntityQueryWithoutPendingComponentsEngine(List entities) + public EntityQueryWithoutImmediateComponentsEngine(List entities) { this.entities = entities; } @@ -1322,7 +1322,7 @@ namespace Tests } [Test] - public void EntitiesWithoutPendingComponents() + public void EntitiesWithoutImmediateComponents() { var worldBuilder = new WorldBuilder(); @@ -1332,8 +1332,8 @@ namespace Tests worldBuilder.SetComponent(entity, new MockComponent()); var queriedEntities = new List(); - worldBuilder.AddEngine(new AddPendingComponentEngine()); - worldBuilder.AddEngine(new EntityQueryWithoutPendingComponentsEngine(queriedEntities)); + worldBuilder.AddEngine(new AddImmediateComponentEngine()); + worldBuilder.AddEngine(new EntityQueryWithoutImmediateComponentsEngine(queriedEntities)); var world = worldBuilder.Build(); @@ -1343,10 +1343,10 @@ namespace Tests } [Reads(typeof(MockComponentC), typeof(MockComponentD))] - [WritesPending(typeof(MockComponent), typeof(MockComponentB))] + [WritesImmediate(typeof(MockComponent), typeof(MockComponentB))] [Writes(typeof(MockComponent), 0)] [Writes(typeof(MockComponentB), 0)] - class ConditionallyAddPendingComponentsEngine : Engine + class ConditionallyAddImmediateComponentsEngine : Engine { public override void Update(double dt) { @@ -1363,14 +1363,14 @@ namespace Tests } } - [ReadsPending(typeof(MockComponent), typeof(MockComponentB))] + [ReadsImmediate(typeof(MockComponent), typeof(MockComponentB))] [QueryWith(typeof(MockComponent))] [QueryWithout(typeof(MockComponentB))] - class EntityQueryWithAndWithoutPendingComponentsEngine : Engine + class EntityQueryWithAndWithoutImmediateComponentsEngine : Engine { private List entities; - public EntityQueryWithAndWithoutPendingComponentsEngine(List entities) + public EntityQueryWithAndWithoutImmediateComponentsEngine(List entities) { this.entities = entities; } @@ -1384,7 +1384,7 @@ namespace Tests } [Test] - public void EntitiesWithAndWithoutPendingComponents() + public void EntitiesWithAndWithoutImmediateComponents() { var worldBuilder = new WorldBuilder(); @@ -1396,8 +1396,8 @@ namespace Tests worldBuilder.SetComponent(entityC, new MockComponentD()); var queriedEntities = new List(); - worldBuilder.AddEngine(new ConditionallyAddPendingComponentsEngine()); - worldBuilder.AddEngine(new EntityQueryWithAndWithoutPendingComponentsEngine(queriedEntities)); + worldBuilder.AddEngine(new ConditionallyAddImmediateComponentsEngine()); + worldBuilder.AddEngine(new EntityQueryWithAndWithoutImmediateComponentsEngine(queriedEntities)); var world = worldBuilder.Build(); @@ -1407,9 +1407,9 @@ namespace Tests } [Reads(typeof(MockComponentC))] - [WritesPending(typeof(MockComponentB))] + [WritesImmediate(typeof(MockComponentB))] [Writes(typeof(MockComponentB), 0)] - class ConditionallyAddPendingComponentEngine : Engine + class ConditionallyAddImmediateComponentEngine : Engine { public override void Update(double dt) { @@ -1420,14 +1420,14 @@ namespace Tests } } - [ReadsPending(typeof(MockComponentB))] + [ReadsImmediate(typeof(MockComponentB))] [Reads(typeof(MockComponent))] [QueryWith(typeof(MockComponent), typeof(MockComponentB))] - class EntityQueryWithPendingAndNonPendingComponents : Engine + class EntityQueryWithImmediateAndNonImmediateComponents : Engine { private List entities; - public EntityQueryWithPendingAndNonPendingComponents(List entities) + public EntityQueryWithImmediateAndNonImmediateComponents(List entities) { this.entities = entities; } @@ -1440,7 +1440,7 @@ namespace Tests } [Test] - public void EntitiesWithPendingAndNonPendingComponents() + public void EntitiesWithImmediateAndNonImmediateComponents() { var worldBuilder = new WorldBuilder(); @@ -1453,8 +1453,8 @@ namespace Tests worldBuilder.SetComponent(entityC, new MockComponentD()); var queriedEntities = new List(); - worldBuilder.AddEngine(new ConditionallyAddPendingComponentEngine()); - worldBuilder.AddEngine(new EntityQueryWithPendingAndNonPendingComponents(queriedEntities)); + worldBuilder.AddEngine(new ConditionallyAddImmediateComponentEngine()); + worldBuilder.AddEngine(new EntityQueryWithImmediateAndNonImmediateComponents(queriedEntities)); var world = worldBuilder.Build(); diff --git a/test/SpawnerTest.cs b/test/SpawnerTest.cs index a7f8158..c0c5f0c 100644 --- a/test/SpawnerTest.cs +++ b/test/SpawnerTest.cs @@ -19,7 +19,7 @@ namespace Tests } } - [WritesPending(typeof(TestComponent))] + [WritesImmediate(typeof(TestComponent))] [Writes(typeof(TestComponent))] class TestSpawner : Spawner { diff --git a/test/WorldBuilderTest.cs b/test/WorldBuilderTest.cs index 8e75f8a..2fd62fd 100644 --- a/test/WorldBuilderTest.cs +++ b/test/WorldBuilderTest.cs @@ -153,7 +153,7 @@ namespace Tests [Receives(typeof(SetMessage))] [Writes(typeof(AComponent), 0)] - [WritesPending(typeof(AComponent))] + [WritesImmediate(typeof(AComponent))] class AEngine : Engine { public override void Update(double dt) @@ -167,7 +167,7 @@ namespace Tests [Receives(typeof(SetMessage))] [Writes(typeof(AComponent), 1)] - [WritesPending(typeof(AComponent))] + [WritesImmediate(typeof(AComponent))] class BEngine : Engine { public override void Update(double dt) @@ -181,7 +181,7 @@ namespace Tests static AComponent resultComponent; - [ReadsPending(typeof(AComponent))] + [ReadsImmediate(typeof(AComponent))] class ReadComponentEngine : Engine { public override void Update(double dt) @@ -222,7 +222,7 @@ namespace Tests [Receives(typeof(SetMessage))] [Writes(typeof(AComponent))] - [WritesPending(typeof(AComponent))] + [WritesImmediate(typeof(AComponent))] [Encompass.DefaultWritePriority(4)] class AEngine : Engine { @@ -238,7 +238,7 @@ namespace Tests [Receives(typeof(SetMessage))] [Writes(typeof(AComponent), 3)] - [WritesPending(typeof(AComponent))] + [WritesImmediate(typeof(AComponent))] class BEngine : Engine { public override void Update(double dt) @@ -252,7 +252,7 @@ namespace Tests [Receives(typeof(SetMessage))] [Writes(typeof(AComponent), 2)] - [WritesPending(typeof(AComponent))] + [WritesImmediate(typeof(AComponent))] class CEngine : Engine { public override void Update(double dt) @@ -266,7 +266,7 @@ namespace Tests static AComponent resultComponent; - [ReadsPending(typeof(AComponent))] + [ReadsImmediate(typeof(AComponent))] class ReadComponentEngine : Engine { public override void Update(double dt)