From 5f846f00b00f7b448160b011c69613dff38a0382 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Fri, 31 Jan 2020 12:40:23 +0400 Subject: [PATCH] Have entity.remove() set active = false Removes the need to check if an entity hasn't been removed prior to processing. --- core/src/com/me/asteroids/systems/CollisionSystem.java | 4 ++-- core/src/com/me/common/ecs/Entity.java | 1 + core/src/com/me/common/ecs/EntitySystem.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/com/me/asteroids/systems/CollisionSystem.java b/core/src/com/me/asteroids/systems/CollisionSystem.java index 7e06a88..4982802 100644 --- a/core/src/com/me/asteroids/systems/CollisionSystem.java +++ b/core/src/com/me/asteroids/systems/CollisionSystem.java @@ -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; } diff --git a/core/src/com/me/common/ecs/Entity.java b/core/src/com/me/common/ecs/Entity.java index e7d975a..dd79c83 100644 --- a/core/src/com/me/common/ecs/Entity.java +++ b/core/src/com/me/common/ecs/Entity.java @@ -50,6 +50,7 @@ public final class Entity { public void remove() { removed = true; + active = false; refresh(); } diff --git a/core/src/com/me/common/ecs/EntitySystem.java b/core/src/com/me/common/ecs/EntitySystem.java index a5b4170..5c71ccf 100644 --- a/core/src/com/me/common/ecs/EntitySystem.java +++ b/core/src/com/me/common/ecs/EntitySystem.java @@ -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); } }