add Exists API call to check if entity exists

pull/1/head
cosmonaut 2022-03-31 16:15:30 -07:00
parent 24455bcaed
commit 323fb0e209
3 changed files with 15 additions and 0 deletions

View File

@ -51,4 +51,9 @@ public abstract class EntityComponentReader
{
return ref ComponentDepot.GetEntity<TComponent>();
}
protected bool Exists(in Entity entity)
{
return EntityStorage.Exists(entity);
}
}

View File

@ -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);

View File

@ -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);