From 6f00191258aab2d416b1350683b59a304197c041 Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+ehemsley@users.noreply.github.com> Date: Sun, 29 Dec 2019 19:08:32 -0800 Subject: [PATCH] tightening up replay behavior --- .../Collections/ComponentDeltaStore.cs | 8 ++++++ encompass-cs/Collections/ComponentStore.cs | 3 ++- encompass-cs/ComponentManager.cs | 27 ++++++++++++------- test/ComponentTest.cs | 2 ++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/encompass-cs/Collections/ComponentDeltaStore.cs b/encompass-cs/Collections/ComponentDeltaStore.cs index b4f5d89..9b212d0 100644 --- a/encompass-cs/Collections/ComponentDeltaStore.cs +++ b/encompass-cs/Collections/ComponentDeltaStore.cs @@ -23,6 +23,14 @@ namespace Encompass } } + public override void Set(int entityID, TComponent component) + { + base.Set(entityID, component); + var replayer = _replayers[typeof(TComponent)]; + _currentReplayers.Add(replayer); + replayer.UnMarkRemoval(entityID); + } + public override bool Set(int entityID, TComponent component, int priority) { var result = base.Set(entityID, component, priority); diff --git a/encompass-cs/Collections/ComponentStore.cs b/encompass-cs/Collections/ComponentStore.cs index d879c4e..9097c52 100644 --- a/encompass-cs/Collections/ComponentStore.cs +++ b/encompass-cs/Collections/ComponentStore.cs @@ -57,7 +57,7 @@ namespace Encompass return Lookup().Get(entityID); } - public void Set(int entityID, TComponent component) where TComponent : struct, IComponent + public virtual void Set(int entityID, TComponent component) where TComponent : struct, IComponent { Lookup().Set(entityID, component); ComponentBitSet.Set(entityID); @@ -86,6 +86,7 @@ namespace Encompass public void ForceRemove(int entityID) where TComponent : struct, IComponent { Lookup().ForceRemove(entityID); + ComponentBitSet.RemoveComponent(entityID); } public virtual void Remove(int entityID) diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index 26836bd..93bd754 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -8,7 +8,8 @@ namespace Encompass private readonly DrawLayerManager drawLayerManager; private readonly ComponentStore existingComponentStore; - private readonly ComponentDeltaStore immediateComponentStore; + private readonly ComponentStore immediateComponentStore; + private readonly ComponentDeltaStore replayStore; private ComponentStore upToDateComponentStore; public Dictionary TypeToIndex { get; } @@ -22,7 +23,8 @@ namespace Encompass { this.drawLayerManager = drawLayerManager; existingComponentStore = new ComponentStore(typeToIndex); - immediateComponentStore = new ComponentDeltaStore(typeToIndex); + immediateComponentStore = new ComponentStore(typeToIndex); + replayStore = new ComponentDeltaStore(typeToIndex); upToDateComponentStore = new ComponentStore(typeToIndex); TypeToIndex = typeToIndex; } @@ -31,6 +33,7 @@ namespace Encompass { existingComponentStore.RegisterComponentType(); immediateComponentStore.RegisterComponentType(); + replayStore.RegisterComponentType(); upToDateComponentStore.RegisterComponentType(); } @@ -51,20 +54,16 @@ namespace Encompass internal void WriteComponents() { - SetExistingComponentStore(upToDateComponentStore); - upToDateComponentStore.UpdateUsing(immediateComponentStore); + existingComponentStore.UpdateUsing(replayStore); immediateComponentStore.ClearAll(); - } - - internal void AddExistingComponent(int entityID, TComponent component) where TComponent : struct, IComponent - { - upToDateComponentStore.Set(entityID, component); + replayStore.ClearAll(); } internal bool AddImmediateComponent(int entityID, TComponent component, int priority) where TComponent : struct, IComponent { if (immediateComponentStore.Set(entityID, component, priority)) { + replayStore.Set(entityID, component); upToDateComponentStore.Set(entityID, component); return true; } @@ -74,7 +73,12 @@ namespace Encompass public bool UpdateComponent(int entityID, TComponent component, int priority) where TComponent : struct, IComponent { - return upToDateComponentStore.Set(entityID, component, priority); + var result = upToDateComponentStore.Set(entityID, component, priority); + if (result) + { + replayStore.Set(entityID, component); + } + return result; } // existing or immediate reads @@ -215,6 +219,7 @@ namespace Encompass { existingComponentStore.Remove(entityID); immediateComponentStore.Remove(entityID); + replayStore.Remove(entityID); upToDateComponentStore.Remove(entityID); drawLayerManager.UnRegisterEntityWithLayer(entityID); } @@ -226,6 +231,7 @@ namespace Encompass { if (immediateComponentStore.Remove(entityID, priority)) { + replayStore.Remove(entityID, priority); upToDateComponentStore.Remove(entityID, priority); drawLayerManager.UnRegisterComponentWithLayer(entityID); return true; @@ -237,6 +243,7 @@ namespace Encompass { if (upToDateComponentStore.Remove(entityID, priority)) { + replayStore.Remove(entityID, priority); drawLayerManager.UnRegisterComponentWithLayer(entityID); } } diff --git a/test/ComponentTest.cs b/test/ComponentTest.cs index ce2fd5a..327869e 100644 --- a/test/ComponentTest.cs +++ b/test/ComponentTest.cs @@ -75,6 +75,7 @@ namespace Tests var world = worldBuilder.Build(); world.Update(0.01); + world.Update(0.01); } [Test] @@ -258,6 +259,7 @@ namespace Tests var world = worldBuilder.Build(); + world.Update(0.01); world.Update(0.01); Assert.AreEqual(mockComponent, gottenMockComponent);