2019-12-23 01:16:54 +00:00
|
|
|
|
using System.Collections;
|
2019-12-22 01:58:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-12-23 01:16:54 +00:00
|
|
|
|
using Encompass.Collections;
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
|
{
|
|
|
|
|
public struct EntitySetQuery : IEnumerable<Entity>
|
|
|
|
|
{
|
2019-12-23 01:16:54 +00:00
|
|
|
|
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; }
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
2019-12-23 01:16:54 +00:00
|
|
|
|
internal EntitySetQuery(EntityManager entityManager, ComponentUpdateManager componentUpdateManager, BitSet1024 withPendingMask, BitSet1024 withExistingMask, BitSet1024 withoutPendingMask, BitSet1024 withoutExistingMask, BitSet1024 notWithMask)
|
2019-12-22 01:58:07 +00:00
|
|
|
|
{
|
2019-12-22 09:15:58 +00:00
|
|
|
|
EntityManager = entityManager;
|
|
|
|
|
ComponentUpdateManager = componentUpdateManager;
|
2019-12-23 01:16:54 +00:00
|
|
|
|
WithPendingMask = withPendingMask;
|
|
|
|
|
WithExistingMask = withExistingMask;
|
|
|
|
|
WithoutPendingMask = withoutPendingMask;
|
|
|
|
|
WithoutExistingMask = withoutExistingMask;
|
|
|
|
|
NotWithMask = notWithMask;
|
2019-12-22 01:58:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 01:16:54 +00:00
|
|
|
|
public IEnumerator<Entity> GetEnumerator()
|
2019-12-22 01:58:07 +00:00
|
|
|
|
{
|
2019-12-23 01:16:54 +00:00
|
|
|
|
foreach (var entity in EntityManager.Entities)
|
|
|
|
|
{
|
|
|
|
|
var pendingBits = ComponentUpdateManager.PendingBits(entity);
|
|
|
|
|
var existingBits = ComponentUpdateManager.ExistingBits(entity);
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
2019-12-23 01:16:54 +00:00
|
|
|
|
var pending = WithPendingMask.And(pendingBits);
|
|
|
|
|
var existing = WithExistingMask.And(existingBits);
|
|
|
|
|
var withCheck = pending.Or(existing).Or(NotWithMask);
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
2019-12-23 01:16:54 +00:00
|
|
|
|
var pendingForbidden = WithoutPendingMask.And(pendingBits);
|
|
|
|
|
var existingForbidden = WithoutExistingMask.And(existingBits);
|
|
|
|
|
var withoutCheck = pendingForbidden.And(existingForbidden);
|
|
|
|
|
|
|
|
|
|
if (withCheck.And(withoutCheck).AllTrue()) { yield return entity; }
|
|
|
|
|
}
|
2019-12-22 01:58:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|