using System.Collections; using System.Collections.Generic; using Encompass.Collections; namespace Encompass { public struct EntitySetQuery : IEnumerable { private EntityManager EntityManager { get; } private ComponentUpdateManager ComponentUpdateManager { get; } private BitSet1024 WithPendingMask { get; } private BitSet1024 WithExistingMask { get; } private BitSet1024 WithoutPendingMask { get; } private BitSet1024 WithoutExistingMask { get; } private BitSet1024 NotWithMask { get; } internal EntitySetQuery(EntityManager entityManager, ComponentUpdateManager componentUpdateManager, BitSet1024 withPendingMask, BitSet1024 withExistingMask, BitSet1024 withoutPendingMask, BitSet1024 withoutExistingMask, BitSet1024 notWithMask) { EntityManager = entityManager; ComponentUpdateManager = componentUpdateManager; WithPendingMask = withPendingMask; WithExistingMask = withExistingMask; WithoutPendingMask = withoutPendingMask; WithoutExistingMask = withoutExistingMask; NotWithMask = notWithMask; } public IEnumerator GetEnumerator() { foreach (var entity in EntityManager.Entities) { var pendingBits = ComponentUpdateManager.PendingBits(entity); var existingBits = ComponentUpdateManager.ExistingBits(entity); var pending = WithPendingMask.And(pendingBits); var existing = WithExistingMask.And(existingBits); var withCheck = pending.Or(existing).Or(NotWithMask); var pendingForbidden = WithoutPendingMask.And(pendingBits); var existingForbidden = WithoutExistingMask.And(existingBits); var withoutCheck = pendingForbidden.And(existingForbidden); if (withCheck.And(withoutCheck).AllTrue()) { yield return entity; } } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }