refactor to remove ComponentUpdateManager

pull/5/head
Evan Hemsley 2019-12-29 13:24:51 -08:00
parent a2d29a6591
commit f7095ffdfb
6 changed files with 189 additions and 277 deletions

View File

@ -6,28 +6,37 @@ namespace Encompass
internal class ComponentManager internal class ComponentManager
{ {
private readonly DrawLayerManager drawLayerManager; private readonly DrawLayerManager drawLayerManager;
private readonly ComponentUpdateManager componentUpdateManager;
private readonly ComponentStore componentStore; private readonly ComponentStore existingComponentStore;
private readonly ComponentStore immediateComponentStore;
private ComponentStore upToDateComponentStore;
public Dictionary<Type, int> TypeToIndex { get; }
private readonly HashSet<int> entitiesMarkedForRemoval = new HashSet<int>(); private readonly HashSet<int> entitiesMarkedForRemoval = new HashSet<int>();
internal ComponentBitSet ComponentBitSet { get { return componentStore.ComponentBitSet; } } internal ComponentBitSet ImmediateBits { get { return immediateComponentStore.ComponentBitSet; } }
internal ComponentBitSet ExistingBits { get { return existingComponentStore.ComponentBitSet; } }
public ComponentManager(DrawLayerManager drawLayerManager, ComponentUpdateManager componentUpdateManager, Dictionary<Type, int> typeToIndex) public ComponentManager(DrawLayerManager drawLayerManager, Dictionary<Type, int> typeToIndex)
{ {
this.drawLayerManager = drawLayerManager; this.drawLayerManager = drawLayerManager;
this.componentUpdateManager = componentUpdateManager; existingComponentStore = new ComponentStore(typeToIndex);
componentStore = new ComponentStore(typeToIndex); immediateComponentStore = new ComponentStore(typeToIndex);
upToDateComponentStore = new ComponentStore(typeToIndex);
TypeToIndex = typeToIndex;
} }
public void RegisterComponentType<TComponent>() where TComponent : struct, IComponent public void RegisterComponentType<TComponent>() where TComponent : struct, IComponent
{ {
componentStore.RegisterComponentType<TComponent>(); existingComponentStore.RegisterComponentType<TComponent>();
immediateComponentStore.RegisterComponentType<TComponent>();
upToDateComponentStore.RegisterComponentType<TComponent>();
} }
internal void SetComponentStore(ComponentStore componentStore) internal void SetComponentStore(ComponentStore componentStore)
{ {
this.componentStore.SwapWith(componentStore); existingComponentStore.SwapWith(componentStore);
} }
internal void RegisterDrawableComponent<TComponent>(Entity entity, TComponent component, int layer) where TComponent : struct, IComponent internal void RegisterDrawableComponent<TComponent>(Entity entity, TComponent component, int layer) where TComponent : struct, IComponent
@ -35,24 +44,146 @@ namespace Encompass
drawLayerManager.RegisterComponentWithLayer(entity.ID, component, layer); drawLayerManager.RegisterComponentWithLayer(entity.ID, component, layer);
} }
internal void AddComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{
componentStore.Set(entity.ID, component);
}
internal void WriteComponents() internal void WriteComponents()
{ {
componentStore.SwapWith(componentUpdateManager.UpToDateComponentStore); SetComponentStore(upToDateComponentStore);
upToDateComponentStore.ClearAll();
immediateComponentStore.ClearAll();
}
internal void AddExistingComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{
upToDateComponentStore.Set(entity.ID, component);
}
internal bool AddImmediateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
if (immediateComponentStore.Set(entity.ID, component, priority))
{
upToDateComponentStore.Set(entity.ID, component);
return true;
}
return false;
}
public bool UpdateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
return upToDateComponentStore.Set(entity.ID, component, priority);
}
// existing or immediate reads
internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return upToDateComponentStore.All<TComponent>();
}
internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeExistingOrImmediateComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadExistingAndImmediateComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
internal bool SomeExistingOrImmediateComponent<TComponent>() where TComponent : struct, IComponent
{
return upToDateComponentStore.Any<TComponent>();
}
// existing reads
internal (TComponent, int) ReadFirstExistingComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeExistingComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = GetComponentsIncludingEntity<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
internal bool SomeExistingComponent<TComponent>() where TComponent : struct, IComponent
{
return existingComponentStore.Any<TComponent>();
}
// immediate reads
internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return immediateComponentStore.All<TComponent>();
}
internal (TComponent, int) ReadFirstImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeImmediateComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadImmediateComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
internal bool SomeImmediateComponent<TComponent>() where TComponent : struct, IComponent
{
return immediateComponentStore.Any<TComponent>();
}
// component getters
internal TComponent ReadImmediateOrExistingComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return upToDateComponentStore.Get<TComponent>(entity.ID);
}
internal TComponent ReadExistingComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return existingComponentStore.Get<TComponent>(entity.ID);
}
internal TComponent ReadImmediateComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return immediateComponentStore.Get<TComponent>(entity.ID);
}
// has checkers
internal bool HasExistingOrImmediateComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return upToDateComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasExistingOrImmediateComponent(Entity entity, Type type)
{
return upToDateComponentStore.Has(type, entity.ID);
}
internal bool HasExistingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return existingComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasExistingComponent(Entity entity, Type type)
{
return existingComponentStore.Has(type, entity.ID);
}
internal bool HasImmediateComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return immediateComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasImmediateComponent(Entity entity, Type type)
{
return immediateComponentStore.Has(type, entity.ID);
} }
internal IEnumerable<(TComponent, int)> GetComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent internal IEnumerable<(TComponent, int)> GetComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent
{ {
return componentStore.All<TComponent>(); return existingComponentStore.All<TComponent>();
} }
internal IEnumerable<TComponent> GetComponentsByType<TComponent>() where TComponent : struct, IComponent internal IEnumerable<TComponent> GetComponentsByType<TComponent>() where TComponent : struct, IComponent
{ {
foreach (var pair in componentStore.All<TComponent>()) foreach (var pair in existingComponentStore.All<TComponent>())
{ {
yield return pair.Item1; yield return pair.Item1;
} }
@ -60,17 +191,12 @@ namespace Encompass
internal TComponent GetComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent internal TComponent GetComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{ {
return componentStore.Get<TComponent>(entity.ID); return existingComponentStore.Get<TComponent>(entity.ID);
} }
internal bool EntityHasComponentOfType<TComponent>(Entity entity) where TComponent : struct, IComponent internal bool EntityHasComponentOfType<TComponent>(Entity entity) where TComponent : struct, IComponent
{ {
return componentStore.Has<TComponent>(entity.ID); return existingComponentStore.Has<TComponent>(entity.ID);
}
internal bool ComponentOfTypeExists<TComponent>() where TComponent : struct, IComponent
{
return componentStore.Any<TComponent>();
} }
internal void MarkAllComponentsOnEntityForRemoval(Entity entity) internal void MarkAllComponentsOnEntityForRemoval(Entity entity)
@ -82,7 +208,8 @@ namespace Encompass
{ {
foreach (var entityID in entitiesMarkedForRemoval) foreach (var entityID in entitiesMarkedForRemoval)
{ {
componentStore.Remove(entityID); existingComponentStore.Remove(entityID);
upToDateComponentStore.Remove(entityID);
drawLayerManager.UnRegisterEntityWithLayer(entityID); drawLayerManager.UnRegisterEntityWithLayer(entityID);
} }
@ -91,8 +218,9 @@ namespace Encompass
public bool RemoveImmediate<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent public bool RemoveImmediate<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
{ {
if (componentUpdateManager.RemoveImmediate<TComponent>(entity, priority)) if (immediateComponentStore.Remove<TComponent>(entity.ID, priority))
{ {
upToDateComponentStore.Remove<TComponent>(entity.ID, priority);
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entity.ID); drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entity.ID);
return true; return true;
} }
@ -101,7 +229,7 @@ namespace Encompass
public void Remove<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent public void Remove<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
{ {
if (componentUpdateManager.Remove<TComponent>(entity, priority)) if (upToDateComponentStore.Remove<TComponent>(entity.ID, priority))
{ {
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entity.ID); drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entity.ID);
} }

View File

@ -1,189 +0,0 @@
using System;
using System.Collections.Generic;
namespace Encompass
{
internal class ComponentUpdateManager
{
private ComponentStore existingComponentStore;
private readonly ComponentStore immediateComponentStore;
public ComponentStore UpToDateComponentStore { get; private set; }
public Dictionary<Type, int> TypeToIndex { get; }
public ComponentUpdateManager(Dictionary<Type, int> typeToIndex)
{
existingComponentStore = new ComponentStore(typeToIndex);
immediateComponentStore = new ComponentStore(typeToIndex);
UpToDateComponentStore = new ComponentStore(typeToIndex);
TypeToIndex = typeToIndex;
}
public void RegisterComponentType<TComponent>() where TComponent : struct, IComponent
{
existingComponentStore.RegisterComponentType<TComponent>();
immediateComponentStore.RegisterComponentType<TComponent>();
UpToDateComponentStore.RegisterComponentType<TComponent>();
}
internal void Clear()
{
existingComponentStore.ClearAll();
immediateComponentStore.ClearAll();
}
internal void SetStartingComponentStore(ComponentStore componentStore)
{
UpToDateComponentStore = componentStore;
}
internal void AddExistingComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{
existingComponentStore.Set(entity.ID, component);
}
internal bool AddImmediateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
if (immediateComponentStore.Set(entity.ID, component, priority))
{
UpToDateComponentStore.Set(entity.ID, component);
return true;
}
return false;
}
internal bool RemoveImmediate<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
{
if (immediateComponentStore.Remove<TComponent>(entity.ID, priority))
{
UpToDateComponentStore.Remove<TComponent>(entity.ID, priority);
return true;
}
return false;
}
internal bool Remove<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
{
return UpToDateComponentStore.Remove<TComponent>(entity.ID, priority);
}
public bool UpdateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
return UpToDateComponentStore.Set<TComponent>(entity.ID, component, priority);
}
// general component reads by type
internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return UpToDateComponentStore.All<TComponent>();
}
internal IEnumerable<(TComponent, int)> ReadExistingComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return existingComponentStore.All<TComponent>();
}
internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return immediateComponentStore.All<TComponent>();
}
// singular component reads by type
internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeExistingOrImmediateComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadExistingAndImmediateComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
internal (TComponent, int) ReadFirstExistingComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeExistingComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadExistingComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
internal (TComponent, int) ReadFirstImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeImmediateComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadImmediateComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
// check if some component of type exists in the world
internal bool SomeExistingOrImmediateComponent<TComponent>() where TComponent : struct, IComponent
{
return UpToDateComponentStore.Any<TComponent>();
}
internal bool SomeExistingComponent<TComponent>() where TComponent : struct, IComponent
{
return existingComponentStore.Any<TComponent>();
}
internal bool SomeImmediateComponent<TComponent>() where TComponent : struct, IComponent
{
return immediateComponentStore.Any<TComponent>();
}
// read components by entity and type
internal TComponent ReadImmediateOrExistingComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return UpToDateComponentStore.Get<TComponent>(entity.ID);
}
internal TComponent ReadExistingComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return existingComponentStore.Get<TComponent>(entity.ID);
}
internal TComponent ReadImmediateComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return immediateComponentStore.Get<TComponent>(entity.ID);
}
// check if entity has component of type
internal bool HasExistingOrImmediateComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return UpToDateComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasExistingOrImmediateComponent(Entity entity, Type type)
{
return UpToDateComponentStore.Has(type, entity.ID);
}
internal bool HasExistingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return existingComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasExistingComponent(Entity entity, Type type)
{
return existingComponentStore.Has(type, entity.ID);
}
internal bool HasImmediateComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return immediateComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasImmediateComponent(Entity entity, Type type)
{
return immediateComponentStore.Has(type, entity.ID);
}
internal ComponentBitSet ImmediateBits { get { return immediateComponentStore.ComponentBitSet; } }
internal ComponentBitSet ExistingBits { get { return existingComponentStore.ComponentBitSet; } }
}
}

