remove nested pooled collections

pull/5/head
Evan Hemsley 2019-08-09 20:04:11 -07:00
parent bde0c0437e
commit 583776dd53
2 changed files with 24 additions and 24 deletions

View File

@ -15,7 +15,7 @@ namespace Encompass
private readonly Dictionary<Guid, PooledSet<Guid>> entityIDToComponentIDs = new Dictionary<Guid, PooledSet<Guid>>();
private readonly Dictionary<Guid, Guid> componentIDToEntityID = new Dictionary<Guid, Guid>();
private readonly Dictionary<Guid, PooledDictionary<Type, PooledSet<Guid>>> entityIDToComponentTypeToComponentIDs = new Dictionary<Guid, PooledDictionary<Type, PooledSet<Guid>>>();
private readonly Dictionary<Guid, PooledDictionary<Type, HashSet<Guid>>> entityIDToComponentTypeToComponentIDs = new Dictionary<Guid, PooledDictionary<Type, HashSet<Guid>>>();
private readonly Dictionary<Type, HashSet<Guid>> typeToComponentIDs = new Dictionary<Type, HashSet<Guid>>();
@ -31,7 +31,7 @@ namespace Encompass
internal void RegisterEntity(Guid entityID)
{
entityIDToComponentIDs.Add(entityID, new PooledSet<Guid>());
entityIDToComponentTypeToComponentIDs.Add(entityID, new PooledDictionary<Type, PooledSet<Guid>>());
entityIDToComponentTypeToComponentIDs.Add(entityID, new PooledDictionary<Type, HashSet<Guid>>(ClearMode.Never));
}
internal Guid NextID()
@ -53,7 +53,7 @@ namespace Encompass
entityIDToComponentIDs[entity.ID].Add(componentID);
if (!entityIDToComponentTypeToComponentIDs[entity.ID].ContainsKey(typeof(TComponent))) {
entityIDToComponentTypeToComponentIDs[entity.ID].Add(typeof(TComponent), new PooledSet<Guid>());
entityIDToComponentTypeToComponentIDs[entity.ID].Add(typeof(TComponent), new HashSet<Guid>());
}
entityIDToComponentTypeToComponentIDs[entity.ID][typeof(TComponent)].Add(componentID);
@ -90,7 +90,7 @@ namespace Encompass
internal IEnumerable<ValueTuple<Guid, TComponent>> GetComponentsByEntityAndType<TComponent>(Guid entityID) where TComponent : struct, IComponent
{
if (entityIDToComponentTypeToComponentIDs.ContainsKey(entityID) && entityIDToComponentTypeToComponentIDs[entityID].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityIDToComponentTypeToComponentIDs.ContainsKey(entityID) && entityIDToComponentTypeToComponentIDs[entityID].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Select(id => (id, (TComponent)IDToComponent[id]));
}
@ -99,7 +99,7 @@ namespace Encompass
internal bool EntityHasComponentOfType<TComponent>(Guid entityID) where TComponent : struct, IComponent
{
if (entityIDToComponentTypeToComponentIDs.ContainsKey(entityID) && entityIDToComponentTypeToComponentIDs[entityID].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityIDToComponentTypeToComponentIDs.ContainsKey(entityID) && entityIDToComponentTypeToComponentIDs[entityID].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Count > 0;
}
@ -200,7 +200,7 @@ namespace Encompass
foreach (var set in entityIDToComponentTypeToComponentIDs[entityID].Values)
{
set.Dispose();
set.Clear();
}
entityIDToComponentTypeToComponentIDs[entityID].Dispose();
entityIDToComponentTypeToComponentIDs.Remove(entityID);

View File

@ -13,36 +13,36 @@ namespace Encompass
private readonly Dictionary<Type, HashSet<Guid>> componentMessageTypeToPendingComponentIDs = new Dictionary<Type, HashSet<Guid>>();
private readonly Dictionary<Type, HashSet<Guid>> componentMessageTypeToComponentIDs = new Dictionary<Type, HashSet<Guid>>();
private readonly Dictionary<Entity, PooledDictionary<Type, PooledSet<Guid>>> entityToTypeToExistingComponentIDs = new Dictionary<Entity, PooledDictionary<Type, PooledSet<Guid>>>();
private readonly Dictionary<Entity, PooledDictionary<Type, PooledSet<Guid>>> entityToTypeToPendingComponentIDs = new Dictionary<Entity, PooledDictionary<Type, PooledSet<Guid>>>();
private readonly Dictionary<Entity, PooledDictionary<Type, PooledSet<Guid>>> entityToTypeToComponentIDs = new Dictionary<Entity, PooledDictionary<Type, PooledSet<Guid>>>();
private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToExistingComponentIDs = new Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>>();
private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToPendingComponentIDs = new Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>>();
private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToComponentIDs = new Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>>();
internal void RegisterEntity(Entity entity)
{
entityToTypeToComponentIDs[entity] = new PooledDictionary<Type, PooledSet<Guid>>();
entityToTypeToPendingComponentIDs[entity] = new PooledDictionary<Type, PooledSet<Guid>>();
entityToTypeToExistingComponentIDs[entity] = new PooledDictionary<Type, PooledSet<Guid>>();
entityToTypeToComponentIDs[entity] = new PooledDictionary<Type, HashSet<Guid>>(ClearMode.Never);
entityToTypeToPendingComponentIDs[entity] = new PooledDictionary<Type, HashSet<Guid>>(ClearMode.Never);
entityToTypeToExistingComponentIDs[entity] = new PooledDictionary<Type, HashSet<Guid>>(ClearMode.Never);
}
internal void RegisterDestroyedEntity(Entity entity)
{
foreach (var set in entityToTypeToComponentIDs[entity].Values)
{
set.Dispose();
set.Clear();
}
entityToTypeToComponentIDs[entity].Dispose();
entityToTypeToComponentIDs.Remove(entity);
foreach (var set in entityToTypeToPendingComponentIDs[entity].Values)
{
set.Dispose();
set.Clear();
}
entityToTypeToPendingComponentIDs[entity].Dispose();
entityToTypeToPendingComponentIDs.Remove(entity);
foreach (var set in entityToTypeToExistingComponentIDs[entity].Values)
{
set.Dispose();
set.Clear();
}
entityToTypeToExistingComponentIDs[entity].Dispose();
entityToTypeToExistingComponentIDs.Remove(entity);
@ -105,7 +105,7 @@ namespace Encompass
if (!entityToTypeToExistingComponentIDs[componentMessage.entity].ContainsKey(typeof(TComponent)))
{
entityToTypeToExistingComponentIDs[componentMessage.entity].Add(typeof(TComponent), new PooledSet<Guid>());
entityToTypeToExistingComponentIDs[componentMessage.entity].Add(typeof(TComponent), new HashSet<Guid>());
}
entityToTypeToExistingComponentIDs[componentMessage.entity][typeof(TComponent)].Add(componentMessage.componentID);
@ -124,7 +124,7 @@ namespace Encompass
if (!entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].ContainsKey(typeof(TComponent)))
{
entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].Add(typeof(TComponent), new PooledSet<Guid>());
entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].Add(typeof(TComponent), new HashSet<Guid>());
}
entityToTypeToPendingComponentIDs[pendingComponentMessage.entity][typeof(TComponent)].Add(pendingComponentMessage.componentID);
@ -142,7 +142,7 @@ namespace Encompass
if (!entityToTypeToComponentIDs[entity].ContainsKey(typeof(TComponent)))
{
entityToTypeToComponentIDs[entity].Add(typeof(TComponent), new PooledSet<Guid>());
entityToTypeToComponentIDs[entity].Add(typeof(TComponent), new HashSet<Guid>());
}
entityToTypeToComponentIDs[entity][typeof(TComponent)].Add(componentID);
@ -233,7 +233,7 @@ namespace Encompass
internal IEnumerable<(Guid, TComponent)> ReadExistingAndPendingComponentsByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (entityToTypeToComponentIDs.ContainsKey(entity) && entityToTypeToComponentIDs[entity].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityToTypeToComponentIDs.ContainsKey(entity) && entityToTypeToComponentIDs[entity].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Select(id => (id, (TComponent)componentIDToComponent[id]));
}
@ -243,7 +243,7 @@ namespace Encompass
internal IEnumerable<(Guid, TComponent)> ReadExistingComponentsByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (entityToTypeToExistingComponentIDs.ContainsKey(entity) && entityToTypeToExistingComponentIDs[entity].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityToTypeToExistingComponentIDs.ContainsKey(entity) && entityToTypeToExistingComponentIDs[entity].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Select(id => (id, (TComponent)componentIDToComponent[id]));
}
@ -253,7 +253,7 @@ namespace Encompass
internal IEnumerable<(Guid, TComponent)> ReadPendingComponentsByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (entityToTypeToPendingComponentIDs.ContainsKey(entity) && entityToTypeToPendingComponentIDs[entity].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityToTypeToPendingComponentIDs.ContainsKey(entity) && entityToTypeToPendingComponentIDs[entity].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Select(id => (id, (TComponent)componentIDToComponent[id]));
}
@ -282,7 +282,7 @@ namespace Encompass
internal bool HasExistingOrPendingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (entityToTypeToComponentIDs.TryGetValue(entity, out _) && entityToTypeToComponentIDs[entity].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityToTypeToComponentIDs.TryGetValue(entity, out _) && entityToTypeToComponentIDs[entity].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Count > 0;
}
@ -292,7 +292,7 @@ namespace Encompass
internal bool HasExistingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (entityToTypeToExistingComponentIDs.TryGetValue(entity, out _) && entityToTypeToExistingComponentIDs[entity].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityToTypeToExistingComponentIDs.TryGetValue(entity, out _) && entityToTypeToExistingComponentIDs[entity].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Count > 0;
}
@ -302,7 +302,7 @@ namespace Encompass
internal bool HasPendingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
if (entityToTypeToPendingComponentIDs.TryGetValue(entity, out _) && entityToTypeToPendingComponentIDs[entity].TryGetValue(typeof(TComponent), out PooledSet<Guid> idSet))
if (entityToTypeToPendingComponentIDs.TryGetValue(entity, out _) && entityToTypeToPendingComponentIDs[entity].TryGetValue(typeof(TComponent), out HashSet<Guid> idSet))
{
return idSet.Count > 0;
}