diff --git a/docs/entity/Entity.md b/docs/entity/Entity.md index 6930a91..9e14b0c 100644 --- a/docs/entity/Entity.md +++ b/docs/entity/Entity.md @@ -34,6 +34,6 @@ void todo(); ``` ## 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 * 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. diff --git a/docs/entity/EntityManager.md b/docs/entity/EntityManager.md new file mode 100644 index 0000000..172bf87 --- /dev/null +++ b/docs/entity/EntityManager.md @@ -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. + +
+ +``` java +public EntityManager(int maxEntities){} +``` +Initialises [unusedEntities](#unusedEntities) to a new queue containing `maxEntities` unique integers. + +
+ +## 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. + +
+ +### getRegistrations +``` java +public BitSet getRegistrations(int entity); +``` +Returns the `BitSet` of registrations the `entity` has + +
+ +### registerComponent +``` java +public void registerComponent(int component, int entity); +``` +Sets the bit `component` in [entityRegistrations](#entityRegistrations) for `entity` to `true`. + +
+ +### 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. + +
+ +### unregisterComponent +``` java +public void unregisterComponent(int component, int entity); +``` +Sets the bit `component` in [entityRegistrations](#entityRegistrations) for `entity` to `false`. + +
+ +## Fields +### entityRegistrations +``` java +List entityRegistrations; +``` + +
+ +### unusedEntities +``` java +Queue unusedEntities; +``` + +
+ + diff --git a/docs/entity/dir.md b/docs/entity/dir.md index 63296e8..eb10a4d 100644 --- a/docs/entity/dir.md +++ b/docs/entity/dir.md @@ -1,4 +1,5 @@ *| [JavaECS](../README.md) | [docs](../overview.md) | entity* # Overview ### In this folder -[entity.md](./entity.md) \ No newline at end of file +*[Entity.md](./Entity.md) +*[EntityManager.md](./EntityManager.md) \ No newline at end of file