fix some bugs with new replay structure

pull/5/head
Evan Hemsley 2019-12-29 17:37:19 -08:00
parent a8669a6c67
commit 4d47a60125
4 changed files with 28 additions and 12 deletions

View File

@ -47,6 +47,15 @@ namespace Encompass
return result; return result;
} }
public override void Remove(int entityID)
{
base.Remove(entityID);
foreach (var replayer in CurrentReplayers)
{
replayer.MarkRemoval(entityID);
}
}
public override void ClearAll() public override void ClearAll()
{ {
base.ClearAll(); base.ClearAll();

View File

@ -88,7 +88,7 @@ namespace Encompass
Lookup<TComponent>().ForceRemove(entityID); Lookup<TComponent>().ForceRemove(entityID);
} }
public void Remove(int entityID) public virtual void Remove(int entityID)
{ {
foreach (var entry in Stores.Values) foreach (var entry in Stores.Values)
{ {

View File

@ -34,11 +34,16 @@ namespace Encompass
upToDateComponentStore.RegisterComponentType<TComponent>(); upToDateComponentStore.RegisterComponentType<TComponent>();
} }
internal void SetComponentStore(ComponentStore componentStore) internal void SetExistingComponentStore(ComponentStore componentStore)
{ {
existingComponentStore.SwapWith(componentStore); existingComponentStore.SwapWith(componentStore);
} }
internal void SetUpToDateComponentStore(ComponentStore componentStore)
{
upToDateComponentStore.SwapWith(componentStore);
}
internal void RegisterDrawableComponent<TComponent>(int entityID, TComponent component, int layer) where TComponent : struct, IComponent internal void RegisterDrawableComponent<TComponent>(int entityID, TComponent component, int layer) where TComponent : struct, IComponent
{ {
drawLayerManager.RegisterComponentWithLayer(entityID, component, layer); drawLayerManager.RegisterComponentWithLayer(entityID, component, layer);
@ -46,7 +51,7 @@ namespace Encompass
internal void WriteComponents() internal void WriteComponents()
{ {
SetComponentStore(upToDateComponentStore); SetExistingComponentStore(upToDateComponentStore);
upToDateComponentStore.UpdateUsing(immediateComponentStore); upToDateComponentStore.UpdateUsing(immediateComponentStore);
immediateComponentStore.ClearAll(); immediateComponentStore.ClearAll();
} }
@ -209,6 +214,7 @@ namespace Encompass
foreach (var entityID in entitiesMarkedForRemoval) foreach (var entityID in entitiesMarkedForRemoval)
{ {
existingComponentStore.Remove(entityID); existingComponentStore.Remove(entityID);
immediateComponentStore.Remove(entityID);
upToDateComponentStore.Remove(entityID); upToDateComponentStore.Remove(entityID);
drawLayerManager.UnRegisterEntityWithLayer(entityID); drawLayerManager.UnRegisterEntityWithLayer(entityID);
} }

View File

@ -21,8 +21,8 @@ namespace Encompass
private readonly int entityCapacity; private readonly int entityCapacity;
private readonly List<Engine> engines = new List<Engine>(); private readonly List<Engine> engines = new List<Engine>();
private readonly DirectedGraph<Engine, Unit> engineGraph = GraphBuilder.DirectedGraph<Engine>(); private readonly DirectedGraph<Engine, Unit> engineGraph = GraphBuilder.DirectedGraph<Engine>();
private readonly ComponentStore startingComponentStoreForComponentManager; private readonly ComponentStore startingExistingComponentStore;
private readonly ComponentStore startingComponentStoreForComponentUpdateManager; private readonly ComponentStore startingUpToDateComponentStore;
private readonly ComponentManager componentManager; private readonly ComponentManager componentManager;
private readonly EntityManager entityManager; private readonly EntityManager entityManager;
@ -53,8 +53,8 @@ namespace Encompass
entityManager = new EntityManager(componentManager, entityCapacity); entityManager = new EntityManager(componentManager, entityCapacity);
renderManager = new RenderManager(entityManager, drawLayerManager); renderManager = new RenderManager(entityManager, drawLayerManager);
startingComponentStoreForComponentManager = new ComponentStore(typeToIndex); startingExistingComponentStore = new ComponentStore(typeToIndex);
startingComponentStoreForComponentUpdateManager = new ComponentStore(typeToIndex); startingUpToDateComponentStore = new ComponentStore(typeToIndex);
} }
/// <summary> /// <summary>
@ -89,8 +89,8 @@ namespace Encompass
RegisterComponentType<TComponent>(); RegisterComponentType<TComponent>();
componentTypesToRegister.Add(typeof(TComponent)); componentTypesToRegister.Add(typeof(TComponent));
startingComponentStoreForComponentManager.Set(entity.ID, component); startingExistingComponentStore.Set(entity.ID, component);
startingComponentStoreForComponentUpdateManager.Set(entity.ID, component); startingUpToDateComponentStore.Set(entity.ID, component);
if (component is IDrawableComponent drawableComponent) if (component is IDrawableComponent drawableComponent)
{ {
@ -105,8 +105,8 @@ namespace Encompass
{ {
typeToIndex.Add(typeof(TComponent), typeToIndex.Count); typeToIndex.Add(typeof(TComponent), typeToIndex.Count);
componentManager.RegisterComponentType<TComponent>(); componentManager.RegisterComponentType<TComponent>();
startingComponentStoreForComponentManager.RegisterComponentType<TComponent>(); startingExistingComponentStore.RegisterComponentType<TComponent>();
startingComponentStoreForComponentUpdateManager.RegisterComponentType<TComponent>(); startingUpToDateComponentStore.RegisterComponentType<TComponent>();
} }
} }
@ -391,7 +391,8 @@ namespace Encompass
renderManager renderManager
); );
componentManager.SetComponentStore(startingComponentStoreForComponentManager); componentManager.SetExistingComponentStore(startingExistingComponentStore);
componentManager.SetUpToDateComponentStore(startingUpToDateComponentStore);
trackingManager.InitializeTracking(entityManager.EntityIDs); trackingManager.InitializeTracking(entityManager.EntityIDs);