JavaECS-Docs/docs/component/ComponentArray.md
2021-06-08 21:13:34 +12:00

2.3 KiB

| JavaECS | docs | component | ComponentArray.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 ComponentArray.java for the full implementation.

Constructors

Default constructor

public ComponentArray(){}

Methods

getData

protected Object getData(int entity);

Gets the data Object associated with the entity. Returns null if the object was not found.


insertData

protected boolean insertData(int entity, Object component);

Inserts the specified component and associates it with the entity. If the entity alread has data associated to it, then returns false, without adding data.


moveData

protected int moveData(int sourceEntity, int destinationEntity);

'Moves' data from the sourceEntity to the destinationEntity. Actual implementation copies the data Object associated with the key, and inserts it associated with the new entity. Returns 0 if the operation succeeded, -1 if the object data was null, -2 if a NullPointerException occurred, and -3 if inserting the new data failed.


removeData

protected boolean removeData(int entity);

Returns true if it removed the specified entity's data. If the entity does not exist (data isn't mapped to that entity), then returns false.


Fields

componentArray

private List<Object> componentArray = new ArrayList<>();

The List<> containing the component Object data


componentDataEntityMap

private Map<Integer, Integer> componentDataEntityMap = new HashMap<>();

The mapped list of component data indicies to entities.


entityComponentDataMap

private Map<Integer, Integer> entityComponentDataMap = new HashMap<>();

The mapped list of entities to component data indicies.