Flecs: Components
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
Components
C API » Core

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

Collaboration diagram for Components:

## Classes
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...

## Macros
#define | ECS_TYPE_HOOK_CTOR ECS_CAST(ecs_flags32_t, 1 << 0)
| Type that contains component lifecycle callbacks.

## 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_t * | ecs_get_type_info (const ecs_world_t *world, ecs_id_t component)
| Get the type info for an component.
void | ecs_set_hooks_id (ecs_world_t *world, ecs_entity_t component, const ecs_type_hooks_t *hooks)
| Register hooks for component.
const ecs_type_hooks_t * | ecs_get_hooks_id (const ecs_world_t *world, ecs_entity_t component)
| Get hooks for component.

## Detailed Description

Functions for registering and working with components.

## Macro Definition Documentation

## ◆ ECS_TYPE_HOOK_CTOR

#define ECS_TYPE_HOOK_CTOR ECS_CAST(ecs_flags32_t, 1 << 0)

Type that contains component lifecycle callbacks.

Definition at line 888 of file flecs.h.

## 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

  world | The world.
  desc | Component 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 | component )

Get hooks for component.

Parameters

  world | The world.
  component | The component 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 | component )

Get the type info for an component.

This function returns the type information for a component. The component can be a regular component or pair. For the rules on how type information is determined based on a component id, see ecs_get_typeid().

Parameters

  world | The world.
  component | The component.

Returns
  The type information of the id.

## ◆ ecs_set_hooks_id()

void ecs_set_hooks_id | ( | ecs_world_t * | world,
|  | ecs_entity_t | component,
|  | 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

  world | The world.
  component | The component for which to register the actions
  hooks | Type that contains the component actions.