adds pooled dictionary to component message manager

pull/5/head
Evan Hemsley 2019-08-01 18:53:44 -07:00
parent 26aeb46cb8
commit 062b31dfb8
2 changed files with 27 additions and 12 deletions

View File

@ -1,8 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Collections.Pooled;
// TODO: object pool for the inner dictionaries so they dont get GC'd
namespace Encompass namespace Encompass
{ {
@ -14,9 +13,9 @@ namespace Encompass
private readonly Dictionary<Type, HashSet<Guid>> componentMessageTypeToPendingComponentIDs = new Dictionary<Type, HashSet<Guid>>(); 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<Type, HashSet<Guid>> componentMessageTypeToComponentIDs = new Dictionary<Type, HashSet<Guid>>();
private readonly Dictionary<Entity, Dictionary<Type, HashSet<Guid>>> entityToTypeToExistingComponentIDs = new Dictionary<Entity, Dictionary<Type, HashSet<Guid>>>(); private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToExistingComponentIDs = new Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>>();
private readonly Dictionary<Entity, Dictionary<Type, HashSet<Guid>>> entityToTypeToPendingComponentIDs = new Dictionary<Entity, Dictionary<Type, HashSet<Guid>>>(); private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToPendingComponentIDs = new Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>>();
private readonly Dictionary<Entity, Dictionary<Type, HashSet<Guid>>> entityToTypeToComponentIDs = new Dictionary<Entity, Dictionary<Type, HashSet<Guid>>>(); private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToComponentIDs = new Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>>();
internal void ClearMessages() internal void ClearMessages()
{ {
@ -64,8 +63,22 @@ namespace Encompass
internal void RegisterDestroyedEntity(Entity entity) internal void RegisterDestroyedEntity(Entity entity)
{ {
foreach (var pooledDictionary in entityToTypeToComponentIDs.Values)
{
pooledDictionary.Dispose();
}
entityToTypeToComponentIDs.Remove(entity); entityToTypeToComponentIDs.Remove(entity);
foreach (var pooledDictionary in entityToTypeToPendingComponentIDs.Values)
{
pooledDictionary.Dispose();
}
entityToTypeToPendingComponentIDs.Remove(entity); entityToTypeToPendingComponentIDs.Remove(entity);
foreach (var pooledDictionary in entityToTypeToExistingComponentIDs.Values)
{
pooledDictionary.Dispose();
}
entityToTypeToExistingComponentIDs.Remove(entity); entityToTypeToExistingComponentIDs.Remove(entity);
} }
@ -82,7 +95,7 @@ namespace Encompass
if (!entityToTypeToExistingComponentIDs.ContainsKey(componentMessage.entity)) if (!entityToTypeToExistingComponentIDs.ContainsKey(componentMessage.entity))
{ {
entityToTypeToExistingComponentIDs.Add(componentMessage.entity, new Dictionary<Type, HashSet<Guid>>()); entityToTypeToExistingComponentIDs.Add(componentMessage.entity, new PooledDictionary<Type, HashSet<Guid>>());
} }
if (!entityToTypeToExistingComponentIDs[componentMessage.entity].ContainsKey(typeof(TComponent))) if (!entityToTypeToExistingComponentIDs[componentMessage.entity].ContainsKey(typeof(TComponent)))
{ {
@ -105,7 +118,7 @@ namespace Encompass
if (!entityToTypeToPendingComponentIDs.ContainsKey(pendingComponentMessage.entity)) if (!entityToTypeToPendingComponentIDs.ContainsKey(pendingComponentMessage.entity))
{ {
entityToTypeToPendingComponentIDs.Add(pendingComponentMessage.entity, new Dictionary<Type, HashSet<Guid>>()); entityToTypeToPendingComponentIDs.Add(pendingComponentMessage.entity, new PooledDictionary<Type, HashSet<Guid>>());
} }
if (!entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].ContainsKey(typeof(TComponent))) if (!entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].ContainsKey(typeof(TComponent)))
{ {
@ -127,7 +140,7 @@ namespace Encompass
if (!entityToTypeToComponentIDs.ContainsKey(entity)) if (!entityToTypeToComponentIDs.ContainsKey(entity))
{ {
entityToTypeToComponentIDs.Add(entity, new Dictionary<Type, HashSet<Guid>>()); entityToTypeToComponentIDs.Add(entity, new PooledDictionary<Type, HashSet<Guid>>());
} }
if (!entityToTypeToComponentIDs[entity].ContainsKey(typeof(TComponent))) if (!entityToTypeToComponentIDs[entity].ContainsKey(typeof(TComponent)))
{ {

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
@ -10,7 +9,7 @@
<Company>Moonside Games</Company> <Company>Moonside Games</Company>
<Product>Encompass ECS</Product> <Product>Encompass ECS</Product>
<PackageProjectUrl>https://github.com/encompass-ecs</PackageProjectUrl> <PackageProjectUrl>https://github.com/encompass-ecs</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl> <PackageLicenseUrl/>
<Copyright>Evan Hemsley 2019</Copyright> <Copyright>Evan Hemsley 2019</Copyright>
<Description>Encompass is an engine-agnostic Hyper ECS framework to help you code games, or other kinds of simulations.</Description> <Description>Encompass is an engine-agnostic Hyper ECS framework to help you code games, or other kinds of simulations.</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@ -20,7 +19,10 @@
<ItemGroup> <ItemGroup>
<None Include="..\LICENSE"> <None Include="..\LICENSE">
<Pack>True</Pack> <Pack>True</Pack>
<PackagePath></PackagePath> <PackagePath/>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Collections.Pooled" Version="1.0.82"/>
</ItemGroup>
</Project> </Project>