From 45dd7e0e4a52c8d65f520fac4e8f4e83471b215b Mon Sep 17 00:00:00 2001 From: sonirico Date: Fri, 1 Jul 2016 14:01:45 +0200 Subject: [PATCH] Adds createEntity method to Engine Just a simple method present in Engine class which returns a new Entity instance. Its usefulness arises when retrieving PooledEngine from their EntitySystem in order to create new entities. Since PooledEngine now inherits and overrides createEntity function, castings from Engine to PooledEngine are no longer required. On the other hand, a trivial test have been added. --- ashley/src/com/badlogic/ashley/core/Engine.java | 8 ++++++++ ashley/src/com/badlogic/ashley/core/PooledEngine.java | 3 ++- ashley/tests/com/badlogic/ashley/core/EngineTests.java | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ashley/src/com/badlogic/ashley/core/Engine.java b/ashley/src/com/badlogic/ashley/core/Engine.java index c195706e..5ef14efb 100644 --- a/ashley/src/com/badlogic/ashley/core/Engine.java +++ b/ashley/src/com/badlogic/ashley/core/Engine.java @@ -50,6 +50,14 @@ public class Engine { private FamilyManager familyManager = new FamilyManager(entityManager.getEntities()); private boolean updating; + /** + * Creates a new Entity object. + * @return @{@link Entity} + */ + + public Entity createEntity () { + return new Entity(); + } /** * Adds an entity to this Engine. diff --git a/ashley/src/com/badlogic/ashley/core/PooledEngine.java b/ashley/src/com/badlogic/ashley/core/PooledEngine.java index ada691f0..688f66cd 100644 --- a/ashley/src/com/badlogic/ashley/core/PooledEngine.java +++ b/ashley/src/com/badlogic/ashley/core/PooledEngine.java @@ -60,7 +60,8 @@ public PooledEngine (int entityPoolInitialSize, int entityPoolMaxSize, int compo componentPools = new ComponentPools(componentPoolInitialSize, componentPoolMaxSize); } - /** @return Clean {@link Entity} from the Engine pool. In order to add it to the {@link Engine}, use {@link #addEntity(Entity)}. */ + /** @return Clean {@link Entity} from the Engine pool. In order to add it to the {@link Engine}, use {@link #addEntity(Entity)}. @{@link Override {@link Engine#createEntity()}} */ + @Override public Entity createEntity () { return entityPool.obtain(); } diff --git a/ashley/tests/com/badlogic/ashley/core/EngineTests.java b/ashley/tests/com/badlogic/ashley/core/EngineTests.java index e0a24f22..b2b86468 100644 --- a/ashley/tests/com/badlogic/ashley/core/EngineTests.java +++ b/ashley/tests/com/badlogic/ashley/core/EngineTests.java @@ -833,4 +833,13 @@ public void update(float deltaTime) { engine.update(0.0f); } + + @Test + public void createNewEntity () { + Engine engine = new Engine(); + Entity entity = engine.createEntity(); + + assertNotEquals(entity, null); + } + }