Skip to content
Jesse Wang edited this page Mar 29, 2016 · 8 revisions

com.artemis.Component

The original component type.

Pros

  • Easiest to work with
  • The only component type which "safely" can be shared between multiple entity instances (such as marker-type components, that don't hold any actual data except for the type itself).

Cons

  • Potentially more work for the garbage collector, consider the other types if the component is frequent and short-lived.

com.artemis.PooledComponent

Pooled components are recycled once they're removed from an entity. Use in situations when components are re-created at frequent intervals.

Prerequisites

  • Zero-argument constructor
  • Must use Entity#edit#createComponent(Class<Component>) or World#edit(int eid) or ComponentMapper<Component>#create(int eid)
  • Must not employ final fields.

Cons

  • Somewhat cumbersome to implement vs normal components.
    • @PooledWeaver can however be used to automate the conversion.

com.artemis.PackedComponent

Packed components only exist as a single instance per ComponentMapper plus one held by the ComponentManager. The template implementation uses a static primitive array to hold the data for all entities.

Prerequisites

  • Zero-argument constructor
  • Calling the constructor must not reset the backing array, if any, else ComponentMappers will reset the component upon initialization.
  • Must use Entity#edit#createComponent(Class<Component>) or World#edit(int eid) or ComponentMapper<Component>#create(int eid)
  • No direct field access allowed.

Pros (assuming nearly all entities use have the component)

  • Better memory layout, potentially improving access times.
  • Consumes less memory by reducing component instances.

Cons

  • Cumbersome to implement (unless in situation where @PackedWeaver can be used).
Clone this wiki locally