fixed world initialization and draw component removal issues
parent
0293263684
commit
571310e579
|
@ -85,6 +85,7 @@ namespace Encompass
|
|||
{
|
||||
//componentStore.Remove<TComponent>(entity);
|
||||
componentMessageManager.Remove<TComponent>(entity);
|
||||
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entity);
|
||||
}
|
||||
|
||||
private void Remove(Entity entity)
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Encompass
|
|||
|
||||
private readonly ComponentStore existingComponentStore = new ComponentStore();
|
||||
private readonly ComponentStore pendingComponentStore = new ComponentStore();
|
||||
private readonly ComponentStore upToDateComponentStore = new ComponentStore();
|
||||
private ComponentStore upToDateComponentStore = new ComponentStore();
|
||||
|
||||
private readonly Dictionary<Type, Dictionary<Entity, int>> typeToEntityToPendingComponentPriority = new Dictionary<Type, Dictionary<Entity, int>>();
|
||||
|
||||
|
@ -30,6 +30,11 @@ namespace Encompass
|
|||
}
|
||||
}
|
||||
|
||||
internal void SetStartingComponentStore(ComponentStore componentStore)
|
||||
{
|
||||
upToDateComponentStore = componentStore;
|
||||
}
|
||||
|
||||
internal void AddExistingComponentMessage<TComponent>(ComponentMessage<TComponent> componentMessage) where TComponent : struct, IComponent
|
||||
{
|
||||
RegisterExistingOrPendingComponentMessage(componentMessage.entity, componentMessage.component);
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Encompass
|
|||
internal class DrawLayerManager
|
||||
{
|
||||
private readonly SortedList<int, int> layerOrder = new SortedList<int, int>();
|
||||
private readonly ComponentStore componentStore = new ComponentStore();
|
||||
|
||||
private readonly Dictionary<int, ComponentStore> layerIndexToComponentStore = new Dictionary<int, ComponentStore>();
|
||||
private readonly Dictionary<int, HashSet<GeneralRenderer>> layerIndexToGeneralRenderers = new Dictionary<int, HashSet<GeneralRenderer>>();
|
||||
|
@ -52,7 +51,12 @@ namespace Encompass
|
|||
|
||||
public void RegisterComponentWithLayer<TComponent>(Entity entity, TComponent component, int layer) where TComponent : struct, IComponent
|
||||
{
|
||||
if (typeToEntityToLayer[typeof(TComponent)].ContainsKey(entity)) { UnRegisterComponentWithLayer(entity, component); }
|
||||
if (!typeToEntityToLayer.ContainsKey(typeof(TComponent)))
|
||||
{
|
||||
typeToEntityToLayer.Add(typeof(TComponent), new Dictionary<Entity, int>());
|
||||
}
|
||||
|
||||
if (typeToEntityToLayer[typeof(TComponent)].ContainsKey(entity)) { UnRegisterComponentWithLayer<TComponent>(entity); }
|
||||
|
||||
if (layerIndexToComponentStore.ContainsKey(layer))
|
||||
{
|
||||
|
@ -74,8 +78,10 @@ namespace Encompass
|
|||
}
|
||||
}
|
||||
|
||||
public void UnRegisterComponentWithLayer<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
|
||||
public void UnRegisterComponentWithLayer<TComponent>(Entity entity) where TComponent : struct, IComponent
|
||||
{
|
||||
if (!typeToEntityToLayer.ContainsKey(typeof(TComponent))) { return; }
|
||||
|
||||
if (typeToEntityToLayer[typeof(TComponent)].ContainsKey(entity))
|
||||
{
|
||||
var layer = typeToEntityToLayer[typeof(TComponent)][entity];
|
||||
|
@ -86,7 +92,10 @@ namespace Encompass
|
|||
|
||||
public void UnRegisterEntityWithLayer(Entity entity)
|
||||
{
|
||||
componentStore.Remove(entity);
|
||||
foreach (var store in layerIndexToComponentStore.Values)
|
||||
{
|
||||
store.Remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<GeneralRenderer> GeneralRenderersByLayer(int layer)
|
||||
|
@ -98,7 +107,9 @@ namespace Encompass
|
|||
|
||||
public IEnumerable<(Entity, Type, IComponent)> AllInLayer(int layer)
|
||||
{
|
||||
return layerIndexToComponentStore[layer].AllInterfaceTyped();
|
||||
return layerIndexToComponentStore.ContainsKey(layer) ?
|
||||
layerIndexToComponentStore[layer].AllInterfaceTyped() :
|
||||
Enumerable.Empty<(Entity, Type, IComponent)>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ namespace Encompass
|
|||
{
|
||||
private readonly List<Engine> engines = new List<Engine>();
|
||||
private readonly DirectedGraph<Engine, Unit> engineGraph = GraphBuilder.DirectedGraph<Engine>();
|
||||
private readonly ComponentStore componentStore = new ComponentStore();
|
||||
private readonly ComponentStore startingComponentStoreForComponentManager = new ComponentStore();
|
||||
private readonly ComponentStore startingComponentStoreForComponentMessageManager = new ComponentStore();
|
||||
|
||||
private readonly ComponentManager componentManager;
|
||||
private readonly EntityManager entityManager;
|
||||
|
@ -76,7 +77,8 @@ namespace Encompass
|
|||
/// </summary>
|
||||
public void SetComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
|
||||
{
|
||||
componentStore.Set(entity, component);
|
||||
startingComponentStoreForComponentManager.Set(entity, component);
|
||||
startingComponentStoreForComponentMessageManager.Set(entity, component);
|
||||
|
||||
if (component is IDrawableComponent drawableComponent)
|
||||
{
|
||||
|
@ -348,7 +350,8 @@ namespace Encompass
|
|||
renderManager
|
||||
);
|
||||
|
||||
componentManager.SetComponentStore(componentStore);
|
||||
componentManager.SetComponentStore(startingComponentStoreForComponentManager);
|
||||
componentMessageManager.SetStartingComponentStore(startingComponentStoreForComponentMessageManager);
|
||||
|
||||
return world;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue