From 95b38cb092229229172dcbb37b12760fe2a4dc8c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 7 Nov 2023 21:41:55 -0800 Subject: [PATCH] clear entity sets on snapshot --- src/Snapshot.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Snapshot.cs b/src/Snapshot.cs index 61bde14..6d124cb 100644 --- a/src/Snapshot.cs +++ b/src/Snapshot.cs @@ -59,10 +59,14 @@ public class Snapshot // restore entity relation index state // FIXME: arghhhh this is so slow + + foreach (var (id, relationTypeSet) in world.EntityRelationIndex) + { + relationTypeSet.Clear(); + } + foreach (var (id, relationTypeSet) in EntityRelationIndex) { - world.EntityRelationIndex[id].Clear(); - foreach (var typeId in relationTypeSet) { world.EntityRelationIndex[id].Add(typeId); @@ -71,10 +75,14 @@ public class Snapshot // restore entity component index state // FIXME: arrghghhh this is so slow + + foreach (var (id, componentTypeSet) in world.EntityComponentIndex) + { + componentTypeSet.Clear(); + } + foreach (var (id, componentTypeSet) in EntityComponentIndex) { - world.EntityComponentIndex[id].Clear(); - foreach (var typeId in componentTypeSet) { world.EntityComponentIndex[id].Add(typeId); @@ -192,7 +200,6 @@ public class Snapshot private class ComponentSnapshot { - private readonly Dictionary EntityIDToStorageIndex = new Dictionary(); private readonly NativeArray Components; private readonly NativeArray EntityIDs;