Skip to content

Commit

Permalink
Adds createEntity method to Engine
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sonirico committed Jul 1, 2016
1 parent 969dc72 commit 45dd7e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ashley/src/com/badlogic/ashley/core/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion ashley/src/com/badlogic/ashley/core/PooledEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions ashley/tests/com/badlogic/ashley/core/EngineTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 45dd7e0

Please sign in to comment.