Package com.csse3200.game.entities
Class EntityService
java.lang.Object
com.csse3200.game.entities.EntityService
Provides a global access point for entities to register themselves. This allows for iterating
over entities to perform updates each loop. All game entities should be registered here.
Avoid adding additional state here! Global access is often the easy but incorrect answer to
sharing data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose all entities.Get the oldest (lowest index entity in entities) entity that contains the given component.getSpecificComponent
(Class<T> componentType) Get the oldest (lowest index entity in entities) entity's component of a given component type.void
Register a new entity with the entity service.void
Pause (disable) all entities so update in the gameplay loop doesn't occur for the event and its components.void
unregister
(Entity entity) Unregister an entity with the entity service.void
update()
Update all registered entities.void
Play (enable) all entities so update in the gameplay loop occurs for the event and its components.
-
Constructor Details
-
EntityService
public EntityService()
-
-
Method Details
-
register
Register a new entity with the entity service. The entity will be created and start updating.- Parameters:
entity
- new entity.
-
unregister
Unregister an entity with the entity service. The entity will be removed and stop updating.- Parameters:
entity
- entity to be removed.
-
update
public void update()Update all registered entities. Should only be called from the main game loop. -
dispose
public void dispose()Dispose all entities. -
restWholeScreen
public void restWholeScreen()Pause (disable) all entities so update in the gameplay loop doesn't occur for the event and its components. -
wakeWholeScreen
public void wakeWholeScreen()Play (enable) all entities so update in the gameplay loop occurs for the event and its components. -
getEntity
Get the oldest (lowest index entity in entities) entity that contains the given component. This is used to search for very specific entities. e.g. Player- Type Parameters:
T
- The component type, e.g. RenderComponent- Parameters:
componentType
- The component class, e.g. RenderComponent.class- Returns:
- The entity holding the component or null if nonexistent.
-
getSpecificComponent
Get the oldest (lowest index entity in entities) entity's component of a given component type. This is used to search for very specific components. e.g. QuestManager- Type Parameters:
T
- The component type, e.g. RenderComponent- Parameters:
componentType
- The component class, e.g. RenderComponent.class- Returns:
- The oldest entity's component or null if nonexistent.
-