junkdog / artemis-odb

A continuation of the popular Artemis ECS framework
BSD 2-Clause "Simplified" License
776 stars 111 forks source link

Proposal 2.5: Entity API #500

Closed DaanVanYperen closed 6 years ago

DaanVanYperen commented 7 years ago

This tickets intends to get you up to speed with proposal #499 and put it up for challenge. Love to hear what you guys think! Questions at the bottom.

Overview of changes

Int-only artemis-odb-core module

World world = new World(new WorldConfiguration().setSystem(MySystem));
class MySystem extends IteratingSystem {
        ComponentMapper<Pos> mPos;
        @Override
        public void initialize() {
            int id = world.create();
            mPos.create(id);
        } 

    @Override 
    protected void process(int entityId) { 
        mPos.get(entityId).x = MathUtils.random(100);  
    } 
}

Optional artemis-odb-entity module

World world = new EntityWorld(new WorldConfiguration().setSystem(MySystem));
class MySystem extends EntityProcessingSystem<Entity> {
        ComponentMapper<Pos> mPos;
        @Override
        public void initialize() {
            world.createEntity().edit().add(Pos.class); 
        } 

    @Override 
    protected void process(Entity e) { 
        mPos.get(e).x = MathUtils.random(100);  
    } 
}

Fluid entity API natural extension on artemis-odb-entity.

Extends CosplayWorld<T> For example: FluidWorld extends CosplayWorld<E>.

World world = new FluidWorld(new WorldConfiguration().setSystem(MySystem));
class MyFluid extends EntityProcessingSystem<E> {
        ComponentMapper<Pos> mPos;
        @Override
        public void initialize() {
            E().pos(); // In this case it returns E. 
            // Can also be used to obtain vanilla Entity. :)
        } 

    @Override 
    protected void process(E e) { 
                e.posX(MathUtils.random(100));
                for(E e : world.allEntitiesOf(Cat.class)) {
                      // do something.
                }
    } 
}

Your own Entity and World

World world = new MyWorld(new WorldConfiguration().setSystem(MySystem));
class MySystem extends EntityProcessingSystem<MyEntity> {
    @Override 
    protected void process(MyEntity e) { 
                e.clipTransfigurateMergeAll("grandmother");
                world.myOwnWorldMethod();
    } 
}

Impact when migrating to this new version should be relatively small.

Stuck points

madigan commented 7 years ago

What's the "best practice" for initializing components when working with the integer API? Would you just create a "factory system" and initialize everything using mappers there?