diff --git a/src/Filter.cs b/src/Filter.cs index 3d51524..7d42bac 100644 --- a/src/Filter.cs +++ b/src/Filter.cs @@ -132,12 +132,21 @@ public class Filter // breadth-first search // ignore excluded component edges - foreach (var (componentId, edge) in current.AddEdges) + foreach (var (componentId, archetype) in current.AddEdges) { - if (!filter.Excluded.Contains(componentId)) + if (!Explored.Contains(archetype) && !filter.Excluded.Contains(componentId)) { - Explored.Add(edge); - ArchetypeSearchQueue.Enqueue(edge); + Explored.Add(archetype); + ArchetypeSearchQueue.Enqueue(archetype); + } + } + + foreach (var (componentId, archetype) in current.RemoveEdges) + { + if (!Explored.Contains(archetype)) + { + Explored.Add(archetype); + ArchetypeSearchQueue.Enqueue(archetype); } } } diff --git a/src/World.cs b/src/World.cs index b82ee8f..7948022 100644 --- a/src/World.cs +++ b/src/World.cs @@ -220,7 +220,11 @@ namespace MoonTools.ECS } archetype.AddEdges.Add(componentTypeId, nextArchetype); - nextArchetype.RemoveEdges.Add(componentTypeId, archetype); + + if (!nextArchetype.RemoveEdges.ContainsKey(componentTypeId)) + { + nextArchetype.RemoveEdges.Add(componentTypeId, archetype); + } return nextArchetype; } @@ -246,7 +250,11 @@ namespace MoonTools.ECS } archetype.RemoveEdges.Add(componentTypeId, nextArchetype); - nextArchetype.AddEdges.Add(componentTypeId, archetype); + + if (!nextArchetype.AddEdges.ContainsKey(componentTypeId)) + { + nextArchetype.AddEdges.Add(componentTypeId, archetype); + } return nextArchetype; }