From ffc052ded35e9d120978424e60473dbcf21fa171 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Thu, 19 Mar 2020 17:26:22 -0700 Subject: [PATCH] fix creating new component index on every set --- encompass-cs/Collections/TypedComponentStore.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/encompass-cs/Collections/TypedComponentStore.cs b/encompass-cs/Collections/TypedComponentStore.cs index a32fea4..fa766b5 100644 --- a/encompass-cs/Collections/TypedComponentStore.cs +++ b/encompass-cs/Collections/TypedComponentStore.cs @@ -50,10 +50,13 @@ namespace Encompass 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); - indices[entityID] = index; - components[index] = Unsafe.AsRef(ptr); + components[indices[entityID]] = Unsafe.AsRef(ptr); } public override bool Remove(int entityID, int priority) @@ -84,6 +87,10 @@ namespace Encompass public override void Clear() { + foreach (var entityID in indices.Keys) + { + _idManager.Free(entityID); + } indices.Clear(); priorities.Clear(); }