accidentally destroyed every pooled dictionary when an entity was destroyed LOOOL
parent
fa27ed850a
commit
dbe6cc4f53
|
@ -69,6 +69,7 @@ namespace Encompass
|
||||||
return componentID;
|
return componentID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal IEnumerable<Guid> GetComponentIDsByEntityID(Guid entityID)
|
internal IEnumerable<Guid> GetComponentIDsByEntityID(Guid entityID)
|
||||||
{
|
{
|
||||||
HashSet<Guid> idSet;
|
HashSet<Guid> idSet;
|
||||||
|
@ -201,10 +202,7 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
entityIDToComponentIDs.Remove(entityID);
|
entityIDToComponentIDs.Remove(entityID);
|
||||||
|
|
||||||
foreach (var pooledDictionary in entityIDToComponentTypeToComponentIDs.Values)
|
entityIDToComponentTypeToComponentIDs[entityID].Dispose();
|
||||||
{
|
|
||||||
pooledDictionary.Dispose();
|
|
||||||
}
|
|
||||||
entityIDToComponentTypeToComponentIDs.Remove(entityID);
|
entityIDToComponentTypeToComponentIDs.Remove(entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,25 @@ namespace Encompass
|
||||||
private readonly Dictionary<Entity, PooledDictionary<Type, HashSet<Guid>>> entityToTypeToPendingComponentIDs = 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>>>();
|
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, HashSet<Guid>>();
|
||||||
|
entityToTypeToPendingComponentIDs[entity] = new PooledDictionary<Type, HashSet<Guid>>();
|
||||||
|
entityToTypeToExistingComponentIDs[entity] = new PooledDictionary<Type, HashSet<Guid>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void RegisterDestroyedEntity(Entity entity)
|
||||||
|
{
|
||||||
|
entityToTypeToComponentIDs[entity].Dispose();
|
||||||
|
entityToTypeToComponentIDs.Remove(entity);
|
||||||
|
|
||||||
|
entityToTypeToPendingComponentIDs[entity].Dispose();
|
||||||
|
entityToTypeToPendingComponentIDs.Remove(entity);
|
||||||
|
|
||||||
|
entityToTypeToExistingComponentIDs[entity].Dispose();
|
||||||
|
entityToTypeToExistingComponentIDs.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
internal void ClearMessages()
|
internal void ClearMessages()
|
||||||
{
|
{
|
||||||
componentIDToComponent.Clear();
|
componentIDToComponent.Clear();
|
||||||
|
@ -61,27 +80,6 @@ namespace Encompass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RegisterDestroyedEntity(Entity entity)
|
|
||||||
{
|
|
||||||
foreach (var pooledDictionary in entityToTypeToComponentIDs.Values)
|
|
||||||
{
|
|
||||||
pooledDictionary.Dispose();
|
|
||||||
}
|
|
||||||
entityToTypeToComponentIDs.Remove(entity);
|
|
||||||
|
|
||||||
foreach (var pooledDictionary in entityToTypeToPendingComponentIDs.Values)
|
|
||||||
{
|
|
||||||
pooledDictionary.Dispose();
|
|
||||||
}
|
|
||||||
entityToTypeToPendingComponentIDs.Remove(entity);
|
|
||||||
|
|
||||||
foreach (var pooledDictionary in entityToTypeToExistingComponentIDs.Values)
|
|
||||||
{
|
|
||||||
pooledDictionary.Dispose();
|
|
||||||
}
|
|
||||||
entityToTypeToExistingComponentIDs.Remove(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void AddExistingComponentMessage<TComponent>(ComponentMessage<TComponent> componentMessage) where TComponent : struct, IComponent
|
internal void AddExistingComponentMessage<TComponent>(ComponentMessage<TComponent> componentMessage) where TComponent : struct, IComponent
|
||||||
{
|
{
|
||||||
RegisterExistingOrPendingComponentMessage(componentMessage.entity, componentMessage.componentID, componentMessage.component);
|
RegisterExistingOrPendingComponentMessage(componentMessage.entity, componentMessage.componentID, componentMessage.component);
|
||||||
|
@ -93,10 +91,6 @@ namespace Encompass
|
||||||
|
|
||||||
componentMessageTypeToExistingComponentIDs[typeof(TComponent)].Add(componentMessage.componentID);
|
componentMessageTypeToExistingComponentIDs[typeof(TComponent)].Add(componentMessage.componentID);
|
||||||
|
|
||||||
if (!entityToTypeToExistingComponentIDs.ContainsKey(componentMessage.entity))
|
|
||||||
{
|
|
||||||
entityToTypeToExistingComponentIDs.Add(componentMessage.entity, new PooledDictionary<Type, HashSet<Guid>>());
|
|
||||||
}
|
|
||||||
if (!entityToTypeToExistingComponentIDs[componentMessage.entity].ContainsKey(typeof(TComponent)))
|
if (!entityToTypeToExistingComponentIDs[componentMessage.entity].ContainsKey(typeof(TComponent)))
|
||||||
{
|
{
|
||||||
entityToTypeToExistingComponentIDs[componentMessage.entity].Add(typeof(TComponent), new HashSet<Guid>());
|
entityToTypeToExistingComponentIDs[componentMessage.entity].Add(typeof(TComponent), new HashSet<Guid>());
|
||||||
|
@ -116,10 +110,6 @@ namespace Encompass
|
||||||
|
|
||||||
componentMessageTypeToPendingComponentIDs[typeof(TComponent)].Add(pendingComponentMessage.componentID);
|
componentMessageTypeToPendingComponentIDs[typeof(TComponent)].Add(pendingComponentMessage.componentID);
|
||||||
|
|
||||||
if (!entityToTypeToPendingComponentIDs.ContainsKey(pendingComponentMessage.entity))
|
|
||||||
{
|
|
||||||
entityToTypeToPendingComponentIDs.Add(pendingComponentMessage.entity, new PooledDictionary<Type, HashSet<Guid>>());
|
|
||||||
}
|
|
||||||
if (!entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].ContainsKey(typeof(TComponent)))
|
if (!entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].ContainsKey(typeof(TComponent)))
|
||||||
{
|
{
|
||||||
entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].Add(typeof(TComponent), new HashSet<Guid>());
|
entityToTypeToPendingComponentIDs[pendingComponentMessage.entity].Add(typeof(TComponent), new HashSet<Guid>());
|
||||||
|
@ -138,10 +128,6 @@ namespace Encompass
|
||||||
}
|
}
|
||||||
componentMessageTypeToComponentIDs[typeof(TComponent)].Add(componentID);
|
componentMessageTypeToComponentIDs[typeof(TComponent)].Add(componentID);
|
||||||
|
|
||||||
if (!entityToTypeToComponentIDs.ContainsKey(entity))
|
|
||||||
{
|
|
||||||
entityToTypeToComponentIDs.Add(entity, new PooledDictionary<Type, HashSet<Guid>>());
|
|
||||||
}
|
|
||||||
if (!entityToTypeToComponentIDs[entity].ContainsKey(typeof(TComponent)))
|
if (!entityToTypeToComponentIDs[entity].ContainsKey(typeof(TComponent)))
|
||||||
{
|
{
|
||||||
entityToTypeToComponentIDs[entity].Add(typeof(TComponent), new HashSet<Guid>());
|
entityToTypeToComponentIDs[entity].Add(typeof(TComponent), new HashSet<Guid>());
|
||||||
|
|
|
@ -78,6 +78,7 @@ namespace Encompass
|
||||||
var layer = componentIDToLayerIndex[id];
|
var layer = componentIDToLayerIndex[id];
|
||||||
layerIndexToComponentIDs[layer].Remove(id);
|
layerIndexToComponentIDs[layer].Remove(id);
|
||||||
}
|
}
|
||||||
|
componentIDToLayerIndex.Remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AdjustComponentLayer(Guid id, int layer)
|
public void AdjustComponentLayer(Guid id, int layer)
|
||||||
|
|
|
@ -140,7 +140,7 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
var componentID = componentManager.NextID();
|
var componentID = componentManager.NextID();
|
||||||
|
|
||||||
componentManager.AddDrawComponent(entity, componentID, component);
|
componentManager.AddDrawComponent(entity, componentID, component, layer);
|
||||||
|
|
||||||
if (sendTypes.Contains(typeof(PendingComponentMessage<TComponent>)))
|
if (sendTypes.Contains(typeof(PendingComponentMessage<TComponent>)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace Encompass
|
||||||
var entity = new Entity(id);
|
var entity = new Entity(id);
|
||||||
IDToEntity[id] = entity;
|
IDToEntity[id] = entity;
|
||||||
componentManager.RegisterEntity(id);
|
componentManager.RegisterEntity(id);
|
||||||
|
componentMessageManager.RegisterEntity(entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -438,14 +438,14 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<ValueTuple<Guid, MockComponent>> results;
|
static List<(Guid, MockComponent)> results;
|
||||||
|
|
||||||
[Reads(typeof(MockComponent))]
|
[Reads(typeof(MockComponent))]
|
||||||
class ReaderEngine : Engine
|
class ReaderEngine : Engine
|
||||||
{
|
{
|
||||||
public override void Update(double dt)
|
public override void Update(double dt)
|
||||||
{
|
{
|
||||||
results = ReadComponents<MockComponent>();
|
results = ReadComponents<MockComponent>().ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,6 +458,7 @@ namespace Tests
|
||||||
|
|
||||||
var entity = worldBuilder.CreateEntity();
|
var entity = worldBuilder.CreateEntity();
|
||||||
var entityB = worldBuilder.CreateEntity();
|
var entityB = worldBuilder.CreateEntity();
|
||||||
|
var entityC = worldBuilder.CreateEntity();
|
||||||
|
|
||||||
DestroyerComponent destroyerComponent;
|
DestroyerComponent destroyerComponent;
|
||||||
MockComponent mockComponent;
|
MockComponent mockComponent;
|
||||||
|
@ -470,12 +471,16 @@ namespace Tests
|
||||||
worldBuilder.AddComponent(entityB, destroyerComponent);
|
worldBuilder.AddComponent(entityB, destroyerComponent);
|
||||||
var componentBID = worldBuilder.AddComponent(entityB, mockComponent);
|
var componentBID = worldBuilder.AddComponent(entityB, mockComponent);
|
||||||
|
|
||||||
|
var componentCID = worldBuilder.AddComponent(entityC, mockComponent);
|
||||||
|
|
||||||
var world = worldBuilder.Build();
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
world.Update(0.01f);
|
world.Update(0.01);
|
||||||
|
world.Update(0.01);
|
||||||
|
|
||||||
Assert.That(results, Does.Not.Contain((componentID, mockComponent)));
|
Assert.That(results, Does.Not.Contain((componentID, mockComponent)));
|
||||||
Assert.That(results, Does.Not.Contain((componentBID, mockComponent)));
|
Assert.That(results, Does.Not.Contain((componentBID, mockComponent)));
|
||||||
|
Assert.That(results, Does.Contain((componentCID, mockComponent)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Reads(typeof(DestroyerComponent), typeof(MockComponent))]
|
[Reads(typeof(DestroyerComponent), typeof(MockComponent))]
|
||||||
|
|
|
@ -64,5 +64,38 @@ namespace Tests
|
||||||
Assert.IsTrue(calledOnDraw);
|
Assert.IsTrue(calledOnDraw);
|
||||||
resultComponent.Should().BeEquivalentTo((testDrawComponentID, testDrawComponent));
|
resultComponent.Should().BeEquivalentTo((testDrawComponentID, testDrawComponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Reads(typeof(TestDrawComponent))]
|
||||||
|
class DestroyerEngine : Engine
|
||||||
|
{
|
||||||
|
public override void Update(double dt)
|
||||||
|
{
|
||||||
|
foreach (var (componentID, component) in ReadComponents<TestDrawComponent>())
|
||||||
|
{
|
||||||
|
Destroy(GetEntityIDByComponentID(componentID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void RenderMethodNotCalledAfterDestroy()
|
||||||
|
{
|
||||||
|
calledOnDraw = false;
|
||||||
|
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
worldBuilder.AddEngine(new DestroyerEngine());
|
||||||
|
var renderer = worldBuilder.AddOrderedRenderer(new CalledRenderer());
|
||||||
|
|
||||||
|
TestDrawComponent testDrawComponent;
|
||||||
|
|
||||||
|
var entity = worldBuilder.CreateEntity();
|
||||||
|
var testDrawComponentID = worldBuilder.AddDrawComponent(entity, testDrawComponent, 1);
|
||||||
|
|
||||||
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
|
world.Update(0.01);
|
||||||
|
world.Draw();
|
||||||
|
|
||||||
|
Assert.IsFalse(calledOnDraw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue