3.2 KiB
| JavaECS | docs | component | ComponentManager.md
Component Array
In this Section |
---|
About |
Implementation |
Constructors |
Methods |
Fields |
Examples |
Notes |
About
The ComponentArray
class defines the a common structure that all component data is stored in.
Implementation
Associatively maps an entity to the index position of its component data.
See ComponentManager.java for the full implementation.
Constructors
Default constructor
public ComponentManager(){}
Methods
addComponentToEntity
protected void addComponentToEntity(Type componentType, Object componentData, int entity);
Adds the specified component to the provided entity. Returns true
if successful, false
if the component is already associated to the entity.
entityDestroyed
public void entityDestroyed(int entity);
Signals to the ComponentManager
the entity was destroyed. All component data references should be removed.
getComponent
public Object getComponent(Type componentType, int entity);
Gets the component data associated with the entity, or null
if it was not found.
- The result of this operation should be cast back to the specified
Type
getComponentIndex
protected Integer getComponentIndex(Type type);
Gets the registration index of the provided component type. Returns the index, or -1
if the component isn't registered.
getComponentType
protected Type getComponentType(Integer index);
Gets the registration type of the provided component index. Returns the index, or null
if the component isn't registered.
moveComponentData
protected void moveComponentData(int sourceEntity, int destinationEntity, Type component);
Moves a single component data from one entity to another. Returns true
if the component was moved successfully, else false
.
moveAllComponentData
protected void moveAllComponentData(int sourceEntity, int destinationEntity, BitSet sourceRegistrations);
Moves all component data from one entity to another.
registerComponent
protected boolean registerComponent(Type type);
Registers the component type. Returns true
if successful, else false
.
removeComponentFromEntity
public boolean removeComponentFromEntity(Type componentType, int entity);
Removes the specified component from the entity. Returns true
if successful, else false
.
Fields
componentArrays
private Map<Type, ComponentArray> componentArrays = new HashMap<>();
Maps the component Type
to its ComponentArray
componentPosIndex
private Map<Type, Integer> componentPosIndex = new HashMap<>();
The mapped list of component types to the registration indices.
indexComponentType
private Map<Integer, Type> indexComponentType = new HashMap<>();
The mapped list of registration indices to component types.