From 323fb0e209d375ea964a7f5ec372863533ae4990 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 31 Mar 2022 16:15:30 -0700 Subject: [PATCH] add Exists API call to check if entity exists --- src/EntityComponentReader.cs | 5 +++++ src/EntityStorage.cs | 5 +++++ src/IDStorage.cs | 5 +++++ 3 files changed, 15 insertions(+) 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);