diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index 6aea1d0..49fe78d 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -113,6 +113,11 @@ namespace Encompass return _upToDateComponentStore.AllEntities(); } + internal ref readonly Entity ExistingOrImmediateSingularEntity() where TComponent : struct + { + return ref _upToDateComponentStore.SingularEntity(); + } + internal bool SomeExistingOrImmediateComponent() where TComponent : struct { return _upToDateComponentStore.Any(); @@ -135,7 +140,7 @@ namespace Encompass return _existingComponentStore.AllEntities(); } - internal ref readonly Entity SingularEntity() where TComponent : struct + internal ref readonly Entity ExistingSingularEntity() where TComponent : struct { return ref _existingComponentStore.SingularEntity(); } @@ -152,14 +157,19 @@ namespace Encompass return _immediateComponentStore.All(); } + internal ref readonly TComponent ImmediateSingular() where TComponent : struct + { + return ref _immediateComponentStore.Singular(); + } + internal Span GetImmediateEntities() where TComponent : struct { return _immediateComponentStore.AllEntities(); } - internal ref readonly TComponent ImmediateSingular() where TComponent : struct + internal ref readonly Entity ImmediateSingularEntity() where TComponent : struct { - return ref _immediateComponentStore.Singular(); + return ref _immediateComponentStore.SingularEntity(); } internal bool SomeImmediateComponent() where TComponent : struct diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 5fb740b..6428abc 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -210,23 +210,10 @@ namespace Encompass return _entityManager.EntityExists(entityID); } - /// - /// Returns an Entity containing the specified Component type. - /// - protected ref readonly Entity ReadEntity() where TComponent : struct - { - return ref _componentManager.SingularEntity(); - } - /// /// Returns all Entities containing the specified Component type. /// protected Span ReadEntities() where TComponent : struct - { - return ReadEntitiesHelper(); - } - - private Span ReadEntitiesHelper() where TComponent : struct { var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); var existingRead = ReadTypes.Contains(typeof(TComponent)); @@ -248,6 +235,31 @@ namespace Encompass } } + /// + /// Returns an Entity containing the specified Component type. + /// + protected ref readonly Entity ReadEntity() where TComponent : struct + { + var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); + var existingRead = ReadTypes.Contains(typeof(TComponent)); + if (existingRead && immediateRead) + { + return ref _componentManager.ExistingOrImmediateSingularEntity(); + } + else if (existingRead) + { + return ref _componentManager.ExistingSingularEntity(); + } + else if (immediateRead) + { + return ref _componentManager.ImmediateSingularEntity(); + } + else + { + throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name); + } + } + /// /// Returns all of the Components with the specified Component Type. /// diff --git a/encompass-cs/Renderer.cs b/encompass-cs/Renderer.cs index caad2f7..ccc8e59 100644 --- a/encompass-cs/Renderer.cs +++ b/encompass-cs/Renderer.cs @@ -25,7 +25,7 @@ namespace Encompass protected ref readonly Entity ReadEntity() where TComponent : struct { - return ref _componentManager.SingularEntity(); + return ref _componentManager.ExistingSingularEntity(); } protected Span ReadComponents() where TComponent : struct