public void Associate(ComponentTypeFactory tf, Bag<Type> types, BitSet componentBits) { foreach (var t in types) { componentBits.Set(tf.GetIndexFor(t)); } }
/** * Returns whether this Aspect would accept the given set. */ public bool IsInterested(BitSet componentBits) { // Check if the entity possesses ALL of the components defined in the aspect. if (!allSet.IsEmpty()) { for (int i = allSet.NextSetBit(0); i >= 0; i = allSet.NextSetBit(i + 1)) { if (!componentBits.Get(i)) { return false; } } } // If we are STILL interested, // Check if the entity possesses ANY of the exclusion components, if it does then the system is not interested. if (!exclusionSet.IsEmpty() && exclusionSet.Intersects(componentBits)) { return false; } // If we are STILL interested, // Check if the entity possesses ANY of the components in the oneSet. If so, the system is interested. if (!oneSet.IsEmpty() && !oneSet.Intersects(componentBits)) { return false; } return true; }
private void ToEntityIntBags(BitSet changed, BitSet deleted) { changedIds = changed.ToIntBag(); deletedIds = deleted.ToIntBag(); changed.Clear(); deleted.Clear(); }
public void ProcessComponentIdentity(int id, BitSet componentBits) { foreach (var s in subscriptions) { EntitySubscription subscriber = s; subscriber.ProcessComponentIdentity(id, componentBits); } }
internal EntityEditPool(EntityManager entityManager) { em = entityManager; edited = new Bag<EntityEdit>(); alternateEdited = new Bag<EntityEdit>(); editedIds = new BitSet(); pendingDeletion = new BitSet(); }
public void Process(BitSet changed, BitSet deleted) { ToEntityIntBags(changed, deleted); // note: processAll != process //TODO subscriptions[0].ProcessAll(changedIds, deletedIds); foreach (var s in subscriptions) { EntitySubscription subscriber = s; subscriber.Process(changedIds, deletedIds); } }
public EntitySubscription(World world, AspectPromise builder) { aspect = builder.Build(world); promise = builder; aspectCache = new BitSet(); em = world.EntityManager; activeEntityIds = new BitSet(); entities = new Bag<int>(); listeners = new Bag<ISubscriptionListener>(); insertedIds = new BitSet(); removedIds = new BitSet(); inserted = new Bag<int>(); removed = new Bag<int>(); }
/// <summary> /// Performs the logical AND operation on this bit set and the /// complement of the given <code>bs</code>. This means it /// selects every element in the first set, that isn't in the /// second set. The result is stored into this bit set and is /// effectively the set difference of the two. /// </summary> /// <param name="bs">the second bit set</param> public void AndNot(BitSet bs) { int i = Math.Min(bits.Length, bs.bits.Length); while (--i >= 0) bits[i] &= ~bs.bits[i]; }
public Aspect() { this.allSet = new BitSet(); this.exclusionSet = new BitSet(); this.oneSet = new BitSet(); }
public RecyclingEntityFactory(EntityManager em) { this.em = em; recycled = new BitSet(); limbo = new Queue<int>(64); }
/// <summary> /// Performs the logical AND operation on this bit set and the /// given <code>set</code>. This means it builds the intersection /// of the two sets. The result is stored into this bit set. /// </summary> /// <param name="bs">the second bit set</param> public void And(BitSet bs) { int max = Math.Min(bits.Length, bs.bits.Length); int i; for (i = 0; i < max; ++i) bits[i] &= bs.bits[i]; while (i < bits.Length) bits[i++] = 0; }
// This is used by EnumSet for efficiency. public bool ContainsAll(BitSet other) { for (int i = other.bits.Length - 1; i >= 0; i--) { if ((bits[i] & other.bits[i]) != other.bits[i]) return false; } return true; }
/// <summary> /// Performs the logical XOR operation on this bit set and the /// given <code>set</code>. This means it builds the symmetric /// remainder of the two sets (the elements that are in one set, /// but not in the other). The result is stored into this bit set, /// which grows as necessary. /// </summary> /// <param name="bs">the second bit set</param> public void XOr(BitSet bs) { Ensure(bs.bits.Length - 1); for (int i = bs.bits.Length - 1; i >= 0; i--) bits[i] ^= bs.bits[i]; }
/// <summary> /// Returns true if the specified BitSet and this one share at least one /// common true bit. /// </summary> /// <param name="set">the set to check for intersection</param> /// <returns>true if the sets intersect</returns> public bool Intersects(BitSet set) { int i = Math.Min(bits.Length, set.bits.Length); while (--i >= 0) { if ((bits[i] & set.bits[i]) != 0) return true; } return false; }
/// <summary> /// Returns a new <code>BitSet</code> composed of a range of bits from /// this one. /// </summary> /// <param name="from">the low index (inclusive)</param> /// <param name="to">the high index (exclusive)</param> /// <returns></returns> public BitSet Get(int from, int to) { if (from < 0 || from > to) throw new ArgumentOutOfRangeException(); BitSet bs = new BitSet(to - from); int lo_offset = from >> 6; if (lo_offset >= bits.Length || to == from) return bs; int lo_bit = from & LONG_MASK; int hi_offset = to >> 6; if (lo_bit == 0) { int len = Math.Min(hi_offset - lo_offset + 1, bits.Length - lo_offset); Array.Copy(bits, lo_offset, bs.bits, 0, len); if (hi_offset < bits.Length) bs.bits[hi_offset - lo_offset] &= (1L << to) - 1; return bs; } int len2 = Math.Min(hi_offset, bits.Length - 1); int reverse = 64 - lo_bit; int i; for (i = 0; lo_offset < len2; lo_offset++, i++) bs.bits[i] = ((bits[lo_offset] >> lo_bit) | (bits[lo_offset + 1] << reverse)); if ((to & LONG_MASK) > lo_bit) bs.bits[i++] = bits[lo_offset] >> lo_bit; if (hi_offset < bits.Length) bs.bits[i - 1] &= (1L << (to - from)) - 1; return bs; }
/** Fetch unique identity for passed composition. */ public int GetIdentity(BitSet components) { int i=0; foreach(var c in composition) { if (components.Equals(c)) return i; i++; } composition.Add((BitSet)components.Clone()); return composition.Size; }
/// <summary> /// Fetches unique identifier for composition. /// </summary> /// <param name="componentBits">composition to fetch unique identifier for</param> /// <returns>Unique identifier for passed composition</returns> private int CompositionIdentity(BitSet componentBits) { int identity = identityResolver.GetIdentity(componentBits); if (identity > highestSeenIdentity) { World.AspectSubscriptionManager.ProcessComponentIdentity(identity, componentBits); highestSeenIdentity = identity; } return identity; }
/// <summary> /// A new unique component composition detected, check if this subscription's aspect is interested in it. /// </summary> /// <param name="i"></param> /// <param name="componentBits"></param> public void ProcessComponentIdentity(int id, BitSet componentBits) { aspectCache.Set(id, aspect.IsInterested(componentBits)); }