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
Attributeannotations defined by
Propertyimplementations, 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:
Namedannotation can be used to override the name.
Namedannotation can be applied to either the setter or the parameter to specify the property name.
Namedto specify the property, and the argument type must equal the type of the matching property.
Propertyinstances 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
SharedInstanceannotation can be added to the getter method of a property to specify that the
ShareablePropertyAPI should be leveraged by the generated class. Additional attribute annotations can be added to the getter method to influence the behavior of the
PropertyFactoryused 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 properties
DefaultByte- set value for byte properties
DefaultShort- set value for short properties
DefaultInt- set value for int properties
DefaultLong- set value for long properties
DefaultFloat- set value for float properties
DefaultDouble- set value for double properties
DefaultChar- set value for char properties
Clone- specify clone policy used with entity or component templates
ComponentIteratorclass 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
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|
Get the entity that this component is attached to.
Get the underlying index of this component used to access its properties.
Get the class identifier for this component.
Get the current version of the data of this component.
Get whether or not the component is still attached to an alive entity in an entity system.
Get whether or not this particular instance is a flyweight component object.
Increment the version of the component accessed by this instance.
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.
ComponentIteratorfor more information.
entity.as(T.class).getVersion() != cachedVersionwill correctly detect changes to the original component instance as well as the removal and replacement by a new component of type T.
Object.getClass()because that will return a specific and most likely generated proxy implementation of the component type.
Copyright © 2013. All Rights Reserved.