Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Module

Modules organize components, systems and more in reusable units of code. More...

Collaboration diagram for Module:

Macros

#define ECS_MODULE_DEFINE(world, id)
 Define module.
 
#define ECS_MODULE(world, id)
 
#define ECS_IMPORT(world, id)   ecs_import_c(world, id##Import, #id)
 Wrapper around ecs_import().
 

Functions

FLECS_API ecs_entity_t ecs_import (ecs_world_t *world, ecs_module_action_t module, const char *module_name)
 Import a module.
 
FLECS_API ecs_entity_t ecs_import_c (ecs_world_t *world, ecs_module_action_t module, const char *module_name_c)
 Same as ecs_import(), but with name to scope conversion.
 
FLECS_API ecs_entity_t ecs_import_from_library (ecs_world_t *world, const char *library_name, const char *module_name)
 Import a module from a library.
 
FLECS_API ecs_entity_t ecs_module_init (ecs_world_t *world, const char *c_name, const ecs_component_desc_t *desc)
 Register a new module.
 

Detailed Description

Modules organize components, systems and more in reusable units of code.

Macro Definition Documentation

◆ ECS_IMPORT

#define ECS_IMPORT ( world,
id )   ecs_import_c(world, id##Import, #id)

Wrapper around ecs_import().

This macro provides a convenient way to load a module with the world. It can be used like this:

ECS_IMPORT(world, FlecsSystemsPhysics);
#define ECS_IMPORT(world, id)
Wrapper around ecs_import().
Definition module.h:118

Definition at line 118 of file module.h.

◆ ECS_MODULE

#define ECS_MODULE ( world,
id )
Value:
ecs_entity_t ecs_id(id) = 0; ECS_MODULE_DEFINE(world, id)\
(void)ecs_id(id)
#define ECS_MODULE_DEFINE(world, id)
Define module.
Definition module.h:98
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:318

Definition at line 106 of file module.h.

◆ ECS_MODULE_DEFINE

#define ECS_MODULE_DEFINE ( world,
id )
Value:
{\
ecs_component_desc_t desc = {0};\
desc.entity = ecs_id(id);\
ecs_id(id) = ecs_module_init(world, #id, &desc);\
ecs_set_scope(world, ecs_id(id));\
}
FLECS_API ecs_entity_t ecs_module_init(ecs_world_t *world, const char *c_name, const ecs_component_desc_t *desc)
Register a new module.
Used with ecs_component_init().
Definition flecs.h:984
ecs_entity_t entity
Existing entity to associate with observer (optional)
Definition flecs.h:988

Define module.

Definition at line 98 of file module.h.

Function Documentation

◆ ecs_import()

FLECS_API ecs_entity_t ecs_import ( ecs_world_t * world,
ecs_module_action_t module,
const char * module_name )

Import a module.

This operation will load a modules and store the public module handles in the handles_out out parameter. The module name will be used to verify if the module was already loaded, in which case it won't be reimported. The name will be translated from PascalCase to an entity path (pascal.case) before the lookup occurs.

Module contents will be stored as children of the module entity. This prevents modules from accidentally defining conflicting identifiers. This is enforced by setting the scope before and after loading the module to the module entity id.

A more convenient way to import a module is by using the ECS_IMPORT macro.

Parameters
worldThe world.
moduleThe module import function.
module_nameThe name of the module.
Returns
The module entity.

◆ ecs_import_c()

FLECS_API ecs_entity_t ecs_import_c ( ecs_world_t * world,
ecs_module_action_t module,
const char * module_name_c )

Same as ecs_import(), but with name to scope conversion.

PascalCase names are automatically converted to scoped names.

Parameters
worldThe world.
moduleThe module import function.
module_name_cThe name of the module.
Returns
The module entity.

◆ ecs_import_from_library()

FLECS_API ecs_entity_t ecs_import_from_library ( ecs_world_t * world,
const char * library_name,
const char * module_name )

Import a module from a library.

Similar to ecs_import(), except that this operation will attempt to load the module from a dynamic library.

A library may contain multiple modules, which is why both a library name and a module name need to be provided. If only a library name is provided, the library name will be reused for the module name.

The library will be looked up using a canonical name, which is in the same form as a module, like flecs.components.transform. To transform this identifier to a platform specific library name, the operation relies on the module_to_dl callback of the os_api which the application has to override if the default does not yield the correct library name.

Parameters
worldThe world.
library_nameThe name of the library to load.
module_nameThe name of the module to load.