IntervalEntitySystem abstract class
A system that processes entities at a interval in milliseconds. A typical usage would be a collision system or physics system.
abstract class IntervalEntitySystem extends EntitySystem {
num _acc = 0;
num _delta = 0;
final num _interval;
/// Returns the accumulated delta since the system was last invoked.
num get delta => _delta;
IntervalEntitySystem(this._interval, Aspect aspect) : super(aspect);
bool checkProcessing() {
_acc += world.delta;
_delta += world.delta;
if(_acc >= _interval) {
_acc -= _interval;
return true;
}
return false;
}
/**
* Resets the accumulated delta to 0.
*
* Call `super.end()` if you overwrite this function.
*/
void end() {
_delta = 0;
}
}
Extends
EntitySystem > IntervalEntitySystem
Subclasses
IntervalEntityProcessingSystem
Constructors
Properties
Methods
void begin() #
Called before processing of entities begins.
void begin() {}
bool checkProcessing() #
Returns true if the system should be processed, false if not.
bool checkProcessing() {
_acc += world.delta;
_delta += world.delta;
if(_acc >= _interval) {
_acc -= _interval;
return true;
}
return false;
}
void deleted(Entity e) #
void deleted(Entity e) {
if (_contains(e)) {
_removeFromSystem(e);
}
}
void disabled(Entity e) #
void disabled(Entity e) {
if (_contains(e)) {
_removeFromSystem(e);
}
}
void end() #
Resets the accumulated delta to 0.
Call super.end() if you overwrite this function.
void end() {
_delta = 0;
}
void initialize() #
Override to implement code that gets executed when systems are initialized.
void initialize() {}
void inserted(Entity entity) #
Called if the system has received an entity it is interested in, e.g. created or a component was added to it.
void inserted(Entity entity) {}
void process() #
This is the only method that is supposed to be called from outside the library,
void process() {
if(checkProcessing()) {
begin();
processEntities(_actives.readOnly);
end();
}
}
abstract void processEntities(ReadOnlyBag<Entity> entities) #
Any implementing entity system must implement this method and the logic to process the given entities of the system.
void removed(Entity entity) #
Called if an entity was removed from this system, e.g. deleted or had one of it's components removed.
void removed(Entity entity) {}