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 initialCapacity)
      Creates a new World instance with specified initial capacity of Entity. When the capacity is reached it will trigger a resize that may be expensive since it will resize all internal arrays of Components.
      Parameters:
      initialCapacity - the initial capacity Entity in this World, must be greater than 0
  • Method Details

    • getCurrentCapacity

      public int getCurrentCapacity()
      Gets the current capacity of Entity for this world. When an entity is created and capacity has been reached, then all internal arrays will be resized to accommodate the new entity.
      Returns:
      the capacity of Entity
    • 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.
      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.
      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.
      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 found.
      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
    • update

      public void update()
      Applies all entity mutations that happened during the previous frame. Should be called at the end of a frame.