com.artemis.systems.IntervalEntitySystem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artemis-odb Show documentation
Show all versions of artemis-odb Show documentation
Fork of Artemis Entity System Framework.
package com.artemis.systems;
import com.artemis.Aspect;
import com.artemis.EntitySystem;
/**
* A system that processes entities at a interval in milliseconds.
*
* A typical usage would be a collision system or physics system.
*
*
* @author Arni Arent
*/
public abstract class IntervalEntitySystem extends EntitySystem {
/** Accumulated delta to keep track of interval. */
protected float acc;
/** How long to wait between updates. */
private final float interval;
private float intervalDelta;
/**
* Creates a new IntervalEntitySystem.
* @param aspect
* the aspect to match entities
* @param interval
* the interval at which the system processes
*/
public IntervalEntitySystem(Aspect.Builder aspect, float interval) {
super(aspect);
this.interval = interval;
}
@Override
protected boolean checkProcessing() {
acc += getTimeDelta();
if(acc >= interval) {
acc -= interval;
intervalDelta = (acc - intervalDelta);
return true;
}
return false;
}
/**
* Gets the actual delta since this system was last processed.
*
* @return Time passed since last process round.
*/
protected float getIntervalDelta() {
return interval + intervalDelta;
}
protected float getTimeDelta() {
return world.getDelta();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy