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:
parent
fa809148a7
commit
5f846f00b0
@ -23,7 +23,7 @@ public class CollisionSystem extends EntitySystem {
|
|||||||
Entity[] entities = getEntities().items;
|
Entity[] entities = getEntities().items;
|
||||||
for (int i = 0, n = getEntities().size; i < n-1; i++) {
|
for (int i = 0, n = getEntities().size; i < n-1; i++) {
|
||||||
Entity entityA = entities[i];
|
Entity entityA = entities[i];
|
||||||
if (!entityA.isActive() || entityA.isRemoved()) {
|
if (!entityA.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public class CollisionSystem extends EntitySystem {
|
|||||||
|
|
||||||
for (int j = i + 1; j < n; j++) {
|
for (int j = i + 1; j < n; j++) {
|
||||||
Entity entityB = entities[j];
|
Entity entityB = entities[j];
|
||||||
if (!entityB.isActive() || entityB.isRemoved()) {
|
if (!entityB.isActive()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ public final class Entity {
|
|||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
removed = true;
|
removed = true;
|
||||||
|
active = false;
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public abstract class EntitySystem extends BaseSystem {
|
|||||||
public void process(float dt) {
|
public void process(float dt) {
|
||||||
for (int i = 0, n = entities.size; i < n; i++) {
|
for (int i = 0, n = entities.size; i < n; i++) {
|
||||||
Entity entity = entities.items[i];
|
Entity entity = entities.items[i];
|
||||||
if (!entity.removed && entity.active) {
|
if (entity.isActive()) {
|
||||||
processEntity(entity, dt);
|
processEntity(entity, dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user