From c1391bbcd85cdeb7d593de79ee21e4ba8201f0de Mon Sep 17 00:00:00 2001 From: Dylan Wilson Date: Wed, 24 Jan 2018 21:27:57 +1000 Subject: [PATCH] fixed some bugs in the ecs --- Source/MonoGame.Extended.Entities/Entity.cs | 18 +++---- .../EntityManager.cs | 50 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Source/MonoGame.Extended.Entities/Entity.cs b/Source/MonoGame.Extended.Entities/Entity.cs index c35f0122..db4f562c 100644 --- a/Source/MonoGame.Extended.Entities/Entity.cs +++ b/Source/MonoGame.Extended.Entities/Entity.cs @@ -104,15 +104,15 @@ namespace MonoGame.Extended.Entities } } - public string Group - { - get { return _group; } - set - { - _group = value; - Manager.AddEntityToGroup(value, this); - } - } + //public string Group + //{ + // get { return _group; } + // set + // { + // _group = value; + // Manager.AddEntityToGroup(value, this); + // } + //} IPoolable IPoolable.NextNode { get; set; } IPoolable IPoolable.PreviousNode { get; set; } diff --git a/Source/MonoGame.Extended.Entities/EntityManager.cs b/Source/MonoGame.Extended.Entities/EntityManager.cs index 41d6777b..b2a61024 100644 --- a/Source/MonoGame.Extended.Entities/EntityManager.cs +++ b/Source/MonoGame.Extended.Entities/EntityManager.cs @@ -165,41 +165,41 @@ namespace MonoGame.Extended.Entities return bag; } - internal void AddEntityToGroup(string group, Entity entity) - { - Debug.Assert(entity != null); + //internal void AddEntityToGroup(string group, Entity entity) + //{ + // Debug.Assert(entity != null); - if (string.IsNullOrEmpty(group)) - return; + // if (string.IsNullOrEmpty(group)) + // return; - RemoveEntityFromGroup(entity); + // RemoveEntityFromGroup(entity); - entity._group = group; + // entity._group = group; - Bag entities; + // Bag entities; - if (!_entitiesByGroup.TryGetValue(group, out entities)) - { - entities = new Bag(); - _entitiesByGroup.Add(group, entities); - } + // if (!_entitiesByGroup.TryGetValue(group, out entities)) + // { + // entities = new Bag(); + // _entitiesByGroup.Add(group, entities); + // } - entities.Add(entity); - } + // entities.Add(entity); + //} - internal void RemoveEntityFromGroup(Entity entity) - { - Bag entities; + //internal void RemoveEntityFromGroup(Entity entity) + //{ + // Bag entities; - if (_entitiesByGroup.TryGetValue(entity._group, out entities)) - entities.Remove(entity); - } + // if (_entitiesByGroup.TryGetValue(entity._group, out entities)) + // entities.Remove(entity); + //} internal void DestroyEntity(Entity entity) { Debug.Assert(entity != null); - RemoveEntityFromGroup(entity); + //RemoveEntityFromGroup(entity); RemoveComponents(entity); entity.Return(); } @@ -405,6 +405,7 @@ namespace MonoGame.Extended.Entities components.Remove(entity); (component as IPoolable)?.Return(); + (component as IDisposable)?.Dispose(); } _componentsToRemove.Clear(); @@ -420,10 +421,9 @@ namespace MonoGame.Extended.Entities { var components = _entitiesToComponentsBag[i]; - Debug.Assert(components != null); - object component; - if (!components.TryGetValue(entity, out component)) + + if (components == null || !components.TryGetValue(entity, out component)) continue; components.Remove(entity);