adds pooled dictionary to componentmanager lookup

pull/5/head
Evan Hemsley 2019-08-01 18:56:52 -07:00
parent 062b31dfb8
commit efb47c2879
2 changed files with 8 additions and 3 deletions

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Encompass.Exceptions; using Encompass.Exceptions;
using Collections.Pooled;
namespace Encompass namespace Encompass
{ {
@ -14,7 +15,7 @@ namespace Encompass
private readonly Dictionary<Guid, HashSet<Guid>> entityIDToComponentIDs = new Dictionary<Guid, HashSet<Guid>>(); 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<Guid, Dictionary<Type, HashSet<Guid>>> entityIDToComponentTypeToComponentIDs = new Dictionary<Guid, Dictionary<Type, HashSet<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>>(); private readonly Dictionary<Type, HashSet<Guid>> typeToComponentIDs = new Dictionary<Type, HashSet<Guid>>();
@ -30,7 +31,7 @@ namespace Encompass
internal void RegisterEntity(Guid entityID) internal void RegisterEntity(Guid entityID)
{ {
entityIDToComponentIDs.Add(entityID, new HashSet<Guid>()); entityIDToComponentIDs.Add(entityID, new HashSet<Guid>());
entityIDToComponentTypeToComponentIDs.Add(entityID, new Dictionary<Type, HashSet<Guid>>()); entityIDToComponentTypeToComponentIDs.Add(entityID, new PooledDictionary<Type, HashSet<Guid>>());
} }
internal Guid NextID() internal Guid NextID()
@ -199,6 +200,11 @@ namespace Encompass
public void RegisterDestroyedEntity(Guid entityID) public void RegisterDestroyedEntity(Guid entityID)
{ {
entityIDToComponentIDs.Remove(entityID); entityIDToComponentIDs.Remove(entityID);
foreach (var pooledDictionary in entityIDToComponentTypeToComponentIDs.Values)
{
pooledDictionary.Dispose();
}
entityIDToComponentTypeToComponentIDs.Remove(entityID); entityIDToComponentTypeToComponentIDs.Remove(entityID);
} }
} }

View File

@ -150,7 +150,6 @@ namespace Encompass
newComponentMessage.component = component; newComponentMessage.component = component;
SendMessage(newComponentMessage); SendMessage(newComponentMessage);
SendPendingComponentMessage(newComponentMessage); SendPendingComponentMessage(newComponentMessage);
} }
return componentID; return componentID;