2019-12-29 05:39:35 +00:00
|
|
|
|
using MoonTools.FastCollections;
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
|
{
|
2019-12-23 02:13:35 +00:00
|
|
|
|
internal struct EntitySetQuery
|
2019-12-22 01:58:07 +00:00
|
|
|
|
{
|
2019-12-29 05:39:35 +00:00
|
|
|
|
private BitSet512 WithImmediateMask { get; }
|
|
|
|
|
private BitSet512 WithExistingMask { get; }
|
|
|
|
|
private BitSet512 WithoutImmediateMask { get; }
|
|
|
|
|
private BitSet512 WithoutExistingMask { get; }
|
|
|
|
|
private BitSet512 NotWithMask { get; }
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
2019-12-29 05:39:35 +00:00
|
|
|
|
internal EntitySetQuery(BitSet512 withImmediateMask, BitSet512 withExistingMask, BitSet512 withoutImmediateMask, BitSet512 withoutExistingMask, BitSet512 notWithMask)
|
2019-12-22 01:58:07 +00:00
|
|
|
|
{
|
2019-12-24 03:04:26 +00:00
|
|
|
|
WithImmediateMask = withImmediateMask;
|
2019-12-23 01:16:54 +00:00
|
|
|
|
WithExistingMask = withExistingMask;
|
2019-12-24 03:04:26 +00:00
|
|
|
|
WithoutImmediateMask = withoutImmediateMask;
|
2019-12-23 01:16:54 +00:00
|
|
|
|
WithoutExistingMask = withoutExistingMask;
|
|
|
|
|
NotWithMask = notWithMask;
|
2019-12-22 01:58:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 21:54:08 +00:00
|
|
|
|
public bool CheckEntity(int entityID, ComponentBitSet componentBitSet)
|
2019-12-22 01:58:07 +00:00
|
|
|
|
{
|
2019-12-29 21:54:08 +00:00
|
|
|
|
var existingBits = componentBitSet.EntityBitArray(entityID);
|
2019-12-29 05:39:35 +00:00
|
|
|
|
var existing = (WithExistingMask & existingBits) | NotWithMask;
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
2019-12-29 05:39:35 +00:00
|
|
|
|
var existingForbidden = ~(WithoutExistingMask & existingBits);
|
2019-12-22 01:58:07 +00:00
|
|
|
|
|
2019-12-29 05:39:35 +00:00
|
|
|
|
return (existing & existingForbidden).AllTrue();
|
2019-12-28 21:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 21:54:08 +00:00
|
|
|
|
public bool ImmediateCheckEntity(int entityID, ComponentBitSet immediateBitLookup, ComponentBitSet existingBitLookup)
|
2019-12-28 21:53:02 +00:00
|
|
|
|
{
|
2019-12-29 21:54:08 +00:00
|
|
|
|
var immediateBits = immediateBitLookup.EntityBitArray(entityID);
|
|
|
|
|
var existingBits = existingBitLookup.EntityBitArray(entityID);
|
2019-12-28 21:53:02 +00:00
|
|
|
|
|
2019-12-29 05:39:35 +00:00
|
|
|
|
var immediate = WithImmediateMask & immediateBits;
|
|
|
|
|
var existing = WithExistingMask & existingBits;
|
|
|
|
|
var withCheck = immediate | existing | NotWithMask;
|
2019-12-28 21:53:02 +00:00
|
|
|
|
|
2019-12-29 05:39:35 +00:00
|
|
|
|
var immediateForbidden = ~(WithoutImmediateMask & immediateBits);
|
|
|
|
|
var existingForbidden = ~(WithoutExistingMask & existingBits);
|
|
|
|
|
var withoutCheck = immediateForbidden & existingForbidden;
|
2019-12-23 01:16:54 +00:00
|
|
|
|
|
2019-12-29 05:39:35 +00:00
|
|
|
|
return (withCheck & withoutCheck).AllTrue();
|
2019-12-22 01:58:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|