I've been thinking about these Delay systems, DelayedEntitySystem and DelayedEntityProcessingSystem. They're a hassle to use. Extending them gives you no idea how they work. How you would tell the system to start a delayed run, when to do it, etc. You ended up having to do a lot of code just to make it work like it's supposed to.
I've changed it so there is only one system now, DelayedEntityProcessingSystem (deleted the other).
Now it should be simpler to use it. Here's an example usage of adding support to delete entities after a certain expiration time:
Code:
public class ExpiringSystem extends DelayedEntityProcessingSystem {
@Mapper
ComponentMapper<Expires> em;
public ExpiringSystem() {
super(Aspect.getAspectForAll(Expires.class));
}
@Override
protected void processDelta(Entity e, float accumulatedDelta) {
Expires expires = em.get(e);
expires.delay -= accumulatedDelta;
}
@Override
protected void processExpired(Entity e) {
e.deleteFromWorld();
}
@Override
protected float getRemainingDelay(Entity e) {
Expires expires = em.get(e);
return expires.delay;
}
}
The system only runs when some entity needs to be processed, but does not run every loop.
It automatically picks up on inserted entities, so no need to worry about them.
You need to override three methods:
In processDelta you must subtract the accumulatedDelta from all the entities "delay".
getRemainingDelay should return how much "delay" remains of the entity after the processDelta.
processExpired is called on all entities who's delay has expired.
I haven't pushed in the changes because I wonder if anyone actually used the other systems who think this change is in the wrong direction. This change is quite dramatic, but I think gives it a more useful purpose.