From b5e28ae69f599e6fb14630dbfa301daee22eac4e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 21 Jul 2023 14:41:53 -0700 Subject: [PATCH] add World.Clear --- src/FilterStorage.cs | 9 +++++++++ src/World.cs | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/FilterStorage.cs b/src/FilterStorage.cs index 804ed93..aad179b 100644 --- a/src/FilterStorage.cs +++ b/src/FilterStorage.cs @@ -171,6 +171,15 @@ namespace MoonTools.ECS } } + // used by World.Clear, ignores callbacks + public void Clear() + { + foreach (var (filterSignature, entityIDs) in filterSignatureToEntityIDs) + { + entityIDs.Clear(); + } + } + public void RegisterAddCallback(FilterSignature filterSignature, Action callback) { addCallbacks.Add(filterSignature, callback); diff --git a/src/World.cs b/src/World.cs index 81a8ca5..79fa68f 100644 --- a/src/World.cs +++ b/src/World.cs @@ -14,14 +14,11 @@ namespace MoonTools.ECS internal readonly FilterStorage FilterStorage; public FilterBuilder FilterBuilder => new FilterBuilder(FilterStorage, ComponentTypeIndices); - internal readonly ComponentDepot TemplateComponentDepot; - public World() { ComponentDepot = new ComponentDepot(ComponentTypeIndices); RelationDepot = new RelationDepot(RelationTypeIndices); FilterStorage = new FilterStorage(EntityStorage, ComponentTypeIndices); - TemplateComponentDepot = new ComponentDepot(ComponentTypeIndices); } public Entity CreateEntity(string tag = "") @@ -148,6 +145,15 @@ namespace MoonTools.ECS MessageDepot.Clear(); } + public void Clear() + { + EntityStorage.Clear(); + MessageDepot.Clear(); + RelationDepot.Clear(); + ComponentDepot.Clear(); + FilterStorage.Clear(); + } + private Dictionary WorldToTransferID = new Dictionary(); // FIXME: there's probably a better way to handle Filters so they are not world-bound