@Test public void recycleEntity() { PooledEngine engine = new PooledEngine(); int numEntities = 200; Array<Entity> entities = new Array<Entity>(); for (int i = 0; i < numEntities; ++i) { Entity entity = engine.createEntity(); assertEquals(0, entity.flags); engine.addEntity(entity); entities.add(entity); entity.flags = 1; } for (Entity entity : entities) { engine.removeEntity(entity); assertEquals(0, entity.flags); } for (int i = 0; i < numEntities; ++i) { Entity entity = engine.createEntity(); assertEquals(0, entity.flags); engine.addEntity(entity); entities.add(entity); } }
@Override public void update(float deltaTime) { Entity entity; PooledEngine engine = (PooledEngine) getEngine(); for (int i = 0; i < 10; i++) { entity = engine.createEntity(); assertEquals(0, entity.flags); entity.flags = 1; entity.add(engine.createComponent(PositionComponent.class)); engine.addEntity(entity); } for (int i = 0; i < entities.size(); ++i) { entity = entities.get(i); engine.removeEntity(entity); engine.removeEntity(entity); } }