JavaECS-Docs/docs/entity/EntityManager.md
2021-06-08 21:13:34 +12:00

3.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 unregistration 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

protected EntityManager(){}

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


protected EntityManager(int maxEntities){}

Initialises unusedEntities to a new queue containing maxEntities unique integers.


Methods

addEntity

protected Integer addEntity();

Pops the next available entity index off the queue, and returns its value.

Returns -1 if there is no remaining unused entities.


getMaxSize

protected Integer getMaxSize();

Gets the current maximum entity count.


getRegistrations

protected BitSet getRegistrations(int entity);

Returns the BitSet of registrations the entity has.

If the call results in an IndexOutOfBoundsError, then returns a new BitSet();


registerComponent

protected void registerComponent(int component, int entity);

Sets the bit component in entityRegistrations for entity to true.


removeEntity

protected 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.


resize

protected boolean resize(int newSize, SystemManager systemManager, ComponentManager componentManager);

Resizes the currentSize of the entity manager. Moves elements above newSize if space is available.

If the current defined elements won't fit, the operation returns false and the previous state is maintained.


setRegistrations

protected void setRegistrations(int entity, BitSet registrations);

Sets the entity's registrations to the provided BitSet


unregisterComponent

protected void unregisterComponent(int component, int entity);

Sets the bit component in entityRegistrations for entity to false.

Returns true if successful.


Fields

entityRegistrations

List<BitSet> entityRegistrations;

The BitSet of registrations for each entity


maxSize

private int maxSize = 1024;

The current maximum entity count.

Default 1024

unusedEntities

Queue<Integer> unusedEntities;

The queue of unused entity values