diff --git a/encompass-cs/Collections/ComponentDeltaStore.cs b/encompass-cs/Collections/ComponentDeltaStore.cs index a0b022c..eadc90f 100644 --- a/encompass-cs/Collections/ComponentDeltaStore.cs +++ b/encompass-cs/Collections/ComponentDeltaStore.cs @@ -52,6 +52,7 @@ namespace Encompass var result = _store.Remove(entityID, priority); if (result) { + RegisterComponentType(); var replayer = _replayers[typeof(TComponent)]; _currentReplayers.Add(replayer); replayer.MarkRemoval(entityID); diff --git a/encompass-cs/Collections/TypedComponentStore.cs b/encompass-cs/Collections/TypedComponentStore.cs index 9cb2788..679ee1c 100644 --- a/encompass-cs/Collections/TypedComponentStore.cs +++ b/encompass-cs/Collections/TypedComponentStore.cs @@ -17,8 +17,8 @@ namespace Encompass { private int _nextID = 0; private readonly Dictionary _entityIDToStorageIndex = new Dictionary(128); - private readonly Dictionary _storageIndexToEntityID = new Dictionary(128); private readonly Dictionary _priorities = new Dictionary(128); + private int[] _storageIndexToEntityID = new int[128]; private TComponent[] _components = new TComponent[128]; public override int Count { get => _entityIDToStorageIndex.Count; } @@ -54,6 +54,7 @@ namespace Encompass if (index >= _components.Length) { System.Array.Resize(ref _components, _components.Length * 2); + System.Array.Resize(ref _storageIndexToEntityID, _storageIndexToEntityID.Length * 2); } _entityIDToStorageIndex[entityID] = index; _storageIndexToEntityID[index] = entityID; @@ -80,7 +81,6 @@ namespace Encompass { var storageIndex = _entityIDToStorageIndex[entityID]; _entityIDToStorageIndex.Remove(entityID); - _storageIndexToEntityID.Remove(storageIndex); _priorities.Remove(entityID); // move a component into the hole to maintain contiguous memory @@ -88,7 +88,6 @@ namespace Encompass { var lastStorageIndex = _nextID - 1; var lastEntityID = _storageIndexToEntityID[lastStorageIndex]; - _storageIndexToEntityID.Remove(lastStorageIndex); _entityIDToStorageIndex[lastEntityID] = storageIndex; _storageIndexToEntityID[storageIndex] = lastEntityID; @@ -109,7 +108,6 @@ namespace Encompass { _nextID = 0; _entityIDToStorageIndex.Clear(); - _storageIndexToEntityID.Clear(); _priorities.Clear(); } @@ -120,9 +118,9 @@ namespace Encompass public IEnumerable<(TComponent, int)> All() { - foreach (var kvp in _entityIDToStorageIndex) + for (var i = 0; i < _nextID; i++) { - yield return (_components[kvp.Value], kvp.Key); + yield return (_components[i], _storageIndexToEntityID[i]); } } }