Java Code Examples for com.badlogic.gdx.utils.Bits#set()
The following examples show how to use
com.badlogic.gdx.utils.Bits#set() .
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 |
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 |
void updatePopPads(Bits bits, int x, int y) { if (popPads == null) return; for (PopPad popPad : popPads.values()) { if (popPad.contains(x, y)) { bits.set(DT1.Tile.Index.subIndex(popPad.id)); } } }
Example 3
Source File: NavMeshGraph.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Get an array of the vertex indices from the mesh. Any vertices which share the same position will be counted * as a single vertex and share the same index. That is, position duplicates will be filtered out. * * @param mesh * @return */ private static short[] getUniquePositionVertexIndices(Mesh mesh) { FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; // Number of array elements which make up a vertex int vertexSize = mesh.getVertexSize() / 4; // The indices tell us which vertices are part of a triangle. short[] indices = new short[mesh.getNumIndices()]; mesh.getIndices(indices); // Marks true if an index has already been compared to avoid unnecessary comparisons Bits handledIndices = new Bits(mesh.getNumIndices()); for (int i = 0; i < indices.length; i++) { short indexI = indices[i]; if (handledIndices.get(indexI)) { // Index handled in an earlier iteration continue; } int vBufIndexI = indexI * vertexSize + positionOffset; float xi = verticesBuffer.get(vBufIndexI++); float yi = verticesBuffer.get(vBufIndexI++); float zi = verticesBuffer.get(vBufIndexI++); for (int j = i + 1; j < indices.length; j++) { short indexJ = indices[j]; int vBufIndexJ = indexJ * vertexSize + positionOffset; float xj = verticesBuffer.get(vBufIndexJ++); float yj = verticesBuffer.get(vBufIndexJ++); float zj = verticesBuffer.get(vBufIndexJ++); if (xi == xj && yi == yj && zi == zj) { indices[j] = indexI; } } handledIndices.set(indexI); } return indices; }
Example 4
Source File: ComponentType.java From ashley with Apache License 2.0 | 5 votes |
/** * @param componentTypes list of {@link Component} classes * @return Bits representing the collection of components for quick comparison and matching. See * {@link Family#getFor(Bits, Bits, Bits)}. */ public static Bits getBitsFor (Class<? extends Component>... componentTypes) { Bits bits = new Bits(); int typesLength = componentTypes.length; for (int i = 0; i < typesLength; i++) { bits.set(ComponentType.getIndexFor(componentTypes[i])); } return bits; }
Example 5
Source File: FamilyManager.java From ashley with Apache License 2.0 | 5 votes |
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 6
Source File: FamilyManager.java From ashley with Apache License 2.0 | 4 votes |
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; } }