Template

Template — Entities with a pre-defined set of components.

Functions

Description

An entity template is a named set of components and values for those components. Templates are used to create entities with a pre-defined composition.

Creating templates is similar to creating entities. Create a new template with leecs_template_new() and then add components to the template using leecs_template_add_component() and leecs_template_add_tag(). Then any number of entities can be created using leecs_entity_new_from_template() and they will have the same components with the same values which were added to the template.

Additional components can be added to and removed from entities created from a template, but the components from the template cannot be removed.

Functions

leecs_template_new ()

void
leecs_template_new (LeecsRegistry *registry,
                    const char *name);

Creates a new empty entity template in registry .

Parameters

registry

LeecsRegistry to register the template in.

 

name

Name of the template as a string literal.

 

leecs_template_add_component()

#define             leecs_template_add_component(registry, template, component_t, ...)

Adds component_t to the given template. When an entity is created from the template, component_t will be initialized using the given initializer list.

Parameters

registry

LeecsRegistry the template is stored in.

 

template

Name of the template.

 

component_t

The type of the component.

 

...

Default initializer list for component_t . Must not contain dynamically allocated memory.

 

leecs_template_add_tag()

#define             leecs_template_add_tag(registry, template, tag)

Adds tag to the given template.

Parameters

registry

LeecsRegistry the template is stored in.

 

template

Name of the template.

 

tag

The symbol of the tag.

 

leecs_template_has_component()

#define             leecs_template_has_component(registry, template, component)

Checks whether the given template has component .

Parameters

registry

LeecsRegistry the template is stored in.

 

template

Name of the template.

 

component

The symbol of the component.

 

Returns

true if the template has component , false is not.