fix bug in delta store + storage index map is now an array
continuous-integration/drone/push Build is passing Details

pull/3/head
Evan Hemsley 2020-03-22 17:18:23 -07:00
parent 61845d752a
commit d5a45d6419
2 changed files with 5 additions and 6 deletions

View File

@ -52,6 +52,7 @@ namespace Encompass
var result = _store.Remove<TComponent>(entityID, priority);
if (result)
{
RegisterComponentType<TComponent>();
var replayer = _replayers[typeof(TComponent)];
_currentReplayers.Add(replayer);
replayer.MarkRemoval(entityID);

View File

@ -17,8 +17,8 @@ namespace Encompass
{
private int _nextID = 0;
private readonly Dictionary<int, int> _entityIDToStorageIndex = new Dictionary<int, int>(128);
private readonly Dictionary<int, int> _storageIndexToEntityID = new Dictionary<int, int>(128);
private readonly Dictionary<int, int> _priorities = new Dictionary<int, int>(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]);
}
}
}