public abstract class DelayedEntityProcessingSystem extends EntitySystem
An example system would be an ExpirationSystem, that deletes entities after a certain lifetime. Instead of running a system that decrements a timeLeft value for each entity, you can simply use this system to execute in a future at a time of the shortest lived entity, and then reset the system to run at a time in a future at a time of the shortest lived entity, etc.
Another example system would be an AnimationSystem. You know when you have to animate a certain entity, e.g. in 300 milliseconds. So you can set the system to run in 300 ms to perform the animation.
This will save CPU cycles in some scenarios.
Implementation notes:
In order to start the system you need to override the
inserted(Entity e) method, look up the delay time
from that entity and offer it to the system by using the
offerDelay(float delay) method. Also, when
processing the entities you must also call
offerDelay(float delay) for all valid entities.
world| Constructor and Description |
|---|
DelayedEntityProcessingSystem(Aspect aspect)
Creates a new DelayedEntityProcessingSystem.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkProcessing()
Check if the system should be processed.
|
float |
getInitialTimeDelay()
Get the initial delay that the system was ordered to process entities
after.
|
protected abstract float |
getRemainingDelay(Entity e)
Return the delay until this entity should be processed.
|
float |
getRemainingTimeUntilProcessing()
Get the time until the system is scheduled to run at.
|
protected void |
inserted(Entity e)
Called if the system has received a entity it is interested in, e.g
created or a component was added to it.
|
boolean |
isRunning()
Check if the system is counting down towards processing.
|
void |
offerDelay(float offeredDelay)
Restarts the system only if the delay offered is shorter than the time
that the system is currently scheduled to execute at.
|
protected abstract void |
processDelta(Entity e,
float accumulatedDelta)
Process a entity this system is interested in.
|
protected void |
processEntities(ImmutableBag<Entity> entities)
Any implementing entity system must implement this method and the logic
to process the given entities of the system.
|
protected abstract void |
processExpired(Entity e) |
void |
restart(float delay)
Deprecated.
bugged and unnecessary. don't use.
|
void |
stop()
Stops the system from running, aborts current countdown.
|
added, added, begin, changed, changed, check, deleted, deleted, disabled, dispose, enabled, end, getActives, initialize, isEnabled, isPassive, process, removed, setEnabled, setPassive, setWorldpublic DelayedEntityProcessingSystem(Aspect aspect)
aspect - the aspect to match against entitiesprotected final void processEntities(ImmutableBag<Entity> entities)
EntitySystemprocessEntities in class EntitySystementities - the entities this system contains.protected void inserted(Entity e)
EntitySysteminserted in class EntitySysteme - the entity that was added to this systemprotected abstract float getRemainingDelay(Entity e)
e - entityprotected final boolean checkProcessing()
EntitySystemcheckProcessing in class EntitySystemprotected abstract void processDelta(Entity e, float accumulatedDelta)
Substract the accumulatedDelta from the entities defined delay.
e - the entity to processaccumulatedDelta - the delta time since this system was last executedprotected abstract void processExpired(Entity e)
@Deprecated public void restart(float delay)
Cancels current delayed run and starts a new one.
delay - time delay until processing startspublic void offerDelay(float offeredDelay)
If the system is already stopped (not running) then the offered delay will be used to restart the system with no matter its value.
If the system is already counting down, and the offered delay is larger than the time remaining, the system will ignore it. If the offered delay is shorter than the time remaining, the system will restart itself to run at the offered delay.
offeredDelay - delay to offerpublic float getInitialTimeDelay()
public float getRemainingTimeUntilProcessing()
Returns zero (0) if the system is not running.
Use isRunning() before checking this value.
public boolean isRunning()
true if it's counting down, false if it's not runningpublic void stop()
Call offerDelay or restart to run it again.
Copyright © 2014. All Rights Reserved.