package zero1hd.polyjet.entity; import com.badlogic.gdx.utils.Pool; public class EntityFrame { private Pool pool; private EntityController ec; Class ct; EntityFrame ef; public EntityFrame(EntityController entityController, Class classType) { ct = classType; ef = this; ec = entityController; pool = new Pool() { @Override protected T newObject() { try { T entity = ct.newInstance(); entity.setup(ec, ef); return entity; } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); return null; } } }; } public T buildEntity() { T entity = pool.obtain(); if (entity.enemy) { ec.activeEnemies.add(entity); } else { ec.activeAllies.add(entity); } return entity; } /** * Free the entity if no longer used. * @param entity to be freed. */ public void recycleEntity(Entity entity) { if (entity.enemy) { ec.activeEnemies.removeValue(entity, true); } else { ec.activeAllies.removeValue(entity, true); } entity.remove(); pool.free(ct.cast(entity)); } }