Have entity.remove() set active = false

Removes the need to check if an entity hasn't been removed prior to
processing.
This commit is contained in:
Matt Low 2020-01-31 12:40:23 +04:00
parent fa809148a7
commit 5f846f00b0
3 changed files with 4 additions and 3 deletions

View File

@ -23,7 +23,7 @@ public class CollisionSystem extends EntitySystem {
Entity[] entities = getEntities().items;
for (int i = 0, n = getEntities().size; i < n-1; i++) {
Entity entityA = entities[i];
if (!entityA.isActive() || entityA.isRemoved()) {
if (!entityA.isActive()) {
continue;
}
@ -31,7 +31,7 @@ public class CollisionSystem extends EntitySystem {
for (int j = i + 1; j < n; j++) {
Entity entityB = entities[j];
if (!entityB.isActive() || entityB.isRemoved()) {
if (!entityB.isActive()) {
continue;
}

View File

@ -50,6 +50,7 @@ public final class Entity {
public void remove() {
removed = true;
active = false;
refresh();
}

View File

@ -29,7 +29,7 @@ public abstract class EntitySystem extends BaseSystem {
public void process(float dt) {
for (int i = 0, n = entities.size; i < n; i++) {
Entity entity = entities.items[i];
if (!entity.removed && entity.active) {
if (entity.isActive()) {
processEntity(entity, dt);
}
}