1
\$\begingroup\$

I'm still thinking, how do I properly pool a bullet in libgdx ashley? Because the PooledEngine is available, which the Entities, Components and Systems are already Pooled. I made this below example, which I just create a builder-pattern to spawn a bullet. Without using the ashley ECS framework, I used this memory-management reference to create a bullet pool as result this made me more confused.

class EntityFactory {

     ...

     public EntityFactory(World world, PooledEngine engine) {

          this.engine = engine;
          this.world = world;

     }

     public Entity createBullet(float x, float y) {
          ...
     }

}

class GunSystem extends IteratingSystem {

     EntityFactory factory;

     public GunSystem(EntityFactory factory) {
          super(Mappers.gunFamily);
          this.factory = factory;
     }

     @Override
     public void processEntity(Entity entity, float deltaTime) {
          GunComponent gun = Mappers.gun.get(entity);
          NodeComponent node = Mappers.node.get(entity);              

          float bulletX = ...;
          float bulletY = ...;

          if(gun.reload) {
               Entity bullet = factory.createBullet(bulletX, bulletY);
               node.putChild("bullet", bullet);
          }


          if(gun.fire) {
               Entity bullet = node.getChild("bullet");
               ... move body to target destination
               BulletComponent b
               b.state.fired = true;
               node.removeChild("bullet");
          }

     }

}

Question what do you think is the proper way of creating bullet pool in ashley ecs framework?

\$\endgroup\$

0

You must log in to answer this question.

Browse other questions tagged .