Java Code Examples for com.badlogic.gdx.utils.Array#removeValue()

The following examples show how to use com.badlogic.gdx.utils.Array#removeValue() . 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: Messager.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void update (Position group) {
	Array<Message> msgs = messages.get(group.ordinal());

	for (Message msg : msgs) {
		// any message?
		if (msg == null && (msgs.size > 0 && msgs.first() != null)) {
			// schedule next message to process
			msg = msgs.first();
			msgs.removeValue(msg, true);
		}

		// busy or became busy?
		if (msg != null && !msg.isCompleted()) {
			// start message if needed
			if (!msg.started) {
				msg.started = true;
				msg.startMs = System.currentTimeMillis();
				msg.show();
			}

			// check if finished
			long much = (long)((System.currentTimeMillis() - msg.startMs) /* URacer.timeMultiplier */);
			if (msg.isShowComplete() && much >= msg.durationMs) {
				// message should end
				msg.hide();
			}
		}
	}
}
 
Example 2
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackTop(PackModel pack) {
    ensurePackExists(pack);

    Array<PackModel> packs = getProject().getPacks();
    // Check if pack is already at the top
    if (packs.indexOf(pack, true) == 0) return;

    packs.removeValue(pack, true);
    packs.insert(0, pack);
    eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 3
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackBottom(PackModel pack) {
    ensurePackExists(pack);

    Array<PackModel> packs = getProject().getPacks();
    int idx = packs.indexOf(pack, true);
    // Check if pack is already at the bottom
    if (idx == packs.size-1) return;

    packs.removeValue(pack, true);
    packs.insert(packs.size-1, pack);
    eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 4
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackNextTo(PackModel anchor, PackModel pack) {
       ensurePackExists(anchor);
       ensurePackExists(pack);

       Array<PackModel> packs = getProject().getPacks();
       int idxAnchor = packs.indexOf(anchor, true);
       int idxPack = packs.indexOf(pack, true);
       // Check if pack is already next to anchor
       if (idxAnchor-idxPack == -1) return;

       packs.removeValue(pack, true);
       packs.insert(idxAnchor+1, pack);
	eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 5
Source File: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public void movePackPrevTo(PackModel anchor, PackModel pack) {
       ensurePackExists(anchor);
       ensurePackExists(pack);

       Array<PackModel> packs = getProject().getPacks();
       int idxAnchor = packs.indexOf(anchor, true);
       int idxPack = packs.indexOf(pack, true);
       // Check if pack is already previous to anchor
       if (idxAnchor-idxPack == 1) return;

       packs.removeValue(pack, true);
       packs.insert(idxAnchor, pack);
	eventDispatcher.postEvent(new PackListOrderChangedEvent());
}
 
Example 6
Source File: PdAudioBase.java    From gdx-pd with Apache License 2.0 5 votes vote down vote up
@Override
public void removeListener(String source, PdListener listener) {
	Array<PdListener> contextualListeners = listeners.get(source);
	if(contextualListeners != null){
		contextualListeners.removeValue(listener, true);
		if(contextualListeners.size <= 0){
			PdBase.unsubscribe(source);
			listeners.remove(source);
		}
	}
}
 
Example 7
Source File: PdAudioRemote.java    From gdx-pd with Apache License 2.0 5 votes vote down vote up
@Override
public void removeListener(String source, PdListener listener) {
	Array<PdListener> listeners = this.listeners.get(source);
	if(listeners != null){
		listeners.removeValue(listener, true);
	}
}
 
Example 8
Source File: DT1s.java    From riiablo with Apache License 2.0 5 votes vote down vote up
void remove(DT1.Tile tile) {
  //if (tile.rarity == 0) return;
  Array<DT1.Tile> tiles = this.tiles.get(tile.id);
  if (tiles == null) return;
  tiles.removeValue(tile, true);
  prob.getAndIncrement(tile.id, 0, -tile.rarity);
}
 
Example 9
Source File: MessageDispatcher.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Unregister the specified listener for the specified message code.
 * @param listener the listener to remove
 * @param msg the message code */
public void removeListener (Telegraph listener, int msg) {
	Array<Telegraph> listeners = msgListeners.get(msg);
	if (listeners != null) {
		listeners.removeValue(listener, true);
	}
}
 
Example 10
Source File: FamilyManagerTests.java    From ashley with Apache License 2.0 5 votes vote down vote up
@Test
public void entityForFamilyWithRemoval () {
	Array<Entity> entities = new Array<Entity>();
	ImmutableArray<Entity> immutableEntities = new ImmutableArray<Entity>(entities);
	FamilyManager manager = new FamilyManager(immutableEntities);

	Entity entity = new Entity();
	entity.add(new ComponentA());

	entities.add(entity);
	
	manager.updateFamilyMembership(entity);
	
	ImmutableArray<Entity> familyEntities = manager.getEntitiesFor(Family.all(ComponentA.class).get());
	
	assertEquals(1, familyEntities.size());
	assertTrue(familyEntities.contains(entity, true));
	
	entity.removing = true;
	entities.removeValue(entity, true);
	
	manager.updateFamilyMembership(entity);
	entity.removing = false;

	assertEquals(0, familyEntities.size());
	assertFalse(familyEntities.contains(entity, true));
}
 
Example 11
Source File: Animation.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public boolean removeAnimationListener(int frame, AnimationListener l) {
  if (l == null || animationListeners == EMPTY_MAP) return false;
  Array<AnimationListener> listeners = animationListeners.get(frame);
  if (listeners == null) return false;
  return listeners.removeValue(l, true);
}
 
Example 12
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;	
	}
}
 
Example 13
Source File: FamilyManagerTests.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Test
public void entitiesForFamilyWithRemoval () {
	Array<Entity> entities = new Array<Entity>();
	ImmutableArray<Entity> immutableEntities = new ImmutableArray<Entity>(entities);
	FamilyManager manager = new FamilyManager(immutableEntities);

	Family family = Family.all(ComponentA.class, ComponentB.class).get();
	ImmutableArray<Entity> familyEntities = manager.getEntitiesFor(family);

	Entity entity1 = new Entity();
	Entity entity2 = new Entity();
	Entity entity3 = new Entity();
	Entity entity4 = new Entity();

	entities.add(entity1);
	entities.add(entity2);
	entities.add(entity3);
	entities.add(entity4);

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

	entity2.add(new ComponentA());
	entity2.add(new ComponentC());

	entity3.add(new ComponentA());
	entity3.add(new ComponentB());
	entity3.add(new ComponentC());

	entity4.add(new ComponentA());
	entity4.add(new ComponentB());
	entity4.add(new ComponentC());
	
	manager.updateFamilyMembership(entity1);
	manager.updateFamilyMembership(entity2);
	manager.updateFamilyMembership(entity3);
	manager.updateFamilyMembership(entity4);

	assertEquals(3, familyEntities.size());
	assertTrue(familyEntities.contains(entity1, true));
	assertTrue(familyEntities.contains(entity3, true));
	assertTrue(familyEntities.contains(entity4, true));
	assertFalse(familyEntities.contains(entity2, true));

	entity1.remove(ComponentA.class);
	entity3.removing = true;
	entities.removeValue(entity3, true);

	manager.updateFamilyMembership(entity1);
	manager.updateFamilyMembership(entity3);
	
	entity3.removing = false;
	
	assertEquals(1, familyEntities.size());
	assertTrue(familyEntities.contains(entity4, true));
	assertFalse(familyEntities.contains(entity1, true));
	assertFalse(familyEntities.contains(entity3, true));
	assertFalse(familyEntities.contains(entity2, true));
}