fix component updates

pull/5/head
Evan Hemsley 2019-12-05 15:14:28 -08:00
parent 5513402573
commit 0293263684
3 changed files with 21 additions and 3 deletions

View File

@ -37,7 +37,7 @@ namespace Encompass
internal void WriteComponents()
{
componentStore.SwapWith(componentMessageManager.ComponentStore);
componentStore.SwapWith(componentMessageManager.UpToDateComponentStore);
}
internal IEnumerable<(TComponent, Entity)> GetComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent
@ -83,7 +83,8 @@ namespace Encompass
public void Remove<TComponent>(Entity entity) where TComponent : struct, IComponent
{
componentStore.Remove<TComponent>(entity);
//componentStore.Remove<TComponent>(entity);
componentMessageManager.Remove<TComponent>(entity);
}
private void Remove(Entity entity)

View File

@ -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<Type, Dictionary<Entity, int>> typeToEntityToPendingComponentPriority = new Dictionary<Type, Dictionary<Entity, int>>();
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<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{
componentStore.Set(entity, component);
upToDateComponentStore.Set(entity, component);
}
public void UpdateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
upToDateComponentStore.Set<TComponent>(entity, component, priority);
}
// general component reads by type
@ -145,5 +153,10 @@ namespace Encompass
{
return pendingComponentStore.Has(type, entity);
}
internal void Remove<TComponent>(Entity entity) where TComponent : struct, IComponent
{
upToDateComponentStore.Remove<TComponent>(entity);
}
}
}

View File

@ -415,6 +415,10 @@ namespace Encompass
newComponentMessage.priority = priority;
SendPendingComponentMessage(newComponentMessage);
}
else
{
componentMessageManager.UpdateComponent<TComponent>(entity, component, priority);
}
if (component is IDrawableComponent drawableComponent)
{