reverse lookup optimization

pull/5/head
thatcosmonaut 2019-07-17 18:56:02 -07:00
parent a62153730f
commit 0b2ef55634
1 changed files with 4 additions and 4 deletions

View File

@ -11,10 +11,10 @@ namespace Encompass
private readonly Dictionary<Guid, Type> componentIDToType = new Dictionary<Guid, Type>(); private readonly Dictionary<Guid, Type> componentIDToType = new Dictionary<Guid, Type>();
private readonly Dictionary<Guid, IComponent> IDToComponent = new Dictionary<Guid, IComponent>(); private readonly Dictionary<Guid, IComponent> IDToComponent = new Dictionary<Guid, IComponent>();
private readonly Dictionary<Guid, List<Guid>> entityIDToComponentIDs = new Dictionary<Guid, List<Guid>>(); // TODO: hashset private readonly Dictionary<Guid, HashSet<Guid>> entityIDToComponentIDs = new Dictionary<Guid, HashSet<Guid>>();
private readonly Dictionary<Guid, Guid> componentIDToEntityID = new Dictionary<Guid, Guid>(); private readonly Dictionary<Guid, Guid> componentIDToEntityID = new Dictionary<Guid, Guid>();
private readonly Dictionary<Type, List<Guid>> typeToComponentIDs = new Dictionary<Type, List<Guid>>(); // TODO: hashset private readonly Dictionary<Type, HashSet<Guid>> typeToComponentIDs = new Dictionary<Type, HashSet<Guid>>();
private readonly List<Guid> activeComponents = new List<Guid>(); private readonly List<Guid> activeComponents = new List<Guid>();
private readonly List<Guid> inactiveComponents = new List<Guid>(); private readonly List<Guid> inactiveComponents = new List<Guid>();
@ -42,7 +42,7 @@ namespace Encompass
internal void RegisterEntity(Guid entityID) internal void RegisterEntity(Guid entityID)
{ {
entityIDToComponentIDs.Add(entityID, new List<Guid>()); entityIDToComponentIDs.Add(entityID, new HashSet<Guid>());
} }
internal Guid AddComponent<TComponent>(Guid entityID, TComponent component) where TComponent : struct, IComponent internal Guid AddComponent<TComponent>(Guid entityID, TComponent component) where TComponent : struct, IComponent
@ -54,7 +54,7 @@ namespace Encompass
if (!typeToComponentIDs.ContainsKey(typeof(TComponent))) if (!typeToComponentIDs.ContainsKey(typeof(TComponent)))
{ {
typeToComponentIDs.Add(typeof(TComponent), new List<Guid>()); typeToComponentIDs.Add(typeof(TComponent), new HashSet<Guid>());
} }
typeToComponentIDs[typeof(TComponent)].Add(componentID); typeToComponentIDs[typeof(TComponent)].Add(componentID);