Java Code Examples for com.badlogic.gdx.utils.Bits#clear()

The following examples show how to use com.badlogic.gdx.utils.Bits#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FamilyManager.java    From ashley with Apache License 2.0 6 votes vote down vote up
public void removeEntityListener (EntityListener listener) {
	for (int i = 0; i < entityListeners.size; i++) {
		EntityListenerData entityListenerData = entityListeners.get(i);
		if (entityListenerData.listener == listener) {
			// Shift down bitmasks by one step
			for (Bits mask : entityListenerMasks.values()) {
				for (int k = i, n = mask.length(); k < n; k++) {
					if (mask.get(k + 1)) {
						mask.set(k);
					} else {
						mask.clear(k);
					}
				}
			}

			entityListeners.removeIndex(i--);
		}
	}
}
 
Example 2
Source File: Map.java    From riiablo with Apache License 2.0 5 votes vote down vote up
/**
 * @param x   world sub-tile
 * @param y   world sub-tile
 * @param tx  world tile
 * @param ty  world tile
 * @param stx sub-tile (0-4)
 * @param sty sub-tile (0-4)
 */
// TODO: x,y alone should be enough, but others are available in MapRenderer on each position change anyways
public void updatePopPads(Bits bits, int x, int y, int tx, int ty, int stx, int sty) {
  bits.clear();
  Zone zone = getZone(x, y);
  if (zone != null) {
    Map.Preset preset = zone.getGrid(tx, ty);
    if (preset != null) {
      int presetX = zone.getGridX(tx) + stx;
      int presetY = zone.getGridX(ty) + sty;
      preset.updatePopPads(bits, presetX, presetY);
    }
  }
}
 
Example 3
Source File: FamilyManager.java    From ashley with Apache License 2.0 5 votes vote down vote up
public void addEntityListener (Family family, int priority, EntityListener listener) {
	registerFamily(family);

	int insertionIndex = 0;
	while (insertionIndex < entityListeners.size) {
		if (entityListeners.get(insertionIndex).priority <= priority) {
			insertionIndex++;
		} else {
			break;
		}
	}

	// Shift up bitmasks by one step
	for (Bits mask : entityListenerMasks.values()) {
		for (int k = mask.length(); k > insertionIndex; k--) {
			if (mask.get(k - 1)) {
				mask.set(k);
			} else {
				mask.clear(k);
			}
		}
		mask.clear(insertionIndex);
	}

	entityListenerMasks.get(family).set(insertionIndex);

	EntityListenerData entityListenerData = new EntityListenerData();
	entityListenerData.listener = listener;
	entityListenerData.priority = priority;
	entityListeners.insert(insertionIndex, entityListenerData);
}
 
Example 4
Source File: GameStage.java    From GdxDemo3D with Apache License 2.0 4 votes vote down vote up
public Bits getVisibleLayers(Bits out) {
	out.clear();
	out.or(visibleLayers);
	return out;
}
 
Example 5
Source File: FamilyManager.java    From ashley with Apache License 2.0 4 votes vote down vote up
public void updateFamilyMembership (Entity entity) {
	// Find families that the entity was added to/removed from, and fill
	// the bitmasks with corresponding listener bits.
	Bits addListenerBits = bitsPool.obtain();
	Bits removeListenerBits = bitsPool.obtain();

	for (Family family : entityListenerMasks.keys()) {
		final int familyIndex = family.getIndex();
		final Bits entityFamilyBits = entity.getFamilyBits();

		boolean belongsToFamily = entityFamilyBits.get(familyIndex);
		boolean matches = family.matches(entity) && !entity.removing;

		if (belongsToFamily != matches) {
			final Bits listenersMask = entityListenerMasks.get(family);
			final Array<Entity> familyEntities = families.get(family);
			if (matches) {
				addListenerBits.or(listenersMask);
				familyEntities.add(entity);
				entityFamilyBits.set(familyIndex);
			} else {
				removeListenerBits.or(listenersMask);
				familyEntities.removeValue(entity, true);
				entityFamilyBits.clear(familyIndex);
			}
		}
	}

	// Notify listeners; set bits match indices of listeners
	notifying = true;
	Object[] items = entityListeners.begin();

	try {
		for (int i = removeListenerBits.nextSetBit(0); i >= 0; i = removeListenerBits.nextSetBit(i + 1)) {
			((EntityListenerData)items[i]).listener.entityRemoved(entity);
		}

		for (int i = addListenerBits.nextSetBit(0); i >= 0; i = addListenerBits.nextSetBit(i + 1)) {
			((EntityListenerData)items[i]).listener.entityAdded(entity);
		}
	}
	finally {
		addListenerBits.clear();
		removeListenerBits.clear();
		bitsPool.free(addListenerBits);
		bitsPool.free(removeListenerBits);
		entityListeners.end();
		notifying = false;	
	}
}