Entity

Entity — Game object constructed through composition.

Functions

Types and Values

typedef LeecsEntity

Description

An entity can be any object or thing in a game which is constructed through composition from any number of defined components. Entities are stored in a LeecsWorld and they are identified by a numeric ID LeecsEntity.

Components can be added and removed from entities at any time using leecs_entity_add_component(), leecs_entity_add_tag(), and leecs_entity_remove_component(). The values of a component can be accessed with leecs_entity_get_component().

The LeecsEntity IDs are not stable, and they may change when an entity is deleted using leecs_entity_delete(). To modify an entity, it is best to always query it using its components and use the LeecsEntity ID from the query.

Functions

leecs_entity_new ()

LeecsEntity
leecs_entity_new (LeecsWorld *world);

Creates a new empty entity in world .

Parameters

world

LeecsWorld to create an entity in.

 

Returns

LeecsEntity ID of the new entity.


leecs_entity_new_from_template ()

LeecsEntity
leecs_entity_new_from_template (LeecsWorld *world,
                                const char *template);

Creates a new entity from the given template in world .

Parameters

world

LeecsWorld to create an entity in.

 

template_name

Name of the template.

 

Returns

LeecsEntity ID of the new entity.


leecs_entity_delete ()

void
leecs_entity_delete (LeecsWorld *world,
                     LeecsEntity entity);

Deletes entity from world .

Parameters

world

LeecsWorld entity is stored in.

 

entity

LeecsEntity to delete.

 

leecs_entity_add_component()

#define             leecs_entity_add_component(world, entity, component_t, ...)

Adds component_t to entity and initializes it with the given initializer list.

Parameters

world

LeecsWorld entity is stored in.

 

entity

LeecsEntity to add component_t to.

 

component_t

The type of the component.

 

...

Initializer list for component_t .

 

leecs_entity_add_tag()

#define             leecs_entity_add_tag(world, entity, tag)

Adds tag to entity .

Parameters

world

LeecsWorld entity is stored in.

 

entity

LeecsEntity to add tag to.

 

tag

The symbol of the tag.

 

leecs_entity_remove_component()

#define             leecs_entity_remove_component(world, entity, component)

Removed component from entity .

Parameters

world

LeecsWorld entity is stored in.

 

entity

LeecsEntity to remove component from.

 

component

The symbol of the component.

 

leecs_entity_get_component()

#define             leecs_entity_get_component(world, entity, component_t)

Gets a pointer to component_t belonging to entity .

Parameters

world

LeecsWorld entity is stored in.

 

entity

LeecsEntity to get component_t from.

 

component_t

The type of the component.

 

Returns

Pointer to a component.

[transfer none]


leecs_entity_has_component()

#define             leecs_entity_has_component(world, entity, component)

Parameters

world

LeecsWorld entity is stored in.

 

entity

LeecsEntity to check for component .

 

component

The symbol of the component.

 

Returns

true if entity has component , false if not.

Types and Values

LeecsEntity

typedef unsigned int LeecsEntity;

Numeric ID for entities.