Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Components

Functions for registering and working with components. More...

Collaboration diagram for Components:

Classes

struct  ecs_type_hooks_t
 Type that contains component lifecycle callbacks. More...
 
struct  ecs_type_info_t
 Type that contains component information (passed to ctors/dtors/...) More...
 
struct  ecs_component_desc_t
 Used with ecs_component_init(). More...
 

Typedefs

typedef struct ecs_component_desc_t ecs_component_desc_t
 Used with ecs_component_init().
 

Functions

ecs_entity_t ecs_component_init (ecs_world_t *world, const ecs_component_desc_t *desc)
 Find or create a component.
 
const ecs_type_info_tecs_get_type_info (const ecs_world_t *world, ecs_id_t id)
 Get the type for an id.
 
void ecs_set_hooks_id (ecs_world_t *world, ecs_entity_t id, const ecs_type_hooks_t *hooks)
 Register hooks for component.
 
const ecs_type_hooks_tecs_get_hooks_id (const ecs_world_t *world, ecs_entity_t id)
 Get hooks for component.
 

Detailed Description

Functions for registering and working with components.

Function Documentation

◆ ecs_component_init()

ecs_entity_t ecs_component_init ( ecs_world_t * world,
const ecs_component_desc_t * desc )

Find or create a component.

This operation creates a new component, or finds an existing one. The find or create behavior is the same as ecs_entity_init().

When an existing component is found, the size and alignment are verified with the provided values. If the values do not match, the operation will fail.

See the documentation of ecs_component_desc_t for more details.

Parameters
worldThe world.
descComponent init parameters.
Returns
A handle to the new or existing component, or 0 if failed.

◆ ecs_get_hooks_id()

const ecs_type_hooks_t * ecs_get_hooks_id ( const ecs_world_t * world,
ecs_entity_t id )

Get hooks for component.

Parameters
worldThe world.
idThe component id for which to retrieve the hooks.
Returns
The hooks for the component, or NULL if not registered.

◆ ecs_get_type_info()

const ecs_type_info_t * ecs_get_type_info ( const ecs_world_t * world,
ecs_id_t id )

Get the type for an id.

This function returns the type information for an id. The specified id can be any valid id. For the rules on how type information is determined based on id, see ecs_get_typeid().

Parameters
worldThe world.
idThe id.
Returns
The type information of the id.

◆ ecs_set_hooks_id()

void ecs_set_hooks_id ( ecs_world_t * world,
ecs_entity_t id,
const ecs_type_hooks_t * hooks )

Register hooks for component.

Hooks allow for the execution of user code when components are constructed, copied, moved, destructed, added, removed or set. Hooks can be assigned as as long as a component has not yet been used (added to an entity).

The hooks that are currently set can be accessed with ecs_get_type_info().

Parameters
worldThe world.
idThe component id for which to register the actions
hooksType that contains the component actions.