Class World

java.lang.Object
technology.sola.ecs.World

@NullMarked public class World extends Object
World contains arrays of Components and methods for creating Entity instances and searching for entities.
  • Constructor Details

    • World

      public World(int maxEntityCount)
      Creates a new World instance with specified max Entity count.
      Parameters:
      maxEntityCount - the maximum number of Entity in this World, must be greater than 0
  • Method Details

    • cleanupDestroyedEntities

      public void cleanupDestroyedEntities()
      Removes entities that were queued for destruction. Should be called at the end of a frame.
    • getMaxEntityCount

      public int getMaxEntityCount()
      Gets the maximum Entity count for this world.
      Returns:
      the max Entity count
    • getEntityCount

      public int getEntityCount()
      Gets the current number of Entity in this World.
      Returns:
      the current number of Entity in this World
    • createEntity

      public Entity createEntity(Component... components)
      Creates a new Entity inside this World with a random unique id. It is initialized with a set of components.

      If the total entity count goes above the max number specified in this world then an exception will be thrown.

      Parameters:
      components - the Components to initialize the Entity with
      Returns:
      a new Entity
    • createEntity

      public Entity createEntity(@Nullable String name, Component... components)
      Creates a new Entity inside this World with a random unique id. It is initialized with name and components.

      If the total entity count goes above the max number specified in this world then an exception will be thrown.

      Parameters:
      name - the name to initialize this Entity with
      components - the Components to initialize the Entity with
      Returns:
      a new Entity
    • createEntity

      public Entity createEntity(@Nullable String uniqueId, @Nullable String name, Component... components)
      Creates a new Entity inside this World with a set unique id. It is initialized with name and components. If the provided unique id is null then one will be generated.

      If the total entity count goes above the max number specified in this world then an exception will be thrown.

      Parameters:
      uniqueId - the unique id to initialize this Entity with or null to generate one automatically
      name - the name to initialize this Entity with
      components - the Components to initialize the Entity with
      Returns:
      a new Entity
    • getEntityAtIndex

      public @Nullable Entity getEntityAtIndex(int index)
      Gets an Entity by index or null if one is not present.
      Parameters:
      index - the index of the Entity to retrieve
      Returns:
      the Entity
    • findEntityByName

      public @Nullable Entity findEntityByName(String name)
      Searches for an Entity by its name. Returns null if not ofund
      Parameters:
      name - the name of the Entity
      Returns:
      the Entity with desired name or null if not found
    • findEntityByUniqueId

      public @Nullable Entity findEntityByUniqueId(String uniqueId)
      Searches for an Entity by its unique id. Returns null if not found.
      Parameters:
      uniqueId - the unique id of the Entity
      Returns:
      the Entity with desired uniqueId or null if not found
    • getEntities

      public List<Entity> getEntities()
      Gets a List of all Entity in the world even if they are disabled.
      Returns:
      a List of all Entity
    • getEnabledEntities

      public List<Entity> getEnabledEntities()
      Gets a List of all Entity in the world that are not disabled.
      Returns:
      a List of all enabled Entity
    • findEntitiesWithComponents

      @SafeVarargs public final List<Entity> findEntitiesWithComponents(Class<? extends Component>... componentClasses)
      Gets a List of Entity where each Entity has all of the Component classes searched for and is not disabled.
      Parameters:
      componentClasses - array of Component classes each Entity will have
      Returns:
      a List of Entity each having the desired Components
    • createView

      public ViewBuilder createView()
      Returns a ViewBuilder instance for creating a View of ViewEntry with desired Components
      Returns:
      the ViewBuilder instance
    • dropView

      @SafeVarargs public final void dropView(Class<? extends Component>... componentClasses)
      Drops a view with desired Components if it exists. Any previous instance of this view will no longer receive updates.
      Parameters:
      componentClasses - the component classes for the view to drop