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

The following examples show how to use com.badlogic.gdx.utils.Bits#length() . 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: Family.java    From ashley with Apache License 2.0 5 votes vote down vote up
private static String getBitsString (Bits bits) {
	StringBuilder stringBuilder = new StringBuilder();

	int numBits = bits.length();
	for (int i = 0; i < numBits; ++i) {
		stringBuilder.append(bits.get(i) ? "1" : "0");
	}

	return stringBuilder.toString();
}
 
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: EntityTests.java    From ashley with Apache License 2.0 5 votes vote down vote up
@Test
public void addAndRemoveComponent () {
	Entity entity = new Entity();

	entity.add(new ComponentA());

	assertEquals(1, entity.getComponents().size());

	Bits componentBits = entity.getComponentBits();
	int componentAIndex = ComponentType.getIndexFor(ComponentA.class);

	for (int i = 0; i < componentBits.length(); ++i) {
		assertEquals(i == componentAIndex, componentBits.get(i));
	}

	assertNotNull(am.get(entity));
	assertNull(bm.get(entity));
	assertTrue(am.has(entity));
	assertFalse(bm.has(entity));

	entity.remove(ComponentA.class);

	assertEquals(0, entity.getComponents().size());

	for (int i = 0; i < componentBits.length(); ++i) {
		assertFalse(componentBits.get(i));
	}

	assertNull(am.get(entity));
	assertNull(bm.get(entity));
	assertFalse(am.has(entity));
	assertFalse(bm.has(entity));
}
 
Example 5
Source File: EntityTests.java    From ashley with Apache License 2.0 5 votes vote down vote up
@Test
public void addAndRemoveAllComponents () {
	Entity entity = new Entity();

	entity.add(new ComponentA());
	entity.add(new ComponentB());

	assertEquals(2, entity.getComponents().size());

	Bits componentBits = entity.getComponentBits();
	int componentAIndex = ComponentType.getIndexFor(ComponentA.class);
	int componentBIndex = ComponentType.getIndexFor(ComponentB.class);

	for (int i = 0; i < componentBits.length(); ++i) {
		assertEquals(i == componentAIndex || i == componentBIndex, componentBits.get(i));
	}

	assertNotNull(am.get(entity));
	assertNotNull(bm.get(entity));
	assertTrue(am.has(entity));
	assertTrue(bm.has(entity));

	entity.removeAll();

	assertEquals(0, entity.getComponents().size());

	for (int i = 0; i < componentBits.length(); ++i) {
		assertFalse(componentBits.get(i));
	}

	assertNull(am.get(entity));
	assertNull(bm.get(entity));
	assertFalse(am.has(entity));
	assertFalse(bm.has(entity));
}