86 lines
2.3 KiB
Markdown
86 lines
2.3 KiB
Markdown
*| [JavaECS](../../README.md) | [docs](../overview.md) | [component](./dir.md) | ComponentArray[]().md*
|
|
# Component Array
|
|
| **In this Section** |
|
|
|-|
|
|
| [About](#about) |
|
|
| [Implementation](#implementation) |
|
|
| [Constructors](#constructors) |
|
|
| [Methods](#methods) |
|
|
| [Fields](#fields) |
|
|
| [Examples](#examples)|
|
|
| [Notes](#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](/BrychanD/JavaECS/src/branch/master/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentArray.java) for the full implementation.
|
|
|
|
## Constructors
|
|
Default constructor
|
|
``` java
|
|
public ComponentArray(){}
|
|
```
|
|
|
|
<br>
|
|
|
|
## Methods
|
|
|
|
### getData
|
|
``` java
|
|
protected Object getData(int entity);
|
|
```
|
|
Gets the data Object associated with the entity. Returns `null` if the object was not found.
|
|
|
|
<br>
|
|
|
|
### insertData
|
|
``` java
|
|
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.
|
|
|
|
<br>
|
|
|
|
### moveData
|
|
``` java
|
|
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.
|
|
|
|
<br>
|
|
|
|
### removeData
|
|
``` java
|
|
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`.
|
|
|
|
<br>
|
|
|
|
## Fields
|
|
### componentArray
|
|
``` java
|
|
private List<Object> componentArray = new ArrayList<>();
|
|
```
|
|
The `List<>` containing the component Object data
|
|
|
|
<br>
|
|
|
|
### componentDataEntityMap
|
|
``` java
|
|
private Map<Integer, Integer> componentDataEntityMap = new HashMap<>();
|
|
```
|
|
The mapped list of component data indicies to entities.
|
|
|
|
<br>
|
|
|
|
### entityComponentDataMap
|
|
``` java
|
|
private Map<Integer, Integer> entityComponentDataMap = new HashMap<>();
|
|
```
|
|
The mapped list of entities to component data indicies.
|