125 lines
3.2 KiB
Markdown
125 lines
3.2 KiB
Markdown
*| [JavaECS](../../README.md) | [docs](../overview.md) | [component](./dir.md) | ComponentManager[]().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 [ComponentManager.java](/BrychanD/JavaECS/src/branch/master/javaecs/src/main/java/nz/ac/massey/javaecs/ComponentManager.java) for the full implementation.
|
|
|
|
## Constructors
|
|
Default constructor
|
|
``` java
|
|
public ComponentManager(){}
|
|
```
|
|
|
|
<br>
|
|
|
|
## Methods
|
|
|
|
### addComponentToEntity
|
|
``` java
|
|
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.
|
|
|
|
<br>
|
|
|
|
### entityDestroyed
|
|
``` java
|
|
public void entityDestroyed(int entity);
|
|
```
|
|
Signals to the `ComponentManager` the entity was destroyed. All component data references should be removed.
|
|
|
|
<br>
|
|
|
|
### getComponent
|
|
``` java
|
|
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`
|
|
|
|
<br>
|
|
|
|
### getComponentIndex
|
|
``` java
|
|
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.
|
|
|
|
<br>
|
|
|
|
### getComponentType
|
|
``` java
|
|
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.
|
|
|
|
<br>
|
|
|
|
### moveComponentData
|
|
``` java
|
|
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`.
|
|
|
|
<br>
|
|
|
|
### moveAllComponentData
|
|
``` java
|
|
protected void moveAllComponentData(int sourceEntity, int destinationEntity, BitSet sourceRegistrations);
|
|
```
|
|
Moves all component data from one entity to another.
|
|
|
|
<br>
|
|
|
|
### registerComponent
|
|
``` java
|
|
protected boolean registerComponent(Type type);
|
|
```
|
|
Registers the component type. Returns `true` if successful, else `false`.
|
|
|
|
<br>
|
|
|
|
### removeComponentFromEntity
|
|
``` java
|
|
public boolean removeComponentFromEntity(Type componentType, int entity);
|
|
```
|
|
Removes the specified component from the entity. Returns `true` if successful, else `false`.
|
|
|
|
<br>
|
|
|
|
## Fields
|
|
### componentArrays
|
|
``` java
|
|
private Map<Type, ComponentArray> componentArrays = new HashMap<>();
|
|
```
|
|
Maps the component `Type` to its [ComponentArray](./ComponentArray.md)
|
|
|
|
<br>
|
|
|
|
### componentPosIndex
|
|
``` java
|
|
private Map<Type, Integer> componentPosIndex = new HashMap<>();
|
|
```
|
|
The mapped list of component types to the registration indices.
|
|
|
|
<br>
|
|
|
|
### indexComponentType
|
|
``` java
|
|
private Map<Integer, Type> indexComponentType = new HashMap<>();
|
|
```
|
|
The mapped list of registration indices to component types. |