Java Code Examples for com.badlogic.ashley.core.Engine#getEntitiesFor()

The following examples show how to use com.badlogic.ashley.core.Engine#getEntitiesFor() . 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: EntityDeleterSystem.java    From entity-system-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
	public void addedToEngine(Engine engine) {
		this.engine = engine;
		entities = engine.getEntitiesFor(Family.all(PlainPosition.class).get());
//		engine.addEntityListener(new EntityListener() {
//			
//			@Override
//			public void entityRemoved(Entity entity) {
//				engine.remove(entity.getIndex());
//			}
//			
//			@Override
//			public void entityAdded(Entity entity) {
//				entities.put(entity.getIndex(), entity);
//			}
//		});
		for (int i = 0; ENTITY_COUNT > i; i++)
			createEntity();
	}
 
Example 2
Source File: EntityManglerSystem.java    From entity-system-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
public void addedToEngine(Engine engine) {
	for (int i = 0; permutations.length > i; i++) {
		Array<Class<? extends Component>> components = new Array<Class<? extends Component>>();
		for (int classIndex = 0, s = (int)(rng.nextFloat() * 7) + 3; s > classIndex; classIndex++) {
			components.add(types.get((int)(rng.nextFloat() * types.size)));
		}
		permutations[i] = components;
	}
	
	this.engine = engine;
	entities = engine.getEntitiesFor(Family.all().get());
	
	for (int i = 0; ENTITY_COUNT > i; i++)
		createEntity();
}
 
Example 3
Source File: PooledEntityDeleterSystem.java    From entity-system-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
	public void addedToEngine(Engine engine) {
		this.engine = (PooledEngine) engine;
		entities = engine.getEntitiesFor(Family.all(PlainPosition.class).get());
//		engine.addEntityListener(new EntityListener() {
//			
//			@Override
//			public void entityRemoved(Entity entity) {
//				entities.remove(entity.getIndex());
//			}
//			
//			@Override
//			public void entityAdded(Entity entity) {
//				entities.put(entity.getIndex(), entity);
//			}
//		});
		for (int i = 0; ENTITY_COUNT > i; i++)
			createEntity();
	}
 
Example 4
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 5
Source File: CollisionSystem.java    From ashley-superjumper with Apache License 2.0 5 votes vote down vote up
@Override
public void addedToEngine(Engine engine) {
	this.engine = engine;
	
	bobs = engine.getEntitiesFor(Family.all(BobComponent.class, BoundsComponent.class, TransformComponent.class, StateComponent.class).get());
	coins = engine.getEntitiesFor(Family.all(CoinComponent.class, BoundsComponent.class).get());
	squirrels = engine.getEntitiesFor(Family.all(SquirrelComponent.class, BoundsComponent.class).get());
	springs = engine.getEntitiesFor(Family.all(SpringComponent.class, BoundsComponent.class, TransformComponent.class).get());
	castles = engine.getEntitiesFor(Family.all(CastleComponent.class, BoundsComponent.class).get());
	platforms = engine.getEntitiesFor(Family.all(PlatformComponent.class, BoundsComponent.class, TransformComponent.class).get());
}
 
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);
}
 
Example 7
Source File: ExploreSystem.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Triggers when this system is added to Ashley engine.
 *
 * @param engine An instance of the engine
 */
public void addedToEngine(Engine engine) {
  entities = engine.getEntitiesFor(
      Family.all(PlayerComponent.class, ExploreComponent.class).get()
  );
}
 
Example 8
Source File: MouseMovementSystem.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Does this really need a comment? I GUESS SO.
 *
 * @param engine Ashley engine
 */
public void addedToEngine(Engine engine) {
  entities = engine.getEntitiesFor(
      Family.all(PlayerComponent.class, MouseMovementComponent.class).get()
  );
}
 
Example 9
Source File: IntervalIteratingSystem.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(family);
}
 
Example 10
Source File: IteratingSystem.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(family);
}
 
Example 11
Source File: CollisionSystem.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(Family.all(RadiusComponent.class).get());
}
 
Example 12
Source File: RemovalSystem.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(Family.all(RemovalComponent.class).get());
}
 
Example 13
Source File: BasicTest.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(Family.all(PositionComponent.class).get());
	log("PositionSystem added to engine.");
}
 
Example 14
Source File: BasicTest.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(Family.all(PositionComponent.class, MovementComponent.class).get());
	log("MovementSystem added to engine.");
}
 
Example 15
Source File: RenderSystem.java    From ashley with Apache License 2.0 4 votes vote down vote up
@Override
public void addedToEngine (Engine engine) {
	entities = engine.getEntitiesFor(Family.all(PositionComponent.class, VisualComponent.class).get());
}