From 02932636847e54d9c988722db4a8a328e8041c67 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Thu, 5 Dec 2019 15:14:28 -0800 Subject: [PATCH] fix component updates --- encompass-cs/ComponentManager.cs | 5 +++-- encompass-cs/ComponentMessageManager.cs | 15 ++++++++++++++- encompass-cs/Engine.cs | 4 ++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index 3459991..6ffb8a6 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -37,7 +37,7 @@ namespace Encompass internal void WriteComponents() { - componentStore.SwapWith(componentMessageManager.ComponentStore); + componentStore.SwapWith(componentMessageManager.UpToDateComponentStore); } internal IEnumerable<(TComponent, Entity)> GetComponentsIncludingEntity() where TComponent : struct, IComponent @@ -83,7 +83,8 @@ namespace Encompass public void Remove(Entity entity) where TComponent : struct, IComponent { - componentStore.Remove(entity); + //componentStore.Remove(entity); + componentMessageManager.Remove(entity); } private void Remove(Entity entity) diff --git a/encompass-cs/ComponentMessageManager.cs b/encompass-cs/ComponentMessageManager.cs index 5747795..06137b9 100644 --- a/encompass-cs/ComponentMessageManager.cs +++ b/encompass-cs/ComponentMessageManager.cs @@ -11,16 +11,18 @@ namespace Encompass private readonly ComponentStore existingComponentStore = new ComponentStore(); private readonly ComponentStore pendingComponentStore = new ComponentStore(); + private readonly ComponentStore upToDateComponentStore = new ComponentStore(); private readonly Dictionary> typeToEntityToPendingComponentPriority = new Dictionary>(); - public ComponentStore ComponentStore { get => componentStore; } + public ComponentStore UpToDateComponentStore { get => upToDateComponentStore; } internal void ClearMessages() { componentStore.ClearAll(); existingComponentStore.ClearAll(); pendingComponentStore.ClearAll(); + upToDateComponentStore.ClearAll(); foreach (var dictionary in typeToEntityToPendingComponentPriority.Values) { @@ -46,6 +48,12 @@ namespace Encompass private void RegisterExistingOrPendingComponentMessage(Entity entity, TComponent component) where TComponent : struct, IComponent { componentStore.Set(entity, component); + upToDateComponentStore.Set(entity, component); + } + + public void UpdateComponent(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent + { + upToDateComponentStore.Set(entity, component, priority); } // general component reads by type @@ -145,5 +153,10 @@ namespace Encompass { return pendingComponentStore.Has(type, entity); } + + internal void Remove(Entity entity) where TComponent : struct, IComponent + { + upToDateComponentStore.Remove(entity); + } } } diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index a910a52..8387b4d 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -415,6 +415,10 @@ namespace Encompass newComponentMessage.priority = priority; SendPendingComponentMessage(newComponentMessage); } + else + { + componentMessageManager.UpdateComponent(entity, component, priority); + } if (component is IDrawableComponent drawableComponent) {