apotapov / gdx-artemis

Fork of artemis entity-system (http://gamadu.com/artemis/) refactored to integrate with Libgdx (http://libgdx.badlogicgames.com/)
Other
53 stars 5 forks source link

Deprecate/Replace DelayedProcessingEntitySystem #9

Closed apotapov closed 10 years ago

apotapov commented 10 years ago

The current implementation of DelayedProcessingEntitySystem is confusing and flawed.

The idea of delayed processing of entities is valid, however it seems unnatural for all the entities to live on the same timer seems badly designed.

It seems like a better approach would be to store the delay in a component that is unique for every entity and have the delayed processing system process entities according to their individual delay timer.

Something along the lines of:

public abstract class DelayComponent implements Component {
    public float delay;
}

public abstract class <T extends DelayComponent> DelayProcessingEntitySystem<T> extends EntityProcessingSystem {

    ComponentMapper<T> delayMapper;

    public void processEntity(Entity e) {
        if (delayMapper.get(e).delay < 0) {
            processExpired(Entity e);
        } else {
            delayMapper.get(e).delay -= world.getDelta();
        }
    }
}
apotapov commented 10 years ago

Look at using the Timer class instead of a delay component.