diff --git a/src/EntityComponentReader.cs b/src/EntityComponentReader.cs index f547518..82884ab 100644 --- a/src/EntityComponentReader.cs +++ b/src/EntityComponentReader.cs @@ -51,4 +51,9 @@ public abstract class EntityComponentReader { return ref ComponentDepot.GetEntity(); } + + protected bool Exists(in Entity entity) + { + return EntityStorage.Exists(entity); + } } diff --git a/src/EntityStorage.cs b/src/EntityStorage.cs index ebbed67..ccadb1a 100644 --- a/src/EntityStorage.cs +++ b/src/EntityStorage.cs @@ -9,6 +9,11 @@ internal class EntityStorage return new Entity(idStorage.NextID()); } + public bool Exists(in Entity entity) + { + return idStorage.Taken(entity.ID); + } + public void Destroy(in Entity entity) { idStorage.Release(entity.ID); diff --git a/src/IDStorage.cs b/src/IDStorage.cs index 011c274..c46e238 100644 --- a/src/IDStorage.cs +++ b/src/IDStorage.cs @@ -20,6 +20,11 @@ internal class IDStorage } } + public bool Taken(int id) + { + return !availableIDs.Contains(id) && id < nextID; + } + public void Release(int id) { availableIDs.Push(id);