Class Engine


  • public class Engine
    extends Object
    The ECS management engine. Supplemented by the EntityManager, ComponentManager, and System Manager These four classes provide the actual functionality of the ecs

    See https://git.software.kauripeak.co.nz/BrychanD/JavaECS for documentation and more information.

    • Constructor Detail

      • Engine

        public Engine()
        Engine Constructors **
      • Engine

        public Engine​(int maxEntities)
        Initialises the ECS with the specified value
        Parameters:
        maxEntities - the maximum number of entities to allow
    • Method Detail

      • resizeMaximum

        public boolean resizeMaximum​(int newSize)
        Attempts to resize the maximum number of entities
        Parameters:
        newSize - the new maximum number of entities
        Returns:
        true if the operation succeeded
      • createEntity

        public Entity createEntity()
                            throws NoSuchElementException
        Create a new Entity (dequeues the first element from unusedEntities)
        Returns:
        the next unused Entity, now set to used
        Throws:
        NoSuchElementException - if there are no more entities available
      • destroyEntity

        public void destroyEntity​(Entity entity)
        Signals each manager to remove the specified entity
        Parameters:
        entity - the entity to destroy
      • getMaxEntities

        public Integer getMaxEntities()
        Gets the set maximum number of entities
        Returns:
        an integer of the maximum number of entities
      • getNumEntities

        public int getNumEntities()
        Gets the current number of entities
        Returns:
        the number of currently active entities
      • entityHasComponent

        public boolean entityHasComponent​(Entity entity,
                                          Type componentType)
        Checks if the entity is subscribed to the provided type
        Parameters:
        entity - the entity to search
        componentType - the class type of the component to search
        Returns:
        true if the entity is subscribed
      • registerComponent

        public boolean registerComponent​(Type type)
        Registers the specified name in the component manager
        Parameters:
        type - the name to register. Should be the component class name or a suitable name for primitive types
        Returns:
        true if the component type was registered successfully
      • addComponent

        public boolean addComponent​(Entity entity,
                                    Type componentType,
                                    Object component)
        Adds an exisiting component to an exisiting entity
        Parameters:
        entity - the entity to add the component to
        componentType - the class name of the component to add
        component - the actual component data
        Returns:
        true if the compnent was added to the entity
      • removeComponent

        public boolean removeComponent​(Entity entity,
                                       Type componentType)
        Removes the component from the specified entity
        Parameters:
        entity - the entity to remove the component from
        componentType - the class type of the component
        Returns:
        true if the component was removed
      • getComponentData

        public Object getComponentData​(Entity entity,
                                       Type componentType)
        Gets the actual data of the component associated to the entity. Requires casting from Object to the known data type
        Parameters:
        entity - the entity to retrieve the data for
        componentType - the class type of the component
        Returns:
        the component data Object associated with the entity
      • getComponentIndex

        public Integer getComponentIndex​(Type type)
        Gets the component index of the provided type
        Parameters:
        type - the type to get the index of
        Returns:
        the index of the component
      • registerSystem

        public boolean registerSystem​(Type systemType,
                                      ECSSystem instance)
        Registers the system to the SystemManager
        Parameters:
        systemType - the type of the system
        instance - the instance of the system
        Returns:
        true if successful
      • setSystemSignature

        public void setSystemSignature​(Type system,
                                       BitSet signature)
        Sets the specified system's signature to the provided signature
        Parameters:
        system - the class name of the system to set the signature of
        signature - the new signature data
      • setErr

        public static void setErr​(PrintStream newErr)
        Sets the error PrintStream to the provided PrintStream
        Parameters:
        newErr - the PrintStream to set as the write destination
      • getErr

        public static PrintStream getErr()
        Gets the current error PrintStream
        Returns:
        the current PrintStream that errors are written to
      • getComponentManager

        public ComponentManager getComponentManager()
        Gets a the current component manager
        Returns:
        the current active component manager
      • getEntityManager

        public EntityManager getEntityManager()
        Gets a the current enitity manager
        Returns:
        the current active enitity manager
      • getSystemManager

        public SystemManager getSystemManager()
        Gets a the current systems manager
        Returns:
        the current active systems manager