public interface Entity extends Iterable<Component>, Comparable<Entity>, Ownable, Owner
EntitySystem.addEntity()
or the similar
function that takes another Entity as a template.
Once created the Entity object will not change its identity. There are no flyweight
entities, unlike components which do use that design pattern.
Entity implements both Ownable
and Owner
. This can be used to create
hierarchies of both components and entities that share a lifetime. When an entity is
removed from the system, all of its owned objects are disowned. If any of them were
entities or components, they are also removed from the system.Modifier and Type | Method and Description |
---|---|
<T extends Component> |
add(Class<T> componentType)
Add a new Component with a data type T to this Entity.
|
<T extends Component> |
add(T toClone)
Add a new Component with a of type T to this Entity, but the new component's state
will be cloned from the given Component instance.
|
<T extends Component> |
as(Class<T> type)
Get the canonical component instance of type T on this Entity.
|
<T extends Component> |
get(Class<T> componentType)
Get the Component instance of the given type that's attached to this Entity.
|
EntitySystem |
getEntitySystem() |
int |
getId() |
boolean |
has(Class<? extends Component> type)
Check whether or not the a component of the given type is attached to this entity.
|
boolean |
isAlive() |
Iterator<Component> |
iterator()
Return an iterator over the components currently attached to the Entity.
|
boolean |
remove(Class<? extends Component> componentType)
Remove any attached Component with the data type from this Entity.
|
compareTo
notifyOwnershipGranted, notifyOwnershipRevoked
int getId()
EntitySystem getEntitySystem()
boolean isAlive()
<T extends Component> T get(Class<T> componentType)
T
- The parameterized type of ComponentData of the componentcomponentType
- The given typeNullPointerException
- if componentType is null<T extends Component> T add(Class<T> componentType)
T
- The parameterized type of component being addedcomponentType
- The component typeNullPointerException
- if componentId is null<T extends Component> T add(T toClone)
T
- The parameterized type of component to addtoClone
- The existing T to clone when attaching to this componentNullPointerException
- if toClone is nullIllegalStateException
- if toClone is not a live component instance<T extends Component> T as(Class<T> type)
get(Class)
, this will add the component if it is not present. Thus, this
is a convenience for getting the component, and adding it if the get returned
null.T
- The parameterized type of componenttype
- The class interface of the component to addboolean has(Class<? extends Component> type)
type
- The component type to check forboolean remove(Class<? extends Component> componentType)
Component.isAlive()
.
When a Component is removed, it will set its owner to null, and disown all of its
owned objects. If any of those owned objects are entities or components, they are
removed from the system as well.componentType
- The component typeNullPointerException
- if componentId is nullIterator<Component> iterator()
remove(Class)
.
Components reported by the iterator are not flyweight.Copyright © 2013. All Rights Reserved.