Package tripleplay.entity
Class Entity
java.lang.Object
tripleplay.entity.Entity
- All Implemented Interfaces:
AutoCloseable
,react.Closeable
Tracks the state of a single entity. This includes its enabled state, as well as the components
which are attached to this entity.
-
Nested Class Summary
Nested classes/interfaces inherited from interface react.Closeable
react.Closeable.Set, react.Closeable.Util
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds the specified component to this entity.Adds the supplied components to this entity.Adds the specified components to this entity.void
close()
An alias fordispose()
.void
Indicates that this entity has changed, and causes it to be reconsidered for inclusion or exclusion from systems on the next update.void
dispose()
Disposes this entity, causing it to be removed from the world on the next update.boolean
Returns true if this entity has the componentcomp
, false otherwise.boolean
Returns whether this entity has been disposed.boolean
Returns whether this entity is currently enabled.Removes the specified component from this entity.void
setEnabled
(boolean enabled) Enables or disables this entity.toString()
-
Field Details
-
world
The world to which this entity belongs. -
id
public final int idThis entity's unique id. This id will be valid for as long as the entity remains alive. Onceclose()
is called, this id may be reused by a new entity.
-
-
Constructor Details
-
Entity
Creates an entity in the specified world, initializes it with the supplied set of components and queues it to be added to the world on the next update.
-
-
Method Details
-
isDisposed
public boolean isDisposed()Returns whether this entity has been disposed. -
isEnabled
public boolean isEnabled()Returns whether this entity is currently enabled. -
setEnabled
public void setEnabled(boolean enabled) Enables or disables this entity. When an entity is disabled, it is removed from all systems in which it is currently an active participant (prior to the next update). When it is re-enabled, it is added back to all systems that are interested in it (prior to the next update). -
has
Returns true if this entity has the componentcomp
, false otherwise. -
add
Adds the specified component to this entity. This will queue the component up to be added or removed to appropriate systems on the next update.- Returns:
- this entity for call chaining.
-
add
Adds the specified components to this entity. This will queue the component up to be added or removed to appropriate systems on the next update. Note: this method uses varags and thus creates an array every time it is called. If you are striving to eliminate all unnecessary garbage generation, use repeated calls toadd(Component)
, oradd(Component[])
with a pre-allocated array.- Returns:
- this entity for call chaining.
-
add
Adds the supplied components to this entity. This will queue the component up to be added or removed to appropriate systems on the next update. This avoids the garbage generation of the varagsadd
method, and is slightly more efficient than a sequence of calls toadd(Component)
. The expectation is that you would keep an array around with the components for a particular kind of entity, like so:Entity createFoo (...) { Entity foo = create(true).add(FOO_COMPS); // init foo... return foo; } private static final Component[] FOO_COMPS = { pos, vel, etc. };
- Returns:
- this entity for call chaining.
-
remove
Removes the specified component from this entity. This will queue the component up to be added or removed to appropriate systems on the next update. -
dispose
public void dispose()Disposes this entity, causing it to be removed from the world on the next update. -
close
public void close()An alias fordispose()
. Needed to implementCloseable
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacereact.Closeable
-
didChange
public void didChange()Indicates that this entity has changed, and causes it to be reconsidered for inclusion or exclusion from systems on the next update. This need not be called when adding or removing components, and should only be called if some other external circumstance changes that requires recalculation of which systems are interested in this entity. -
toString
-