public abstract class DelayedIteratingSystem extends BaseEntitySystem
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:
Within processExpired(Entity e)
you must call offerDelay(float delay) if the
entity's delay time is renewed. That method is also called by inserted(int entityId)
for each newly matched entity.
subscriptionworld| Constructor and Description |
|---|
DelayedIteratingSystem() |
DelayedIteratingSystem(Aspect.Builder aspect)
Creates a new DelayedEntityProcessingSystem.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkProcessing()
Does the system desire processing.
|
float |
getInitialTimeDelay()
Get the initial delay that the system was ordered to process entities
after.
|
protected abstract float |
getRemainingDelay(int entityId)
Return the delay until this entity should be processed.
|
float |
getRemainingTimeUntilProcessing()
Get the time until the system is scheduled to run at.
|
protected float |
getTimeDelta()
Overridable method to provide custom time delta.
|
protected void |
inserted(int entityId)
Called if entity has come into scope for this system, 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(int entityId,
float accumulatedDelta)
Process an entity this system is interested in.
|
protected abstract void |
processExpired(int entityId) |
protected void |
processSystem()
Process the system.
|
void |
stop()
Stops the system from running, aborts current countdown.
|
getEntityIds, getSubscription, inserted, removed, removed, setWorldbegin, dispose, end, getWorld, initialize, isEnabled, process, setEnabledpublic DelayedIteratingSystem(Aspect.Builder aspect)
aspect - the aspect to match against entitiespublic DelayedIteratingSystem()
protected final void processSystem()
BaseSystemprocessSystem in class BaseSystemprotected void inserted(int entityId)
BaseEntitySysteminserted in class BaseEntitySystementityId - the entity that was added to this systemprotected abstract float getRemainingDelay(int entityId)
entityId - entityprotected final boolean checkProcessing()
BaseSystemcheckProcessing in class BaseSystemboth must be true before the system will process.protected float getTimeDelta()
protected abstract void processDelta(int entityId,
float accumulatedDelta)
Substract the accumulatedDelta from the entities defined delay.
entityId - the entity to processaccumulatedDelta - the delta time since this system was last executedprotected abstract void processExpired(int entityId)
public 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 © 2019. All rights reserved.