add World.Clear

set_order
cosmonaut 2023-07-21 14:41:53 -07:00
parent 4d45d05618
commit b5e28ae69f
2 changed files with 18 additions and 3 deletions

View File

@ -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<Entity> callback) public void RegisterAddCallback(FilterSignature filterSignature, Action<Entity> callback)
{ {
addCallbacks.Add(filterSignature, callback); addCallbacks.Add(filterSignature, callback);

View File

@ -14,14 +14,11 @@ namespace MoonTools.ECS
internal readonly FilterStorage FilterStorage; internal readonly FilterStorage FilterStorage;
public FilterBuilder FilterBuilder => new FilterBuilder(FilterStorage, ComponentTypeIndices); public FilterBuilder FilterBuilder => new FilterBuilder(FilterStorage, ComponentTypeIndices);
internal readonly ComponentDepot TemplateComponentDepot;
public World() public World()
{ {
ComponentDepot = new ComponentDepot(ComponentTypeIndices); ComponentDepot = new ComponentDepot(ComponentTypeIndices);
RelationDepot = new RelationDepot(RelationTypeIndices); RelationDepot = new RelationDepot(RelationTypeIndices);
FilterStorage = new FilterStorage(EntityStorage, ComponentTypeIndices); FilterStorage = new FilterStorage(EntityStorage, ComponentTypeIndices);
TemplateComponentDepot = new ComponentDepot(ComponentTypeIndices);
} }
public Entity CreateEntity(string tag = "") public Entity CreateEntity(string tag = "")
@ -148,6 +145,15 @@ namespace MoonTools.ECS
MessageDepot.Clear(); MessageDepot.Clear();
} }
public void Clear()
{
EntityStorage.Clear();
MessageDepot.Clear();
RelationDepot.Clear();
ComponentDepot.Clear();
FilterStorage.Clear();
}
private Dictionary<int, int> WorldToTransferID = new Dictionary<int, int>(); private Dictionary<int, int> WorldToTransferID = new Dictionary<int, int>();
// FIXME: there's probably a better way to handle Filters so they are not world-bound // FIXME: there's probably a better way to handle Filters so they are not world-bound