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 BitSet WithPendingMask { get; }
|
|
private BitSet WithExistingMask { get; }
|
|
private BitSet WithoutPendingMask { get; }
|
|
private BitSet WithoutExistingMask { get; }
|
|
private BitSet NotWithMask { get; }
|
|
|
|
internal EntitySetQuery(BitSet withPendingMask, BitSet withExistingMask, BitSet withoutPendingMask, BitSet withoutExistingMask, BitSet 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.ID);
|
|
var existingBits = existingBitLookup.EntityBitArray(entity.ID);
|
|
|
|
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; }
|
|
}
|
|
}
|
|
}
|
|
}
|