diff --git a/Svelto.ECS/EntityViewsDB.cs b/Svelto.ECS/EntityViewsDB.cs index cca5551..e14f958 100644 --- a/Svelto.ECS/EntityViewsDB.cs +++ b/Svelto.ECS/EntityViewsDB.cs @@ -60,7 +60,7 @@ namespace Svelto.ECS.Internal return entityView; } - public bool EntityExists(EGID entityGID) where T : IEntityData + public bool Exists(EGID entityGID) where T : IEntityData { var type = typeof(T); @@ -83,13 +83,23 @@ namespace Svelto.ECS.Internal return false; } - - public bool TryQueryEntityView(EGID entityegid, out T entityView) where T : class, IEntityData + + public void Fetch(out T entity) where T : IEntityData + { + entity = QueryEntities()[0]; + } + + public bool Has() where T : IEntityData + { + return QueryEntities().Count > 0; + } + + public bool TryQueryEntityView(EGID entityegid, out T entityView) where T : IEntityData { return TryQueryEntityViewInGroup(entityegid, out entityView); } - bool TryQueryEntityViewInGroup(EGID entityGID, out T entityView) where T:class, IEntityData + bool TryQueryEntityViewInGroup(EGID entityGID, out T entityView) where T:IEntityData { var type = typeof(T); diff --git a/Svelto.ECS/IEntityViewsDB.cs b/Svelto.ECS/IEntityViewsDB.cs index 0711e1e..2541bc6 100644 --- a/Svelto.ECS/IEntityViewsDB.cs +++ b/Svelto.ECS/IEntityViewsDB.cs @@ -13,9 +13,11 @@ namespace Svelto.ECS T[] QueryEntitiesCacheFriendly(int group, out int count) where T : struct, IEntityData; //to use with EntityViews - bool TryQueryEntityView(EGID ID, out T entityView) where T : class, IEntityData; - T QueryEntityView(EGID entityGID) where T : class, IEntityData; + bool TryQueryEntityView(EGID egid, out T entityView) where T : IEntityData; + T QueryEntityView(EGID egid) where T : class, IEntityData; - bool EntityExists(EGID ID) where T : IEntityData; + bool Exists(EGID egid) where T : IEntityData; + void Fetch(out T entity) where T:IEntityData; + bool Has() where T:IEntityData; } } \ No newline at end of file diff --git a/Svelto.ECS/MultiEntitiesEngine.cs b/Svelto.ECS/MultiEntitiesEngine.cs index 9805cfa..709bb8c 100644 --- a/Svelto.ECS/MultiEntitiesEngine.cs +++ b/Svelto.ECS/MultiEntitiesEngine.cs @@ -1,7 +1,7 @@ namespace Svelto.ECS { - public abstract class MultiEntitiesEngine : SingleEntitiesEngine, IHandleEntityStructEngine - where U : struct, IEntityData where T : struct, IEntityData + public abstract class MultiEntitiesEngine : SingleEntityEngine, IHandleEntityStructEngine + where U : IEntityData where T : IEntityData { public void AddInternal(ref U entityView) { Add(ref entityView); } @@ -13,7 +13,7 @@ namespace Svelto.ECS } public abstract class MultiEntitiesEngine : MultiEntitiesEngine, IHandleEntityStructEngine - where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData + where V : IEntityData where U : IEntityData where T : IEntityData { public void AddInternal(ref V entityView) { Add(ref entityView); } @@ -30,7 +30,7 @@ namespace Svelto.ECS /// already too many responsabilities. /// public abstract class MultiEntitiesEngine : MultiEntitiesEngine, IHandleEntityStructEngine - where W : struct, IEntityData where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData + where W : IEntityData where V : IEntityData where U : IEntityData where T : IEntityData { public void AddInternal(ref W entityView) { Add(ref entityView); } diff --git a/Svelto.ECS/MultiEntityEngine.cs b/Svelto.ECS/MultiEntityEngine.cs deleted file mode 100644 index 062568b..0000000 --- a/Svelto.ECS/MultiEntityEngine.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Svelto.ECS -{ - public abstract class MultiEntityStructsEngine : SingleEntityStructEngine, IHandleEntityStructEngine - where U : struct, IEntityData where T : struct, IEntityData - { - public void AddInternal(ref U entityView) - { Add(ref entityView); } - public void RemoveInternal(ref U entityView) - { Remove(ref entityView); } - - protected abstract void Add(ref U entityView); - protected abstract void Remove(ref U entityView); - } - - public abstract class MultiEntityStructsEngine : MultiEntityViewsEngine, IHandleEntityStructEngine - where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData - { - public void AddInternal(ref V entityView) - { Add(ref entityView); } - public void RemoveInternal(ref V entityView) - { Remove(ref entityView); } - - protected abstract void Add(ref V entityView); - protected abstract void Remove(ref V entityView); - } - - /// - /// Please do not add more MultiEntityViewsEngine - /// if you use more than 4 nodes, your engine has - /// already too many responsabilities. - /// - public abstract class MultiEntityStructsEngine : MultiEntityViewsEngine, IHandleEntityStructEngine - where W : struct, IEntityData where V : struct, IEntityData where U : struct, IEntityData where T : struct, IEntityData - { - public void AddInternal(ref W entityView) - { Add(ref entityView); } - public void RemoveInternal(ref W entityView) - { Remove(ref entityView); } - - protected abstract void Add(ref W entityView); - protected abstract void Remove(ref W entityView); - } -} \ No newline at end of file diff --git a/Svelto.ECS/MultiEntityStructsEngine.cs b/Svelto.ECS/MultiEntityStructsEngine.cs deleted file mode 100644 index 2e501d4..0000000 --- a/Svelto.ECS/MultiEntityStructsEngine.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Svelto.ECS -{ - public abstract class MultiEntityStructsEngine : SingleEntityViewEngine, IHandleEntityStructEngine - where U : IEntityData where T : IEntityData - { - public void AddInternal(ref U entityView) - { Add(ref entityView); } - public void RemoveInternal(ref U entityView) - { Remove(ref entityView); } - - protected abstract void Add(ref U entityView); - protected abstract void Remove(ref U entityView); - } - - public abstract class MultiEntityStructsEngine : MultiEntityViewsEngine, IHandleEntityStructEngine - where V : IEntityData where U : IEntityData where T : IEntityData - { - public void AddInternal(ref V entityView) - { Add(ref entityView); } - public void RemoveInternal(ref V entityView) - { Remove(ref entityView); } - - protected abstract void Add(ref V entityView); - protected abstract void Remove(ref V entityView); - } - - /// - /// Please do not add more MultiEntityViewsEngine - /// if you use more than 4 nodes, your engine has - /// already too many responsabilities. - /// - public abstract class MultiEntityStructsEngine : MultiEntityViewsEngine, IHandleEntityStructEngine - where W : IEntityData where V : IEntityData where U : IEntityData where T : IEntityData - { - public void AddInternal(ref W entityView) - { Add(ref entityView); } - public void RemoveInternal(ref W entityView) - { Remove(ref entityView); } - - protected abstract void Add(ref W entityView); - protected abstract void Remove(ref W entityView); - } -} \ No newline at end of file diff --git a/Svelto.ECS/SingleEntitiesEngine.cs b/Svelto.ECS/SingleEntityEngine.cs similarity index 74% rename from Svelto.ECS/SingleEntitiesEngine.cs rename to Svelto.ECS/SingleEntityEngine.cs index 5924f2c..dbf0757 100644 --- a/Svelto.ECS/SingleEntitiesEngine.cs +++ b/Svelto.ECS/SingleEntityEngine.cs @@ -1,6 +1,6 @@ namespace Svelto.ECS { - public abstract class SingleEntitiesEngine : IHandleEntityStructEngine where T : struct, IEntityData + public abstract class SingleEntityEngine : IHandleEntityStructEngine where T : IEntityData { public void AddInternal(ref T entityView) { Add(ref entityView); }