Class 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 Detail

      • EntityManager

        public EntityManager()
        Initialise the EntityManager with the default max size of 1024
      • EntityManager

        public EntityManager​(int maxEntities)
        Initialise the EntityManager with the provided maximum size
        Parameters:
        maxEntities - the maximum number of entities to allow
    • Method Detail

      • 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 register
        entity - 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 null

        Does 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 set
        registrations - the preset registrations
      • unregisterComponent

        protected boolean unregisterComponent​(int component,
                                              Entity entity)
        Unregisters the specified component from the entity

        Does not handle component data Use the method in ECS to remove components cleanly

        Parameters:
        component - the component index to remove
        entity - 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 size
        systemManager - reference to the instanced SystemManager
        componentManager - reference to the insanced ComponentManager
        Returns:
        true if the operation succeeded, otherwise false
      • getNumEntities

        public int getNumEntities()