diff --git a/encompass-cs/Collections/ComponentDeltaStore.cs b/encompass-cs/Collections/ComponentDeltaStore.cs index 958c3af..b4f5d89 100644 --- a/encompass-cs/Collections/ComponentDeltaStore.cs +++ b/encompass-cs/Collections/ComponentDeltaStore.cs @@ -47,6 +47,15 @@ namespace Encompass return result; } + public override void Remove(int entityID) + { + base.Remove(entityID); + foreach (var replayer in CurrentReplayers) + { + replayer.MarkRemoval(entityID); + } + } + public override void ClearAll() { base.ClearAll(); diff --git a/encompass-cs/Collections/ComponentStore.cs b/encompass-cs/Collections/ComponentStore.cs index 337f610..d879c4e 100644 --- a/encompass-cs/Collections/ComponentStore.cs +++ b/encompass-cs/Collections/ComponentStore.cs @@ -88,7 +88,7 @@ namespace Encompass Lookup().ForceRemove(entityID); } - public void Remove(int entityID) + public virtual void Remove(int entityID) { foreach (var entry in Stores.Values) { diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index f913e70..26836bd 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -34,11 +34,16 @@ namespace Encompass upToDateComponentStore.RegisterComponentType(); } - internal void SetComponentStore(ComponentStore componentStore) + internal void SetExistingComponentStore(ComponentStore componentStore) { existingComponentStore.SwapWith(componentStore); } + internal void SetUpToDateComponentStore(ComponentStore componentStore) + { + upToDateComponentStore.SwapWith(componentStore); + } + internal void RegisterDrawableComponent(int entityID, TComponent component, int layer) where TComponent : struct, IComponent { drawLayerManager.RegisterComponentWithLayer(entityID, component, layer); @@ -46,7 +51,7 @@ namespace Encompass internal void WriteComponents() { - SetComponentStore(upToDateComponentStore); + SetExistingComponentStore(upToDateComponentStore); upToDateComponentStore.UpdateUsing(immediateComponentStore); immediateComponentStore.ClearAll(); } @@ -209,6 +214,7 @@ namespace Encompass foreach (var entityID in entitiesMarkedForRemoval) { existingComponentStore.Remove(entityID); + immediateComponentStore.Remove(entityID); upToDateComponentStore.Remove(entityID); drawLayerManager.UnRegisterEntityWithLayer(entityID); } diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 5fae89a..368d694 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -21,8 +21,8 @@ namespace Encompass private readonly int entityCapacity; private readonly List engines = new List(); private readonly DirectedGraph engineGraph = GraphBuilder.DirectedGraph(); - private readonly ComponentStore startingComponentStoreForComponentManager; - private readonly ComponentStore startingComponentStoreForComponentUpdateManager; + private readonly ComponentStore startingExistingComponentStore; + private readonly ComponentStore startingUpToDateComponentStore; private readonly ComponentManager componentManager; private readonly EntityManager entityManager; @@ -53,8 +53,8 @@ namespace Encompass entityManager = new EntityManager(componentManager, entityCapacity); renderManager = new RenderManager(entityManager, drawLayerManager); - startingComponentStoreForComponentManager = new ComponentStore(typeToIndex); - startingComponentStoreForComponentUpdateManager = new ComponentStore(typeToIndex); + startingExistingComponentStore = new ComponentStore(typeToIndex); + startingUpToDateComponentStore = new ComponentStore(typeToIndex); } /// @@ -89,8 +89,8 @@ namespace Encompass RegisterComponentType(); componentTypesToRegister.Add(typeof(TComponent)); - startingComponentStoreForComponentManager.Set(entity.ID, component); - startingComponentStoreForComponentUpdateManager.Set(entity.ID, component); + startingExistingComponentStore.Set(entity.ID, component); + startingUpToDateComponentStore.Set(entity.ID, component); if (component is IDrawableComponent drawableComponent) { @@ -105,8 +105,8 @@ namespace Encompass { typeToIndex.Add(typeof(TComponent), typeToIndex.Count); componentManager.RegisterComponentType(); - startingComponentStoreForComponentManager.RegisterComponentType(); - startingComponentStoreForComponentUpdateManager.RegisterComponentType(); + startingExistingComponentStore.RegisterComponentType(); + startingUpToDateComponentStore.RegisterComponentType(); } } @@ -391,7 +391,8 @@ namespace Encompass renderManager ); - componentManager.SetComponentStore(startingComponentStoreForComponentManager); + componentManager.SetExistingComponentStore(startingExistingComponentStore); + componentManager.SetUpToDateComponentStore(startingUpToDateComponentStore); trackingManager.InitializeTracking(entityManager.EntityIDs);