<commit_before>package com.artemis.systems;

import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.EntitySystem;
import com.artemis.utils.Bag;
import com.artemis.utils.ImmutableBag;


/**
 * The purpose of this class is to allow systems to execute at varying
 * intervals.
 * <p>
 * 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.
 * </p><p>
 * 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.
 * </p><p>
 * This will save CPU cycles in some scenarios.
 * </p><p>
 * Implementation notes:<br />
 * In order to start the system you need to override the
 * {@link #inserted(Entity) inserted(Entity e)} method, look up the delay time
 * from that entity and offer it to the system by using the
 * {@link #offerDelay(float) offerDelay(float delay)} method. Also, when
 * processing the entities you must also call
 * {@link #offerDelay(float) offerDelay(float delay)} for all valid entities.
 * </p><p>
 *
 * @author <NAME>
 */
public abstract class DelayedEntityProcessingSystem extends EntitySystem {

	/** The time until an entity should be processed. */
	private float delay;
	/**	If the system is running and counting down delays. */
	private boolean running;
	/** The countdown, accumulates world deltas. */
	private float acc;


	/**
	 * Creates a new DelayedEntityProcessingSystem.
	 *
	 * @param aspect
	 *			the aspect to match against entities
	 */
	public DelayedEntityProcessingSystem(Aspect aspect) {
		super(aspect);
	}



	@Override
	protected final void processEntities(ImmutableBag<Entity> entities) {
		Object[] array = ((Bag<Entity>)entities).getData();
		for (int i = 0, s = entities.size(); s > i; i++) {
			Entity entity = (Entity)array[i];
			processDelta(entity, acc);
			float remaining = getRemainingDelay(entity);
			if(remaining <= 0) {
				processExpired(entity);
			} else {
				offerDelay(remaining);
			}
		}
		stop();
	}


	@Override
	protected void inserted(Entity e) {
		float remainingDelay = getRemainingDelay(e);
		processDelta(e, -acc);
		if(remainingDelay > 0) {
			offerDelay(remainingDelay);
		}
	}<commit_msg>Possible fix for #32.<commit_after>package com.artemis.systems;

import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.EntitySystem;
import com.artemis.utils.Bag;
import com.artemis.utils.ImmutableBag;


/**
 * The purpose of this class is to allow systems to execute at varying
 * intervals.
 * <p>
 * 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.
 * </p><p>
 * 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.
 * </p><p>
 * This will save CPU cycles in some scenarios.
 * </p><p>
 * Implementation notes:<br />
 * In order to start the system you need to override the
 * {@link #inserted(Entity) inserted(Entity e)} method, look up the delay time
 * from that entity and offer it to the system by using the
 * {@link #offerDelay(float) offerDelay(float delay)} method. Also, when
 * processing the entities you must also call
 * {@link #offerDelay(float) offerDelay(float delay)} for all valid entities.
 * </p><p>
 *
 * @author <NAME>
 */
public abstract class DelayedEntityProcessingSystem extends EntitySystem {

	/** The time until an entity should be processed. */
	private float delay;
	/**	If the system is running and counting down delays. */
	private boolean running;
	/** The countdown, accumulates world deltas. */
	private float acc;


	/**
	 * Creates a new DelayedEntityProcessingSystem.
	 *
	 * @param aspect
	 *			the aspect to match against entities
	 */
	public DelayedEntityProcessingSystem(Aspect aspect) {
		super(aspect);
	}



	@Override
	protected final void processEntities(ImmutableBag<Entity> entities) {
		Object[] array = ((Bag<Entity>)entities).getData();
		for (int i = 0, s = entities.size(); s > i; i++) {
			Entity entity = (Entity)array[i];
			processDelta(entity, acc);
			float remaining = getRemainingDelay(entity);
			if(remaining <= 0) {
				processExpired(entity);
			} else {
				offerDelay(remaining);
			}
		}
		
		if (getActives().size() == 0) {
			stop();
		}
	}


	@Override
	protected void inserted(Entity e) {
		float remainingDelay = getRemainingDelay(e);
		processDelta(e, -acc);
		if(remainingDelay > 0) {
			offerDelay(remainingDelay);
		}
	}
{'fraction_non_alphanumeric': 0.10054242541650522, 'fraction_numerical': 0.004068190623789229, 'mean_word_length': 3.861581920903955, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1795548', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1473, 'n_words': 606}