fix creating new component index on every set
continuous-integration/drone/push Build is passing Details

pull/3/head
Evan Hemsley 2020-03-19 17:26:22 -07:00
parent 98955f3048
commit ffc052ded3
1 changed files with 10 additions and 3 deletions

View File

@ -50,10 +50,13 @@ namespace Encompass
private unsafe void InternalSet(int entityID, TComponent component) private unsafe void InternalSet(int entityID, TComponent component)
{ {
var index = _idManager.NextID(); if (!indices.ContainsKey(entityID))
{
indices[entityID] = _idManager.NextID();
}
var ptr = Unsafe.AsPointer(ref component); var ptr = Unsafe.AsPointer(ref component);
indices[entityID] = index; components[indices[entityID]] = Unsafe.AsRef<TComponent>(ptr);
components[index] = Unsafe.AsRef<TComponent>(ptr);
} }
public override bool Remove(int entityID, int priority) public override bool Remove(int entityID, int priority)
@ -84,6 +87,10 @@ namespace Encompass
public override void Clear() public override void Clear()
{ {
foreach (var entityID in indices.Keys)
{
_idManager.Free(entityID);
}
indices.Clear(); indices.Clear();
priorities.Clear(); priorities.Clear();
} }