fix new hashsets being allocated on each entity create

pull/4/head
cosmonaut 2023-01-10 12:41:16 -08:00
parent f69d132a5e
commit e4131d58f5
1 changed files with 8 additions and 2 deletions

View File

@ -18,8 +18,14 @@ namespace MoonTools.ECS
public Entity Create()
{
var entity = new Entity(NextID());
EntityToComponentTypeIndices.TryAdd(entity.ID, new HashSet<int>());
EntityToRelationTypeIndices.TryAdd(entity.ID, new HashSet<int>());
if (!EntityToComponentTypeIndices.ContainsKey(entity.ID))
{
EntityToComponentTypeIndices.Add(entity.ID, new HashSet<int>());
}
if (!EntityToRelationTypeIndices.ContainsKey(entity.ID))
{
EntityToRelationTypeIndices.Add(entity.ID, new HashSet<int>());
}
return entity;
}