EntityManager

Manages entities and their associated components.

Constructors

this
this(EventManager events)

Construct an empty entity manager.

Members

Functions

addComponent
void addComponent(ID id, C component)

Add a component to the specified entity.

capacity
size_t capacity()

Return the maximum capacity of entities before needing reallocation.

clear
void clear()

Delete all entities and components.

component
inout(C) component(ID id)

Return the component associated with this entity.

count
size_t count()

Return the number of entities.

create
Entity create()

Create an entity in a free slot.

destroy
void destroy(ID id)

Destroy the specified entity and invalidate all handles to it.

empty
bool empty()

Return if and only if there are no entities.

entities
auto entities()

Create a range with only the entities with the specified components.

entity
Entity entity(uint index)

Return the entity with the specified index.

entity
Entity entity(ID id)

Return the entity with the specified (and valid) id. Returns null if the id is invalid.

free
size_t free()

Return the number of free entity indices.

hasComponent
bool hasComponent(ID id)

Check if the entity has the specified component.

id
ID id(uint index)

Return the id with the specified index.

opSlice
Range opSlice()

Return a range over the entities.

removeComponent
void removeComponent(ID id)

Remove a component from the entity (no effects if it is not present).

valid
bool valid(ID id)

Check if this entity handle is valid - is not invalidated or outdated

Structs

Range
struct Range

A range over all entities in the manager.

Meta