fix bug in delta store + storage index map is now an array
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
61845d752a
commit
d5a45d6419
|
@ -52,6 +52,7 @@ namespace Encompass
|
||||||
var result = _store.Remove<TComponent>(entityID, priority);
|
var result = _store.Remove<TComponent>(entityID, priority);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
RegisterComponentType<TComponent>();
|
||||||
var replayer = _replayers[typeof(TComponent)];
|
var replayer = _replayers[typeof(TComponent)];
|
||||||
_currentReplayers.Add(replayer);
|
_currentReplayers.Add(replayer);
|
||||||
replayer.MarkRemoval(entityID);
|
replayer.MarkRemoval(entityID);
|
||||||
|
|
|
@ -17,8 +17,8 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
private int _nextID = 0;
|
private int _nextID = 0;
|
||||||
private readonly Dictionary<int, int> _entityIDToStorageIndex = new Dictionary<int, int>(128);
|
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 readonly Dictionary<int, int> _priorities = new Dictionary<int, int>(128);
|
||||||
|
private int[] _storageIndexToEntityID = new int[128];
|
||||||
private TComponent[] _components = new TComponent[128];
|
private TComponent[] _components = new TComponent[128];
|
||||||
|
|
||||||
public override int Count { get => _entityIDToStorageIndex.Count; }
|
public override int Count { get => _entityIDToStorageIndex.Count; }
|
||||||
|
@ -54,6 +54,7 @@ namespace Encompass
|
||||||
if (index >= _components.Length)
|
if (index >= _components.Length)
|
||||||
{
|
{
|
||||||
System.Array.Resize(ref _components, _components.Length * 2);
|
System.Array.Resize(ref _components, _components.Length * 2);
|
||||||
|
System.Array.Resize(ref _storageIndexToEntityID, _storageIndexToEntityID.Length * 2);
|
||||||
}
|
}
|
||||||
_entityIDToStorageIndex[entityID] = index;
|
_entityIDToStorageIndex[entityID] = index;
|
||||||
_storageIndexToEntityID[index] = entityID;
|
_storageIndexToEntityID[index] = entityID;
|
||||||
|
@ -80,7 +81,6 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
var storageIndex = _entityIDToStorageIndex[entityID];
|
var storageIndex = _entityIDToStorageIndex[entityID];
|
||||||
_entityIDToStorageIndex.Remove(entityID);
|
_entityIDToStorageIndex.Remove(entityID);
|
||||||
_storageIndexToEntityID.Remove(storageIndex);
|
|
||||||
_priorities.Remove(entityID);
|
_priorities.Remove(entityID);
|
||||||
|
|
||||||
// move a component into the hole to maintain contiguous memory
|
// move a component into the hole to maintain contiguous memory
|
||||||
|
@ -88,7 +88,6 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
var lastStorageIndex = _nextID - 1;
|
var lastStorageIndex = _nextID - 1;
|
||||||
var lastEntityID = _storageIndexToEntityID[lastStorageIndex];
|
var lastEntityID = _storageIndexToEntityID[lastStorageIndex];
|
||||||
_storageIndexToEntityID.Remove(lastStorageIndex);
|
|
||||||
|
|
||||||
_entityIDToStorageIndex[lastEntityID] = storageIndex;
|
_entityIDToStorageIndex[lastEntityID] = storageIndex;
|
||||||
_storageIndexToEntityID[storageIndex] = lastEntityID;
|
_storageIndexToEntityID[storageIndex] = lastEntityID;
|
||||||
|
@ -109,7 +108,6 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
_nextID = 0;
|
_nextID = 0;
|
||||||
_entityIDToStorageIndex.Clear();
|
_entityIDToStorageIndex.Clear();
|
||||||
_storageIndexToEntityID.Clear();
|
|
||||||
_priorities.Clear();
|
_priorities.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +118,9 @@ namespace Encompass
|
||||||
|
|
||||||
public IEnumerable<(TComponent, int)> All()
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue