Package nz.ac.massey.javaecs
Class EntityManager
- java.lang.Object
-
- nz.ac.massey.javaecs.EntityManager
-
public class EntityManager extends Object
Manages data from the perspective of the entity.I.e. Controls adding and removing entities, and registration and deregistration of components.
-
-
Constructor Summary
Constructors Constructor Description EntityManager()
Initialise the EntityManager with the default max size of 1024EntityManager(int maxEntities)
Initialise the EntityManager with the provided maximum size
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Entity
addEntity()
Creates a new entityInteger
getMaxSize()
Gets the current maximum sizeint
getNumEntities()
BitSet
getRegistrations(Entity entity)
Gets the BitSet containing the registrations of the entity.protected boolean
registerComponent(int component, Entity entity)
Registers the specified component index to the entityprotected void
removeEntity(Entity entity)
Adds the entity index back into unusedEntities, and sets the registrations to nullboolean
resize(int newSize, SystemManager systemManager, ComponentManager componentManager)
Resizes the currentSize of the entity manager.protected void
setRegistrations(Entity entity, BitSet registrations)
Sets the entity's registrations to the provided BitSetprotected boolean
unregisterComponent(int component, Entity entity)
Unregisters the specified component from the entity
-
-
-
Method Detail
-
addEntity
protected Entity addEntity() throws NoSuchElementException
Creates a new entity- Returns:
- the index of the new entity
- Throws:
NoSuchElementException
- an exception if there are no more unused entities
-
getMaxSize
public Integer getMaxSize()
Gets the current maximum size- Returns:
- the value of currentSize
-
getRegistrations
public BitSet getRegistrations(Entity entity)
Gets the BitSet containing the registrations of the entity.- Parameters:
entity
- the entity whose BitSet to retrieve- Returns:
- the BitSet of the provided entity, or a new, empty BitSet if the result was null or out of bounds
-
registerComponent
protected boolean registerComponent(int component, Entity entity)
Registers the specified component index to the entity- Parameters:
component
- the index of the component to registerentity
- the entity to register- Returns:
- true if the operation was successful
-
removeEntity
protected void removeEntity(Entity entity)
Adds the entity index back into unusedEntities, and sets the registrations to nullDoes not handle associated data Use the method in ECS to remove entities cleanly
- Parameters:
entity
- the entity to remove
-
setRegistrations
protected void setRegistrations(Entity entity, BitSet registrations)
Sets the entity's registrations to the provided BitSet- Parameters:
entity
- the entity to setregistrations
- the preset registrations
-
unregisterComponent
protected boolean unregisterComponent(int component, Entity entity)
Unregisters the specified component from the entityDoes not handle component data Use the method in ECS to remove components cleanly
- Parameters:
component
- the component index to removeentity
- the entity to remove- Returns:
- true if successful
-
resize
public boolean resize(int newSize, SystemManager systemManager, ComponentManager componentManager)
Resizes the currentSize of the entity manager.- Parameters:
newSize
- the new maximum sizesystemManager
- reference to the instanced SystemManagercomponentManager
- reference to the insanced ComponentManager- Returns:
- true if the operation succeeded, otherwise false
-
getNumEntities
public int getNumEntities()
-
-