JavaECS-Docs/docs/entity/EntityManager.md
Brychan Dempsey 4cbfb97225 Added entity manager
Fixed links
Trial of direct code link
2021-06-06 14:37:26 +12:00

2.4 KiB

| JavaECS | docs | entity | EntityManager.md

Entity Manager

In this Section
About
Implementation
Constructors
Methods
Fields
Examples
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. Using the object reference, a system can be invoked at any time.

See EntityManager.java

Constructors

public EntityManager(){}

The default constructor initialises unusedEntities to a new queue containing 1024 unique integers.


public EntityManager(int maxEntities){}

Initialises unusedEntities to a new queue containing maxEntities unique integers.


Methods

addEntity

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

public BitSet getRegistrations(int entity);

Returns the BitSet of registrations the entity has


registerComponent

public void registerComponent(int component, int entity);

Sets the bit component in entityRegistrations for entity to true.


removeEntity

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

public void unregisterComponent(int component, int entity);

Sets the bit component in entityRegistrations for entity to false.


Fields

entityRegistrations

List<BitSet> entityRegistrations;

unusedEntities

Queue<Integer> unusedEntities;