/// <summary> /// Creates a new bitset for entity, sets the bitset for no components, and pushes it onto the free entities stack. /// This method should be called in a loop over all entities and should include the initialization of a new component /// at the index of the entity in that component array. /// </summary> /// <param name="entity">Entity to initialize.</param> protected virtual void Initialize(uint entity) { EntityMasks[entity] = new BitSet(); EntityMasks[entity].SetBit(ComponentType.NoComponents); _freeEntities.Push((uint)entity); }
/// <summary> /// Determines whether all of the bits in this instance are also set in the given bitset. /// </summary> /// <param name="other">The bitset to check.</param> /// <returns><c>true</c> if all of the bits in this instance are set in <paramref name="other"/>; otherwise, <c>false</c>.</returns> public bool IsSubsetOf(BitSet other) { if (other == null) throw new ArgumentNullException("other"); var otherBits = other.bits; int count = Math.Min(bits.Length, otherBits.Length); for (int i = 0; i < count; i++) { uint bit = bits[i]; if ((bit & otherBits[i]) != bit) return false; } // handle extra bits on our side that might just be all zero int extra = bits.Length - count; for (int i = count; i < extra; i++) { if (bits[i] != 0) return false; } return true; }