diff --git a/ashley/src/com/badlogic/ashley/core/Engine.java b/ashley/src/com/badlogic/ashley/core/Engine.java index d367edd5..c40059c2 100644 --- a/ashley/src/com/badlogic/ashley/core/Engine.java +++ b/ashley/src/com/badlogic/ashley/core/Engine.java @@ -44,6 +44,7 @@ public class Engine { private static SystemComparator comparator = new SystemComparator(); private Array entities; + private ImmutableArray immutableEntities; private LongMap entitiesById; private Array entityOperations; private EntityOperationPool entityOperationPool; @@ -66,6 +67,7 @@ public class Engine { public Engine () { entities = new Array(false, 16); + immutableEntities = new ImmutableArray(entities); entitiesById = new LongMap(); entityOperations = new Array(false, 16); entityOperationPool = new EntityOperationPool(); @@ -137,6 +139,10 @@ public void removeAllEntities () { public Entity getById(long id) { return entitiesById.get(id); } + + public ImmutableArray getEntities() { + return immutableEntities; + } /** Adds the {@link EntitySystem} to this Engine. */ public void addSystem (EntitySystem system) { diff --git a/ashley/tests/com/badlogic/ashley/core/EngineTests.java b/ashley/tests/com/badlogic/ashley/core/EngineTests.java index 53516afb..78edb5ab 100644 --- a/ashley/tests/com/badlogic/ashley/core/EngineTests.java +++ b/ashley/tests/com/badlogic/ashley/core/EngineTests.java @@ -592,4 +592,31 @@ public void getEntityById () { assertEquals(null, engine.getById(entityId)); } + + @Test + public void getEntities () { + int numEntities = 10; + + Engine engine = new Engine(); + + Array entities = new Array(); + + for (int i = 0; i < numEntities; ++i) { + Entity entity = new Entity(); + entities.add(entity); + engine.addEntity(entity); + } + + ImmutableArray engineEntities = engine.getEntities(); + + assertEquals(entities.size, engineEntities.size()); + + for (int i = 0; i < numEntities; ++i) { + assertEquals(entities.get(i), engineEntities.get(i)); + } + + engine.removeAllEntities(); + + assertEquals(0, engineEntities.size()); + } }