Added entity manager
Fixed links Trial of direct code link
This commit is contained in:
parent
8d8b7ad3a6
commit
4cbfb97225
@ -34,6 +34,6 @@ void todo();
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
* The only requirement for a Entity is that it has a unique ID. A more advanced [entity manager](../manager/EntityManager.md) could implement an ID system with ID regions, or using named IDs.
|
* The only requirement for a Entity is that it has a unique ID. A more advanced [entity manager](./EntityManager.md) could implement an ID system with ID regions, or using named IDs.
|
||||||
Another approach could be to use the first byte as a grouping, in a similar way to how Bethesda Softworks' Skyrim utilises the first byte as a mod index
|
Another approach could be to use the first byte as a grouping, in a similar way to how Bethesda Softworks' Skyrim utilises the first byte as a mod index
|
||||||
* The maximum number of entities is limited by the size of the container used to store it. E.g., for a 32-bit unsigned integer, there are ~4.3 billion ID's available. But keep in mind that such a large amount of IDs will take significant time for each system to consider.
|
* The maximum number of entities is limited by the size of the container used to store it. E.g., for a 32-bit unsigned integer, there are ~4.3 billion ID's available. But keep in mind that such a large amount of IDs will take significant time for each system to consider.
|
||||||
|
98
docs/entity/EntityManager.md
Normal file
98
docs/entity/EntityManager.md
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
*| [JavaECS](../../README.md) | [docs](../overview.md) | [entity](./dir.md) | EntityManager[]().md*
|
||||||
|
# Entity Manager
|
||||||
|
| **In this Section** |
|
||||||
|
|-|
|
||||||
|
| [About](#about) |
|
||||||
|
| [Implementation](#implementation) |
|
||||||
|
| [Constructors](#constructors) |
|
||||||
|
| [Methods](#methods) |
|
||||||
|
| [Fields](#fields) |
|
||||||
|
| [Examples](#examples)|
|
||||||
|
| [Notes](#notes)|
|
||||||
|
|
||||||
|
## About
|
||||||
|
Controls adding and removing entities, and registration and deregistration of components to specific entities.
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
Before attempting to use a system, it must be registered.
|
||||||
|
|
||||||
|
Registration requires a call to `registerSystem(String systemName, ECSSystem system)`, with params of the `String name` and a object reference of the [ECSSystem](./ECSSystem.md). Using the object reference, a system can be invoked at any time.
|
||||||
|
|
||||||
|
See [EntityManager.java](/BrychanD/JaveECS/src/branch/master/javaecs/src/main/java/nz/ac/massey/programming_project_159333_s1_2021/EntityManager.java)
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
``` java
|
||||||
|
public EntityManager(){}
|
||||||
|
```
|
||||||
|
The default constructor initialises [unusedEntities](#unusedEntities) to a new queue containing `1024` unique integers.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
``` java
|
||||||
|
public EntityManager(int maxEntities){}
|
||||||
|
```
|
||||||
|
Initialises [unusedEntities](#unusedEntities) to a new queue containing `maxEntities` unique integers.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
### addEntity
|
||||||
|
``` java
|
||||||
|
public Integer addEntity();
|
||||||
|
```
|
||||||
|
Pops the next available entity index off the queue, and returns its value.
|
||||||
|
|
||||||
|
Returns `-1` if there is no remaining unused entities.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
### getRegistrations
|
||||||
|
``` java
|
||||||
|
public BitSet getRegistrations(int entity);
|
||||||
|
```
|
||||||
|
Returns the `BitSet` of registrations the `entity` has
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
### registerComponent
|
||||||
|
``` java
|
||||||
|
public void registerComponent(int component, int entity);
|
||||||
|
```
|
||||||
|
Sets the bit `component` in [entityRegistrations](#entityRegistrations) for `entity` to `true`.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
### removeEntity
|
||||||
|
``` java
|
||||||
|
public void removeEntity(int entity);
|
||||||
|
```
|
||||||
|
Adds the entity's index back to the unused queue, and clears the assigned registration bits
|
||||||
|
#### Note
|
||||||
|
>This function should not be called directly. Doing so will leave component data in memory, and will cause desynchronisation of the system registrations.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
### unregisterComponent
|
||||||
|
``` java
|
||||||
|
public void unregisterComponent(int component, int entity);
|
||||||
|
```
|
||||||
|
Sets the bit `component` in [entityRegistrations](#entityRegistrations) for `entity` to `false`.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
### entityRegistrations
|
||||||
|
``` java
|
||||||
|
List<BitSet> entityRegistrations;
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
### unusedEntities
|
||||||
|
``` java
|
||||||
|
Queue<Integer> unusedEntities;
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
*| [JavaECS](../README.md) | [docs](../overview.md) | entity*
|
*| [JavaECS](../README.md) | [docs](../overview.md) | entity*
|
||||||
# Overview
|
# Overview
|
||||||
### In this folder
|
### In this folder
|
||||||
[entity.md](./entity.md)
|
*[Entity.md](./Entity.md)
|
||||||
|
*[EntityManager.md](./EntityManager.md)
|
Loading…
x
Reference in New Issue
Block a user