View File

@ -36,7 +36,6 @@ namespace Encompass
private EntityManager entityManager; private EntityManager entityManager;
private MessageManager messageManager; private MessageManager messageManager;
private ComponentManager componentManager; private ComponentManager componentManager;
private ComponentUpdateManager componentUpdateManager;
private TimeManager timeManager; private TimeManager timeManager;
private TrackingManager trackingManager; private TrackingManager trackingManager;
@ -140,11 +139,6 @@ namespace Encompass
this.messageManager = messageManager; this.messageManager = messageManager;
} }
internal void AssignComponentUpdateManager(ComponentUpdateManager componentUpdateManager)
{
this.componentUpdateManager = componentUpdateManager;
}
internal void AssignTimeManager(TimeManager timeManager) internal void AssignTimeManager(TimeManager timeManager)
{ {
this.timeManager = timeManager; this.timeManager = timeManager;
@ -209,15 +203,15 @@ namespace Encompass
var existingRead = readTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && immediateRead) if (existingRead && immediateRead)
{ {
return componentUpdateManager.ReadExistingAndImmediateComponentsByType<TComponent>(); return componentManager.ReadExistingAndImmediateComponentsByType<TComponent>();
} }
else if (existingRead) else if (existingRead)
{ {
return componentUpdateManager.ReadExistingComponentsByType<TComponent>(); return componentManager.GetComponentsIncludingEntity<TComponent>();
} }
else if (immediateRead) else if (immediateRead)
{ {
return componentUpdateManager.ReadImmediateComponentsByType<TComponent>(); return componentManager.ReadImmediateComponentsByType<TComponent>();
} }
else else
{ {
@ -261,15 +255,15 @@ namespace Encompass
var existingRead = readTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && immediateRead) if (existingRead && immediateRead)
{ {
return componentUpdateManager.ReadFirstExistingOrImmediateComponentByType<TComponent>(); return componentManager.ReadFirstExistingOrImmediateComponentByType<TComponent>();
} }
else if (existingRead) else if (existingRead)
{ {
return componentUpdateManager.ReadFirstExistingComponentByType<TComponent>(); return componentManager.ReadFirstExistingComponentByType<TComponent>();
} }
else if (immediateRead) else if (immediateRead)
{ {
return componentUpdateManager.ReadFirstImmediateComponentByType<TComponent>(); return componentManager.ReadFirstImmediateComponentByType<TComponent>();
} }
else else
{ {
@ -303,15 +297,15 @@ namespace Encompass
var existingRead = readTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && immediateRead) if (existingRead && immediateRead)
{ {
return componentUpdateManager.SomeExistingOrImmediateComponent<TComponent>(); return componentManager.SomeExistingOrImmediateComponent<TComponent>();
} }
else if (existingRead) else if (existingRead)
{ {
return componentUpdateManager.SomeExistingComponent<TComponent>(); return componentManager.SomeExistingComponent<TComponent>();
} }
else if (immediateRead) else if (immediateRead)
{ {
return componentUpdateManager.SomeImmediateComponent<TComponent>(); return componentManager.SomeImmediateComponent<TComponent>();
} }
else else
{ {
@ -325,15 +319,15 @@ namespace Encompass
var existingRead = readTypes.Contains(typeof(TComponent)); var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && immediateRead) if (existingRead && immediateRead)
{ {
return componentUpdateManager.ReadImmediateOrExistingComponentByEntityAndType<TComponent>(entity); return componentManager.ReadImmediateOrExistingComponentByEntityAndType<TComponent>(entity);
} }
else if (existingRead) else if (existingRead)
{ {
return componentUpdateManager.ReadExistingComponentByEntityAndType<TComponent>(entity); return componentManager.ReadExistingComponentByEntityAndType<TComponent>(entity);
} }
else if (immediateRead) else if (immediateRead)
{ {
return componentUpdateManager.ReadImmediateComponentByEntityAndType<TComponent>(entity); return componentManager.ReadImmediateComponentByEntityAndType<TComponent>(entity);
} }
else else
{ {
@ -368,15 +362,15 @@ namespace Encompass
if (immediateRead && existingRead) if (immediateRead && existingRead)
{ {
return componentUpdateManager.HasExistingOrImmediateComponent<TComponent>(entity); return componentManager.HasExistingOrImmediateComponent<TComponent>(entity);
} }
else if (existingRead) else if (existingRead)
{ {
return componentUpdateManager.HasExistingComponent<TComponent>(entity); return componentManager.HasExistingComponent<TComponent>(entity);
} }
else if (immediateRead) else if (immediateRead)
{ {
return componentUpdateManager.HasImmediateComponent<TComponent>(entity); return componentManager.HasImmediateComponent<TComponent>(entity);
} }
else else
{ {
@ -397,15 +391,15 @@ namespace Encompass
if (immediateRead && existingRead) if (immediateRead && existingRead)
{ {
return componentUpdateManager.HasExistingOrImmediateComponent(entity, type); return componentManager.HasExistingOrImmediateComponent(entity, type);
} }
else if (existingRead) else if (existingRead)
{ {
return componentUpdateManager.HasExistingComponent(entity, type); return componentManager.HasExistingComponent(entity, type);
} }
else if (immediateRead) else if (immediateRead)
{ {
return componentUpdateManager.HasImmediateComponent(entity, type); return componentManager.HasImmediateComponent(entity, type);
} }
else else
{ {
@ -431,7 +425,7 @@ namespace Encompass
bool written; bool written;
if (writeImmediateTypes.Contains(typeof(TComponent))) if (writeImmediateTypes.Contains(typeof(TComponent)))
{ {
written = componentUpdateManager.AddImmediateComponent(entity, component, priority); written = componentManager.AddImmediateComponent(entity, component, priority);
if (written) if (written)
{ {
trackingManager.ImmediateUpdateTracking(entity, typeof(TComponent)); trackingManager.ImmediateUpdateTracking(entity, typeof(TComponent));
@ -439,10 +433,10 @@ namespace Encompass
} }
else else
{ {
written = componentUpdateManager.UpdateComponent(entity, component, priority); written = componentManager.UpdateComponent(entity, component, priority);
} }
if (!componentUpdateManager.HasExistingComponent<TComponent>(entity)) if (!componentManager.HasExistingComponent<TComponent>(entity))
{ {
trackingManager.RegisterAddition(entity, typeof(TComponent)); trackingManager.RegisterAddition(entity, typeof(TComponent));
} }
@ -489,7 +483,7 @@ namespace Encompass
internal void AddExistingComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent internal void AddExistingComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{ {
componentUpdateManager.AddExistingComponent(entity, component); componentManager.AddExistingComponent(entity, component);
} }
/// <summary> /// <summary>
@ -591,7 +585,7 @@ namespace Encompass
componentManager.Remove<TComponent>(entity, priority); componentManager.Remove<TComponent>(entity, priority);
} }
if (componentUpdateManager.HasExistingComponent<TComponent>(entity)) if (componentManager.HasExistingComponent<TComponent>(entity))
{ {
trackingManager.RegisterRemoval(entity, typeof(TComponent)); trackingManager.RegisterRemoval(entity, typeof(TComponent));
} }
@ -659,11 +653,11 @@ namespace Encompass
internal void CheckAndUpdateTracking(Entity entity) internal void CheckAndUpdateTracking(Entity entity)
{ {
if (_trackedEntities.Contains(entity) && !entityQuery.CheckEntity(entity, componentManager.ComponentBitSet)) if (_trackedEntities.Contains(entity) && !entityQuery.CheckEntity(entity, componentManager.ExistingBits))
{ {
_trackedEntities.Remove(entity); _trackedEntities.Remove(entity);
} }
else if (!_trackedEntities.Contains(entity) && entityQuery.CheckEntity(entity, componentManager.ComponentBitSet)) else if (!_trackedEntities.Contains(entity) && entityQuery.CheckEntity(entity, componentManager.ExistingBits))
{ {
_trackedEntities.Add(entity); _trackedEntities.Add(entity);
} }
@ -671,11 +665,11 @@ namespace Encompass
internal void ImmediateCheckAndUpdateTracking(Entity entity) internal void ImmediateCheckAndUpdateTracking(Entity entity)
{ {
if (_trackedEntities.Contains(entity) && !entityQuery.ImmediateCheckEntity(entity, componentUpdateManager.ImmediateBits, componentUpdateManager.ExistingBits)) if (_trackedEntities.Contains(entity) && !entityQuery.ImmediateCheckEntity(entity, componentManager.ImmediateBits, componentManager.ExistingBits))
{ {
_trackedEntities.Remove(entity); _trackedEntities.Remove(entity);
} }
else if (!_trackedEntities.Contains(entity) && entityQuery.ImmediateCheckEntity(entity, componentUpdateManager.ImmediateBits, componentUpdateManager.ExistingBits)) else if (!_trackedEntities.Contains(entity) && entityQuery.ImmediateCheckEntity(entity, componentManager.ImmediateBits, componentManager.ExistingBits))
{ {
_trackedEntities.Add(entity); _trackedEntities.Add(entity);
} }
@ -689,25 +683,25 @@ namespace Encompass
var withMask = BitSet512.Zero; var withMask = BitSet512.Zero;
foreach (var type in queryWithTypes) foreach (var type in queryWithTypes)
{ {
withMask = withMask.Set(componentUpdateManager.TypeToIndex[type]); withMask = withMask.Set(componentManager.TypeToIndex[type]);
} }
var withoutMask = BitSet512.Zero; var withoutMask = BitSet512.Zero;
foreach (var type in queryWithoutTypes) foreach (var type in queryWithoutTypes)
{ {
withoutMask = withoutMask.Set(componentUpdateManager.TypeToIndex[type]); withoutMask = withoutMask.Set(componentManager.TypeToIndex[type]);
} }
var immediateMask = BitSet512.Zero; var immediateMask = BitSet512.Zero;
foreach (var type in readImmediateTypes) foreach (var type in readImmediateTypes)
{ {
immediateMask = immediateMask.Set(componentUpdateManager.TypeToIndex[type]); immediateMask = immediateMask.Set(componentManager.TypeToIndex[type]);
} }
var existingMask = BitSet512.Zero; var existingMask = BitSet512.Zero;
foreach (var type in readTypes) foreach (var type in readTypes)
{ {
existingMask = existingMask.Set(componentUpdateManager.TypeToIndex[type]); existingMask = existingMask.Set(componentManager.TypeToIndex[type]);
} }
entityQuery = new EntitySetQuery( entityQuery = new EntitySetQuery(

View File

@ -69,7 +69,7 @@ namespace Encompass
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
{ {
return componentManager.ComponentOfTypeExists<TComponent>(); return componentManager.SomeExistingComponent<TComponent>();
} }
} }
} }

View File

@ -12,7 +12,6 @@ namespace Encompass
private readonly ComponentManager componentManager; private readonly ComponentManager componentManager;
private readonly TrackingManager trackingManager; private readonly TrackingManager trackingManager;
private readonly MessageManager messageManager; private readonly MessageManager messageManager;
private readonly ComponentUpdateManager componentUpdateManager;
private readonly TimeManager timeManager; private readonly TimeManager timeManager;
private readonly RenderManager renderManager; private readonly RenderManager renderManager;
@ -22,7 +21,6 @@ namespace Encompass
ComponentManager componentManager, ComponentManager componentManager,
TrackingManager trackingManager, TrackingManager trackingManager,
MessageManager messageManager, MessageManager messageManager,
ComponentUpdateManager componentUpdateManager,
TimeManager timeManager, TimeManager timeManager,
RenderManager renderManager RenderManager renderManager
) )
@ -32,7 +30,6 @@ namespace Encompass
this.componentManager = componentManager; this.componentManager = componentManager;
this.trackingManager = trackingManager; this.trackingManager = trackingManager;
this.messageManager = messageManager; this.messageManager = messageManager;
this.componentUpdateManager = componentUpdateManager;
this.timeManager = timeManager; this.timeManager = timeManager;
this.renderManager = renderManager; this.renderManager = renderManager;
} }
@ -62,10 +59,8 @@ namespace Encompass
messageManager.ClearMessages(); messageManager.ClearMessages();
entityManager.DestroyMarkedEntities(enginesInOrder); entityManager.DestroyMarkedEntities(enginesInOrder);
componentManager.WriteComponents();
componentManager.RemoveMarkedComponents(); componentManager.RemoveMarkedComponents();
componentManager.WriteComponents();
componentUpdateManager.Clear();
} }
/// <summary> /// <summary>

View File

@ -27,7 +27,6 @@ namespace Encompass
private readonly ComponentManager componentManager; private readonly ComponentManager componentManager;
private readonly EntityManager entityManager; private readonly EntityManager entityManager;
private readonly MessageManager messageManager; private readonly MessageManager messageManager;
private readonly ComponentUpdateManager componentUpdateManager;
private readonly TimeManager timeManager; private readonly TimeManager timeManager;
private readonly DrawLayerManager drawLayerManager; private readonly DrawLayerManager drawLayerManager;
private readonly RenderManager renderManager; private readonly RenderManager renderManager;
@ -49,8 +48,7 @@ namespace Encompass
drawLayerManager = new DrawLayerManager(typeToIndex); drawLayerManager = new DrawLayerManager(typeToIndex);
timeManager = new TimeManager(); timeManager = new TimeManager();
trackingManager = new TrackingManager(); trackingManager = new TrackingManager();
componentUpdateManager = new ComponentUpdateManager(typeToIndex); componentManager = new ComponentManager(drawLayerManager, typeToIndex);
componentManager = new ComponentManager(drawLayerManager, componentUpdateManager, typeToIndex);
messageManager = new MessageManager(timeManager); messageManager = new MessageManager(timeManager);
entityManager = new EntityManager(componentManager, entityCapacity); entityManager = new EntityManager(componentManager, entityCapacity);
renderManager = new RenderManager(entityManager, drawLayerManager); renderManager = new RenderManager(entityManager, drawLayerManager);
@ -107,7 +105,6 @@ namespace Encompass
{ {
typeToIndex.Add(typeof(TComponent), typeToIndex.Count); typeToIndex.Add(typeof(TComponent), typeToIndex.Count);
componentManager.RegisterComponentType<TComponent>(); componentManager.RegisterComponentType<TComponent>();
componentUpdateManager.RegisterComponentType<TComponent>();
startingComponentStoreForComponentManager.RegisterComponentType<TComponent>(); startingComponentStoreForComponentManager.RegisterComponentType<TComponent>();
startingComponentStoreForComponentUpdateManager.RegisterComponentType<TComponent>(); startingComponentStoreForComponentUpdateManager.RegisterComponentType<TComponent>();
} }
@ -132,7 +129,6 @@ namespace Encompass
engine.AssignEntityManager(entityManager); engine.AssignEntityManager(entityManager);
engine.AssignComponentManager(componentManager); engine.AssignComponentManager(componentManager);
engine.AssignMessageManager(messageManager); engine.AssignMessageManager(messageManager);
engine.AssignComponentUpdateManager(componentUpdateManager);
engine.AssignTimeManager(timeManager); engine.AssignTimeManager(timeManager);
engine.AssignTrackingManager(trackingManager); engine.AssignTrackingManager(trackingManager);
@ -395,12 +391,10 @@ namespace Encompass
componentManager, componentManager,
trackingManager, trackingManager,
messageManager, messageManager,
componentUpdateManager,
timeManager, timeManager,
renderManager renderManager
); );
componentUpdateManager.SetStartingComponentStore(startingComponentStoreForComponentUpdateManager);
componentManager.SetComponentStore(startingComponentStoreForComponentManager); componentManager.SetComponentStore(startingComponentStoreForComponentManager);
trackingManager.InitializeTracking(entityManager.Entities); trackingManager.InitializeTracking(entityManager.Entities);
@ -420,8 +414,7 @@ namespace Encompass
var dummyMessageManager = new MessageManager(dummyTimeManager); var dummyMessageManager = new MessageManager(dummyTimeManager);
var dummyDrawLayerManager = new DrawLayerManager(typeToIndex); var dummyDrawLayerManager = new DrawLayerManager(typeToIndex);
var dummyTrackingManager = new TrackingManager(); var dummyTrackingManager = new TrackingManager();
var dummyComponentUpdateManager = new ComponentUpdateManager(typeToIndex); var dummyComponentManager = new ComponentManager(dummyDrawLayerManager, typeToIndex);
var dummyComponentManager = new ComponentManager(dummyDrawLayerManager, dummyComponentUpdateManager, typeToIndex);
var dummyEntityManager = new EntityManager(dummyComponentManager, entityCapacity); var dummyEntityManager = new EntityManager(dummyComponentManager, entityCapacity);
var dummyRenderManager = new RenderManager(dummyEntityManager, dummyDrawLayerManager); var dummyRenderManager = new RenderManager(dummyEntityManager, dummyDrawLayerManager);
@ -432,7 +425,6 @@ namespace Encompass
uberEngine.AssignEntityManager(dummyEntityManager); uberEngine.AssignEntityManager(dummyEntityManager);
uberEngine.AssignComponentManager(dummyComponentManager); uberEngine.AssignComponentManager(dummyComponentManager);
uberEngine.AssignMessageManager(dummyMessageManager); uberEngine.AssignMessageManager(dummyMessageManager);
uberEngine.AssignComponentUpdateManager(dummyComponentUpdateManager);
uberEngine.AssignTimeManager(dummyTimeManager); uberEngine.AssignTimeManager(dummyTimeManager);
uberEngine.AssignTrackingManager(dummyTrackingManager); uberEngine.AssignTrackingManager(dummyTrackingManager);
@ -446,10 +438,6 @@ namespace Encompass
var componentManagerRegisterGenericMethod = componentManagerRegisterMethod.MakeGenericMethod(type); var componentManagerRegisterGenericMethod = componentManagerRegisterMethod.MakeGenericMethod(type);
componentManagerRegisterGenericMethod.Invoke(dummyComponentManager, null); componentManagerRegisterGenericMethod.Invoke(dummyComponentManager, null);
var componentUpdateManagerRegisterMethod = typeof(ComponentUpdateManager).GetMethod("RegisterComponentType");
var componentUpdateManagerRegisterGenericMethod = componentUpdateManagerRegisterMethod.MakeGenericMethod(type);
componentUpdateManagerRegisterGenericMethod.Invoke(dummyComponentUpdateManager, null);
if (type.GetInterface("IDrawableComponent") != null) if (type.GetInterface("IDrawableComponent") != null)
{ {
var drawLayerManagerRegisterMethod = typeof(DrawLayerManager).GetMethod("RegisterOrderedDrawable"); var drawLayerManagerRegisterMethod = typeof(DrawLayerManager).GetMethod("RegisterOrderedDrawable");
@ -461,7 +449,6 @@ namespace Encompass
emitterEngine.AssignEntityManager(dummyEntityManager); emitterEngine.AssignEntityManager(dummyEntityManager);
emitterEngine.AssignComponentManager(dummyComponentManager); emitterEngine.AssignComponentManager(dummyComponentManager);
emitterEngine.AssignMessageManager(dummyMessageManager); emitterEngine.AssignMessageManager(dummyMessageManager);
emitterEngine.AssignComponentUpdateManager(dummyComponentUpdateManager);
emitterEngine.AssignTimeManager(dummyTimeManager); emitterEngine.AssignTimeManager(dummyTimeManager);
emitterEngine.AssignTrackingManager(dummyTrackingManager); emitterEngine.AssignTrackingManager(dummyTrackingManager);
@ -476,20 +463,17 @@ namespace Encompass
dummyComponentManager, dummyComponentManager,
dummyTrackingManager, dummyTrackingManager,
dummyMessageManager, dummyMessageManager,
dummyComponentUpdateManager,
dummyTimeManager, dummyTimeManager,
dummyRenderManager dummyRenderManager
); );
uberEngine.Write(); uberEngine.Write();
dummyComponentManager.WriteComponents(); dummyComponentManager.WriteComponents();
dummyComponentUpdateManager.Clear();
dummyWorld.Update(1); dummyWorld.Update(1);
uberEngine.Write(); uberEngine.Write();
dummyComponentManager.WriteComponents(); dummyComponentManager.WriteComponents();
dummyComponentUpdateManager.Clear();
uberRenderer.SetEntity(uberEngine.Entity); uberRenderer.SetEntity(uberEngine.Entity);
uberRenderer.Render(); uberRenderer.Render();