java.lang.Object
technology.sola.ecs.World
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateEntity(@Nullable String uniqueId, @Nullable String name, Component... components) Creates a newEntityinside this World with a set unique id.createEntity(@Nullable String name, Component... components) Creates a newEntityinside this World with a random unique id.createEntity(Component... components) Creates a newEntityinside this World with a random unique id.final voidDrops a view with desiredComponents if it exists.findEntitiesWithComponents(Class<? extends Component>... componentClasses) @Nullable EntityfindEntityByName(String name) Searches for anEntityby its name.@Nullable EntityfindEntityByUniqueId(String uniqueId) Searches for anEntityby its unique id.intGets the current capacity ofEntityfor this world.@Nullable EntitygetEntityAtIndex(int index) Gets anEntityby index or null if one is not present.intGets the current number ofEntityin this World.voidupdate()Applies all entity mutations that happened during the previous frame.
-
Constructor Details
-
World
public World(int initialCapacity) Creates a new World instance with specified initial capacity ofEntity. When the capacity is reached it will trigger a resize that may be expensive since it will resize all internal arrays ofComponents.- Parameters:
initialCapacity- the initial capacityEntityin this World, must be greater than 0
-
-
Method Details
-
getCurrentCapacity
public int getCurrentCapacity()Gets the current capacity ofEntityfor 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 ofEntityin this World.- Returns:
- the current number of
Entityin this World
-
createEntity
Creates a newEntityinside this World with a random unique id. It is initialized with a set of components.- Parameters:
components- theComponents to initialize the Entity with- Returns:
- a new
Entity
-
createEntity
Creates a newEntityinside this World with a random unique id. It is initialized with name and components.- Parameters:
name- the name to initialize this Entity withcomponents- theComponents to initialize the Entity with- Returns:
- a new
Entity
-
createEntity
public Entity createEntity(@Nullable String uniqueId, @Nullable String name, Component... components) Creates a newEntityinside 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 automaticallyname- the name to initialize this Entity withcomponents- theComponents to initialize the Entity with- Returns:
- a new
Entity
-
getEntityAtIndex
Gets anEntityby index or null if one is not present.- Parameters:
index- the index of theEntityto retrieve- Returns:
- the
Entity
-
findEntityByName
Searches for anEntityby its name. Returns null if not found.- Parameters:
name- the name of theEntity- Returns:
- the
Entitywith desired name or null if not found
-
findEntityByUniqueId
Searches for anEntityby its unique id. Returns null if not found.- Parameters:
uniqueId- the unique id of theEntity- Returns:
- the
Entitywith desired uniqueId or null if not found
-
getEntities
- Returns:
- a
Listof allEntity
-
getEnabledEntities
- Returns:
- a
Listof all enabledEntity
-
findEntitiesWithComponents
@SafeVarargs public final List<Entity> findEntitiesWithComponents(Class<? extends Component>... componentClasses) Gets aListofEntitywhere eachEntityhas all of theComponentclasses searched for and is not disabled.- Parameters:
componentClasses- array ofComponentclasses eachEntitywill have- Returns:
- a
ListofEntityeach having the desiredComponents
-
createView
- Returns:
- the
ViewBuilderinstance
-
dropView
Drops a view with desiredComponents 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.
-