using System; using System.Collections.Generic; namespace MoonTools.ECS { public struct FilterBuilder { private TypeIndices ComponentTypeIndices; private TypeIndices RelationTypeIndices; private FilterStorage FilterStorage; private HashSet Included; private HashSet Excluded; private HashSet InRelations; private HashSet OutRelations; internal FilterBuilder( FilterStorage filterStorage, TypeIndices componentTypeIndices, TypeIndices relationTypeIndices ) { FilterStorage = filterStorage; ComponentTypeIndices = componentTypeIndices; RelationTypeIndices = relationTypeIndices; Included = new HashSet(); Excluded = new HashSet(); InRelations = new HashSet(); OutRelations = new HashSet(); } private FilterBuilder( FilterStorage filterStorage, TypeIndices componentTypeIndices, TypeIndices relationTypeIndices, HashSet included, HashSet excluded, HashSet inRelations, HashSet outRelations ) { FilterStorage = filterStorage; ComponentTypeIndices = componentTypeIndices; RelationTypeIndices = relationTypeIndices; Included = included; Excluded = excluded; InRelations = inRelations; OutRelations = outRelations; } public FilterBuilder Include() where TComponent : unmanaged { Included.Add(ComponentTypeIndices.GetIndex()); return this; } public FilterBuilder Exclude() where TComponent : unmanaged { Excluded.Add(ComponentTypeIndices.GetIndex()); return this; } public FilterBuilder WithInRelation() where TRelation : unmanaged { InRelations.Add(RelationTypeIndices.GetIndex()); return this; } public FilterBuilder WithOutRelation() where TRelation : unmanaged { OutRelations.Add(RelationTypeIndices.GetIndex()); return this; } public Filter Build() { return FilterStorage.CreateFilter(Included, Excluded, InRelations, OutRelations); } } }