Class ComponentManager


  • public class ComponentManager
    extends Object
    Manages the addition, sorting and retrieving of components and component data
    • Constructor Detail

      • ComponentManager

        public ComponentManager()
    • Method Detail

      • addComponentToEntity

        protected boolean addComponentToEntity​(Type componentType,
                                               Object componentData,
                                               Entity entity)
        Adds the specified component to the provided entity.

        Providing a null Object defaults the value to boolean false

        Parameters:
        componentType - the class type of the component to add
        componentData - the component data to associate
        entity - the entity to associate data to
      • entityDestroyed

        public void entityDestroyed​(Entity entity,
                                    BitSet entityRegistrations)
        Signals to the ComponentManager the entity was destroyed. All component data references should be removed.
        Parameters:
        entity - the entity that was destroyed.
      • getComponent

        public Object getComponent​(Type componentType,
                                   Entity entity)
        Gets the component data associated with the entity
        Parameters:
        componentType - the class type of data to look for
        entity - the entity to find data for
        Returns:
        the Object data found, or null if it was not found
      • getComponentIndex

        public Integer getComponentIndex​(Type type)
        Gets the registration index of the component type
        Parameters:
        type - the class type of the component
        Returns:
        the index of the component type, or -1 if it isn't found
      • getComponentType

        public Type getComponentType​(Integer index)
        Gets the type of the component at the provided index
        Parameters:
        index - the index of the component
        Returns:
        the class type of the index. `null` if not found
      • moveComponentData

        public boolean moveComponentData​(Entity sourceEntity,
                                         Entity destinationEntity,
                                         Type component)
        Moves a single component data from one entity to another
        Parameters:
        sourceEntity - the entity to move data from
        destinationEntity - the entity to move data to
        component - the component class type to consider
        Returns:
        true if the component was moved successfully, else false
      • moveAllComponentData

        public void moveAllComponentData​(Entity sourceEntity,
                                         Entity destinationEntity,
                                         BitSet sourceRegistrations)
        Moves all component data from one entity to another
        Parameters:
        sourceEntity - the entity to move data from
        destinationEntity - the entity to move data to
        sourceRegistrations - the component registrations of the source entity
      • registerComponent

        public boolean registerComponent​(Type type)
        Registers the component type
        Parameters:
        type - the class type to register
        Returns:
        true if the component was registered successfully, else false
      • registerComponent

        public boolean registerComponent​(Type type,
                                         int arraySize)
        Registers the component type
        Parameters:
        type - the class type to register
        arraySize - the number of elements to prereserve space for.
        Returns:
        true if the component was registered successfully, else false
      • removeComponentFromEntity

        public boolean removeComponentFromEntity​(Type componentType,
                                                 Entity entity)
        Removes the specified component from the entity.

        Be sure to call SystemManager.entityRegistrationsChanged after calling this function

        Parameters:
        componentType - the class type of the component to remove
        entity - the entity to remove the component from
      • entityHasComponentData

        public boolean entityHasComponentData​(Entity entity,
                                              Type componentType)
        Checks if the entity contains data for the provided component
        Parameters:
        entity - the entity to check
        componentType - the component class type
        Returns:
        true if the entity has component data