Java Code Examples for com.badlogic.ashley.utils.ImmutableArray#size()

The following examples show how to use com.badlogic.ashley.utils.ImmutableArray#size() . 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: EntityManager.java    From ashley with Apache License 2.0 6 votes vote down vote up
public void removeAllEntities(ImmutableArray<Entity> entities, boolean delayed) {
	if (delayed) {
		for(Entity entity: entities) {
			entity.scheduledForRemoval = true;
		}
		EntityOperation operation = entityOperationPool.obtain();
		operation.type = EntityOperation.Type.RemoveAll;
		operation.entities = entities;
		pendingOperations.add(operation);
	}
	else {
		while(entities.size() > 0) {
			removeEntity(entities.first(), false);
		}
	}
}
 
Example 2
Source File: Engine.java    From ashley with Apache License 2.0 6 votes vote down vote up
/**
 * Updates all the systems in this Engine.
 * @param deltaTime The time passed since the last frame.
 */
public void update(float deltaTime){
	if (updating) {
		throw new IllegalStateException("Cannot call update() on an Engine that is already updating.");
	}
	
	updating = true;
	ImmutableArray<EntitySystem> systems = systemManager.getSystems();
	try {
		for (int i = 0; i < systems.size(); ++i) {
			EntitySystem system = systems.get(i);
			
			if (system.checkProcessing()) {
				system.update(deltaTime);
			}

			while(componentOperationHandler.hasOperationsToProcess() || entityManager.hasPendingOperations()) {
				componentOperationHandler.processOperations();
				entityManager.processPendingOperations();
			}
		}
	}
	finally {
		updating = false;
	}	
}
 
Example 3
Source File: IntervalIteratingTest.java    From ashley with Apache License 2.0 6 votes vote down vote up
@Test
public void intervalSystem () {
	Engine engine = new Engine();
	IntervalIteratingSystemSpy intervalSystemSpy = new IntervalIteratingSystemSpy();
	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(IntervalComponentSpy.class).get());
	ComponentMapper<IntervalComponentSpy> im = ComponentMapper.getFor(IntervalComponentSpy.class);

	engine.addSystem(intervalSystemSpy);

	for (int i = 0; i < 10; ++i) {
		Entity entity = new Entity();
		entity.add(new IntervalComponentSpy());
		engine.addEntity(entity);
	}

	for (int i = 1; i <= 10; ++i) {
		engine.update(deltaTime);

		for (int j = 0; j < entities.size(); ++j) {
			assertEquals(i / 2, im.get(entities.get(j)).numUpdates);
		}
	}
}
 
Example 4
Source File: EngineTests.java    From ashley with Apache License 2.0 6 votes vote down vote up
@Test
public void entitySystemRemovalWhileIterating () {
	Engine engine = new Engine();

	engine.addSystem(new CounterSystem());

	for (int i = 0; i < 20; ++i) {
		Entity entity = new Entity();
		entity.add(new CounterComponent());
		engine.addEntity(entity);
	}

	ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.all(CounterComponent.class).get());

	for (int i = 0; i < entities.size(); ++i) {
		assertEquals(0, entities.get(i).getComponent(CounterComponent.class).counter);
	}

	engine.update(deltaTime);

	for (int i = 0; i < entities.size(); ++i) {
		assertEquals(1, entities.get(i).getComponent(CounterComponent.class).counter);
	}
}
 
Example 5
Source File: WorldRenderer.java    From xibalba with MIT License 5 votes vote down vote up
private void renderPlayer() {
  ImmutableArray<Entity> entities =
      WorldManager.engine.getEntitiesFor(Family.all(PlayerComponent.class).get());

  if (entities.size() > 0) {
    Entity player = entities.first();

    if (Main.tweenManager.getRunningTimelinesCount() == 0) {
      PositionComponent position = ComponentMappers.position.get(player);
      WorldManager.entityHelpers.updateSprite(player, position.pos.x, position.pos.y);
    }

    ComponentMappers.visual.get(player).sprite.draw(batch);
  }
}
 
Example 6
Source File: SortedIteratingSystem.java    From ashley with Apache License 2.0 5 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	ImmutableArray<Entity> newEntities = engine.getEntitiesFor(family);
	sortedEntities.clear();
	if (newEntities.size() > 0) {
		for (int i = 0; i < newEntities.size(); ++i) {
			sortedEntities.add(newEntities.get(i));
		}
		sortedEntities.sort(comparator);
	}
	shouldSort = false;
	engine.addEntityListener(family, this);
}