44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Encompass.Collections;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal struct EntitySetQuery
|
|
{
|
|
private BitSet512 WithPendingMask { get; }
|
|
private BitSet512 WithExistingMask { get; }
|
|
private BitSet512 WithoutPendingMask { get; }
|
|
private BitSet512 WithoutExistingMask { get; }
|
|
private BitSet512 NotWithMask { get; }
|
|
|
|
internal EntitySetQuery(BitSet512 withPendingMask, BitSet512 withExistingMask, BitSet512 withoutPendingMask, BitSet512 withoutExistingMask, BitSet512 notWithMask)
|
|
{
|
|
WithPendingMask = withPendingMask;
|
|
WithExistingMask = withExistingMask;
|
|
WithoutPendingMask = withoutPendingMask;
|
|
WithoutExistingMask = withoutExistingMask;
|
|
NotWithMask = notWithMask;
|
|
}
|
|
|
|
public IEnumerable<Entity> FilterEntities(IEnumerable<Entity> entities, ComponentBitSet pendingBitLookup, ComponentBitSet existingBitLookup)
|
|
{
|
|
foreach (var entity in entities)
|
|
{
|
|
var pendingBits = pendingBitLookup.EntityBitArray(entity);
|
|
var existingBits = existingBitLookup.EntityBitArray(entity);
|
|
|
|
var pending = WithPendingMask.And(pendingBits);
|
|
var existing = WithExistingMask.And(existingBits);
|
|
var withCheck = pending.Or(existing).Or(NotWithMask);
|
|
|
|
var pendingForbidden = WithoutPendingMask.And(pendingBits).Not();
|
|
var existingForbidden = WithoutExistingMask.And(existingBits).Not();
|
|
var withoutCheck = pendingForbidden.And(existingForbidden);
|
|
|
|
if (withCheck.And(withoutCheck).AllTrue()) { yield return entity; }
|
|
}
|
|
}
|
|
}
|
|
}
|