System_Emitters class
class System_Emitters extends EntityProcessingSystem { ComponentMapper<Emitter> _emitterMapper; num _dt = 0; System_Emitters() : super(Aspect.getAspectForAllOf([Emitter])); void initialize(){ _emitterMapper = new ComponentMapper<Emitter>(Emitter, world); } void begin(){ //TODO use an injected timer _dt = world.delta; } void processEntity(Entity entity) { var em = _emitterMapper.get(entity); var nb = em.counter(_dt); var ne = (em.genParticles != null) ? _genParticles(nb, em.genParticles) : _genEntities(nb); em.initializers.forEach((init) => init(_dt, entity, ne)); ne.forEach((e) => world.addEntity(e)); // em.particles.addAll(np); // em.activities.forEach((ue) => ue(_dt)); // em.actions.forEach((up) => up(_dt, em.particles)); if (em.once) entity.deleteFromWorld(); } List<Entity> _genEntities(int nb) { return new List<Entity>.generate(nb, (i) => world.createEntity()); } List<Entity> _genParticles(int nb, ParticlesConstructor pc) { var e = world.createEntity(); e.addComponent(pc(nb)); return new List<Entity>.filled(1, e); } }
Extends
EntitySystem > EntityProcessingSystem > System_Emitters
Constructors
new System_Emitters() #
Create a new EntityProcessingSystem. It requires at least one component.
System_Emitters() : super(Aspect.getAspectForAllOf([Emitter]));
Properties
Methods
void begin() #
Called before processing of entities begins.
void begin(){ //TODO use an injected timer _dt = world.delta; }
bool checkProcessing() #
Returns true if the system should be processed, false if not.
bool checkProcessing() => true;
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() #
Called after the processing of entities ends.
void end() {}
void initialize() #
Override to implement code that gets executed when systems are initialized.
void initialize(){ _emitterMapper = new ComponentMapper<Emitter>(Emitter, world); }
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(); } }
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 processEntities(ReadOnlyBag<Entity> entities) => entities.forEach((entity) => processEntity(entity));
void processEntity(Entity entity) #
Process a entity this system is interested in.
void processEntity(Entity entity) { var em = _emitterMapper.get(entity); var nb = em.counter(_dt); var ne = (em.genParticles != null) ? _genParticles(nb, em.genParticles) : _genEntities(nb); em.initializers.forEach((init) => init(_dt, entity, ne)); ne.forEach((e) => world.addEntity(e)); // em.particles.addAll(np); // em.activities.forEach((ue) => ue(_dt)); // em.actions.forEach((up) => up(_dt, em.particles)); if (em.once) entity.deleteFromWorld(); }
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) {}