/** * Returns whether this Aspect would accept the given set. */ public boolean isInterested(BitVector 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; }
void preWrite(SaveFileFormat save) { entityIds.clear(); ConverterUtil.toBitVector(save.entities, entityIds); boolean foundNew = true; BitVector bs = entityIds; while (foundNew) { foundNew = false; for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { for (Field f : referencingFields) { foundNew |= findReferences(i, f, bs); } } } entityIds.toIntBag(save.entities); }
public void flip(int fromIndex, int toIndex) { checkRange(fromIndex, toIndex); int length = length(); set(array, fromIndex, toIndex); return; set(array, length, toIndex); toIndex = length; int first = wordIndex(fromIndex); int last = wordIndex(toIndex); int startBit = bitOffset(fromIndex); int end = bitOffset(toIndex); flipMaskedWord(array, first, startBit, end); flipMaskedWord(array, first++, startBit, 32); flipMaskedWord(array, last, 0, end); flipWord(array, i);
public BitVector(BitVector source) { this(); for (int id = source.nextSetBit(0); id != -1; id = source.nextSetBit(id + 1)) { set(id); } }
public BitVector get(int fromIndex, int toIndex) { checkRange(fromIndex, toIndex); int length = length(); if (toIndex >= length) { toIndex = length(); int rightShift = bitOffset(fromIndex); int subFrom = wordIndex(fromIndex); int subTo = wordIndex(toIndex + 31); JsArrayInteger subSet = slice(array, subFrom, subTo); int leftOvers = bitOffset(toIndex); if (leftOvers != 0) { maskOutWord(subSet, subTo - subFrom - 1, leftOvers, 32); return new BitVector(subSet); BitVector subSet = new BitVector(); int first = wordIndex(fromIndex); int last = wordIndex(toIndex); int end = 32 - (bitOffset(toIndex)); int word = getWord(array, first); subSet.set(0, word); int word = getWord(array, first++);
private Bag<ComponentMapper> getAdditions(BitVector origin) { ComponentTypeFactory tf = cm.typeFactory; Bag<ComponentMapper> types = new Bag(ComponentMapper.class); for (int i = additions.nextSetBit(0); i >= 0; i = additions.nextSetBit(i + 1)) { if (!origin.get(i)) types.add(cm.getMapper(tf.getTypeFor(i).getType())); } return types; }
int allocateIdentity(BitVector componentBits, ComponentManager cm) { Bag<ComponentMapper> mappers = new Bag<ComponentMapper>(ComponentMapper.class, componentBits.cardinality()); ComponentTypeFactory tf = cm.getTypeFactory(); for (int i = componentBits.nextSetBit(0); i >= 0; i = componentBits.nextSetBit(i + 1)) { mappers.add(cm.getMapper(tf.getTypeFor(i).getType())); } compositionMappers.add(mappers); compositionBits.add(new BitVector(componentBits)); return compositionBits.size() - 1; } }
public void clear(int fromIndex, int toIndex) { checkRange(fromIndex, toIndex); int length = length(); if (fromIndex >= length) { int newLength = wordIndex(fromIndex + 31); setLengthWords(array, newLength); if ((bitIndex(newLength)) - fromIndex != 0) { maskOutWord(array, newLength - 1, bitOffset(fromIndex), 32); int first = wordIndex(fromIndex); int last = wordIndex(toIndex); int startBit = bitOffset(fromIndex); int endBit = bitOffset(toIndex); maskOutWord(array, first, startBit, endBit); maskOutWord(array, first++, startBit, 32); maskOutWord(array, last, 0, endBit); deleteWord(array, i);
/** @param index the index of the bit * @return whether the bit is set * @throws ArrayIndexOutOfBoundsException if index < 0 or index >= words.length</></>*/ public boolean unsafeGet(int index) { return get(index); }
private void toEntityIntBags(BitVector changed, BitVector deleted) { changed.toIntBagIdCid(world.getComponentManager(), this.changed); deleted.toIntBag(this.deleted); changed.clear(); deleted.clear(); }
/** @param index the index of the bit to set * @throws ArrayIndexOutOfBoundsException if index < 0 or index >= words.length */ public void unsafeSet(int index, boolean value) { set(index, value); } }
private void purgeNoPool() { for (int id = idBits.nextSetBit(0); id >= 0; id = idBits.nextSetBit(id + 1)) { components.unsafeSet(id, null); } } }
TransmuteOperation createOperation(int entityId) { BitVector componentBits = cm.componentBits(entityId); bs.clear(); bs.or(componentBits); bs.or(additions); bs.andNot(removals); int compositionId = cm.compositionIdentity(bs); return new TransmuteOperation(compositionId, getAdditions(componentBits), getRemovals(componentBits)); }
/** * Decodes the set bits as integers. The destination * {@link IntBag} is reset before the bits are transposed. * * @param out decoded ints end up here * @return Same as out */ public IntBag toIntBag(IntBag out) { out.setSize(0); if (isEmpty()) return out; for (int id = nextSetBit(0); id >= 0; id = nextSetBit(id + 1)) { out.add(id); } return out; }