public interface Component extends Owner, Ownable
Entity
. An Entity's behavior is defined by the union of all components attached
to it, and the system's configured tasks that process the entities. Tasks must be
implemented and used in order to take advantage of a particular component
configuration.
An entity can be considered as a collection of aspects represented by component
instances. An entity can have at most one instance of a component type at a time,
although over its lifetime the specific component instance may change.
Logically a component definition is a set of named and typed properties, and a
method-based API to get and set the values of each property. Specific types of
component are defined by creating a sub-interface of Component. Using the Named
, SharedInstance
, Factory
and custom Attribute
annotations defined by Property
implementations, the data properties of
the component type are specified in the sub-interface. A declaration model similar to
the Java Bean model is used and is outlined below:
Named
annotation
can be used to override the name.Named
annotation can be applied to either the setter or the parameter to specify the property
name.Named
to specify the property,
and the argument type must equal the type of the matching property.IllegalComponentDefinitionException
.Property
instances of a compatible type. This
allows iteration over components to have much better cache locality if the component is
defined in terms of primitives or types that have specialized Property implementations
that can pack and unpack an instance. The SharedInstance
annotation can be added to the getter method of a property to specify
that the ShareableProperty
API
should be leveraged by the generated class.
Additional attribute annotations can be added to the getter method to influence the
behavior of the PropertyFactory
used for each property in the component definition. Besides using the Factory
annotation to specify the factory type, a property implementation can be associated
with a type with canonical name C by adding the file
META-INF/entreri/mapping/C to the classpath, where its contents must be:
<BINARY NAME OF PROPERTY>where the value is suitable for passing into
Class.forName(String)
.
Attribute annotations provided by the default property implementations are outlined
below: DefaultBoolean
- set value for boolean propertiesDefaultByte
- set value for byte
propertiesDefaultShort
- set value for short propertiesDefaultInt
- set value for int
propertiesDefaultLong
- set value for long propertiesDefaultFloat
- set value for
float propertiesDefaultDouble
- set value for double propertiesDefaultChar
- set value for char
propertiesClone
- specify clone
policy used with entity or component templatesComponentIterator
class creates flyweight
component instances whose identity changes as iteration proceeds; equals() and
hashCode() will behave appropriately. This means that flyweight components should not
be stored in collections that depend on equality or hashes. Flyweight components are
used for performance reasons when iterating over the entities in a system with specific
component configurations because the JVM does not need to load each unique component
instance into the cache.
Component implements both Ownable
and Owner
. This can be used to create
hierarchies of both components and entities that share a lifetime. When a component is
removed from an entity, 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 |
---|---|
Entity |
getEntity()
Get the entity that this component is attached to.
|
EntitySystem |
getEntitySystem() |
int |
getIndex()
Get the underlying index of this component used to access its properties.
|
Class<? extends Component> |
getType()
Get the class identifier for this component.
|
int |
getVersion()
Get the current version of the data of this component.
|
boolean |
isAlive()
Get whether or not the component is still attached to an alive entity in an entity
system.
|
boolean |
isFlyweight()
Get whether or not this particular instance is a flyweight component object.
|
void |
updateVersion()
Increment the version of the component accessed by this instance.
|
notifyOwnershipGranted, notifyOwnershipRevoked
EntitySystem getEntitySystem()
Entity getEntity()
boolean isAlive()
boolean isFlyweight()
Entity.add(Class)
, Entity.get(Class)
, and
its other component returning functions will always return non-flyweight
components. These components are the 'canonical' instances for that component type
and entity.int getIndex()
ComponentIterator
for more information.int getVersion()
entity.as(T.class).getVersion() != cachedVersion
will correctly detect changes to the original component instance as well as the
removal and replacement by a new component of type T.void updateVersion()
getVersion()
Class<? extends Component> getType()
Object.getClass()
because that will return a specific and
most likely generated proxy implementation of the component type.Copyright © 2013. All Rights Reserved.