Flecs v3.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs_c.h File Reference

Extends the core API with convenience macros for C applications. More...

Go to the source code of this file.

Macros

#define ECS_DECLARE(id)    ecs_entity_t id, ecs_id(id)
 
#define ECS_ENTITY_DECLARE   ECS_DECLARE
 Forward declare an entity. More...
 
#define ECS_ENTITY_DEFINE(world, id_, ...)
 Define a forward declared entity. More...
 
#define ECS_ENTITY(world, id, ...)
 Declare & define an entity. More...
 
#define ECS_TAG_DECLARE   ECS_DECLARE
 Forward declare a tag. More...
 
#define ECS_TAG_DEFINE(world, id)   ECS_ENTITY_DEFINE(world, id, 0)
 Define a forward declared tag. More...
 
#define ECS_TAG(world, id)   ECS_ENTITY(world, id, 0)
 Declare & define a tag. More...
 
#define ECS_PREFAB_DECLARE   ECS_DECLARE
 Forward declare a prefab. More...
 
#define ECS_PREFAB_DEFINE(world, id, ...)   ECS_ENTITY_DEFINE(world, id, Prefab, __VA_ARGS__)
 Define a forward declared prefab. More...
 
#define ECS_PREFAB(world, id, ...)   ECS_ENTITY(world, id, Prefab, __VA_ARGS__)
 Declare & define a prefab. More...
 
#define ECS_COMPONENT_DECLARE(id)   ecs_entity_t ecs_id(id)
 Forward declare a component. More...
 
#define ECS_COMPONENT_DEFINE(world, id_)
 Define a forward declared component. More...
 
#define ECS_COMPONENT(world, id)
 Declare & define a component. More...
 
#define ECS_OBSERVER_DECLARE(id)   ecs_entity_t ecs_id(id)
 
#define ECS_OBSERVER_DEFINE(world, id_, kind, ...)
 Define a forward declared observer. More...
 
#define ECS_OBSERVER(world, id, kind, ...)
 Declare & define an observer. More...
 
#define ecs_entity(world, ...)    ecs_entity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
 Shorthand for creating an entity with ecs_entity_init. More...
 
#define ecs_component(world, ...)    ecs_component_init(world, &(ecs_component_desc_t) __VA_ARGS__ )
 Shorthand for creating a component with ecs_component_init. More...
 
#define ecs_filter(world, ...)    ecs_filter_init(world, &(ecs_filter_desc_t) __VA_ARGS__ )
 Shorthand for creating a filter with ecs_filter_init. More...
 
#define ecs_query(world, ...)    ecs_query_init(world, &(ecs_query_desc_t) __VA_ARGS__ )
 Shorthand for creating a query with ecs_query_init. More...
 
#define ecs_observer(world, ...)    ecs_observer_init(world, &(ecs_observer_desc_t) __VA_ARGS__ )
 Shorthand for creating an observer with ecs_observer_init. More...
 
#define ecs_new(world, T)   ecs_new_w_id(world, ecs_id(T))
 
#define ecs_new_w_pair(world, first, second)    ecs_new_w_id(world, ecs_pair(first, second))
 
#define ecs_bulk_new(world, component, count)    ecs_bulk_new_w_id(world, ecs_id(component), count)
 
#define ecs_new_entity(world, n)
 
#define ecs_new_prefab(world, n)
 
#define ecs_delete_children(world, parent)    ecs_delete_with(world, ecs_pair(EcsChildOf, parent))
 
#define ecs_add(world, entity, T)    ecs_add_id(world, entity, ecs_id(T))
 
#define ecs_add_pair(world, subject, first, second)    ecs_add_id(world, subject, ecs_pair(first, second))
 
#define ecs_remove(world, entity, T)    ecs_remove_id(world, entity, ecs_id(T))
 
#define ecs_remove_pair(world, subject, first, second)    ecs_remove_id(world, subject, ecs_pair(first, second))
 
#define ecs_override(world, entity, T)    ecs_override_id(world, entity, ecs_id(T))
 
#define ecs_override_pair(world, subject, first, second)    ecs_override_id(world, subject, ecs_pair(first, second))
 
#define ecs_set_ptr(world, entity, component, ptr)    ecs_set_id(world, entity, ecs_id(component), sizeof(component), ptr)
 
#define ecs_set(world, entity, component, ...)    ecs_set_id(world, entity, ecs_id(component), sizeof(component), &(component)__VA_ARGS__)
 
#define ecs_set_pair(world, subject, First, second, ...)
 
#define ecs_set_pair_second(world, subject, first, Second, ...)
 
#define ecs_set_pair_object   ecs_set_pair_second
 
#define ecs_set_override(world, entity, T, ...)
 
#define ecs_emplace(world, entity, T)    (ECS_CAST(T*, ecs_emplace_id(world, entity, ecs_id(T))))
 
#define ecs_get(world, entity, T)    (ECS_CAST(const T*, ecs_get_id(world, entity, ecs_id(T))))
 
#define ecs_get_pair(world, subject, First, second)
 
#define ecs_get_pair_second(world, subject, first, Second)
 
#define ecs_get_pair_object   ecs_get_pair_second
 
#define ecs_record_get(world, record, T)    (ECS_CAST(const T*, ecs_record_get_id(world, record, ecs_id(T))))
 
#define ecs_record_get_pair(world, record, First, second)
 
#define ecs_record_get_pair_second(world, record, first, Second)
 
#define ecs_record_get_mut(world, record, T)    (ECS_CAST(T*, ecs_record_get_mut_id(world, record, ecs_id(T))))
 
#define ecs_record_get_mut_pair(world, record, First, second)
 
#define ecs_record_get_mut_pair_second(world, record, first, Second)
 
#define ecs_record_get_mut_pair_object   ecs_record_get_mut_pair_second
 
#define ecs_ref_init(world, entity, T)    ecs_ref_init_id(world, entity, ecs_id(T))
 
#define ecs_ref_get(world, ref, T)    (ECS_CAST(const T*, ecs_ref_get_id(world, ref, ecs_id(T))))
 
#define ecs_get_mut(world, entity, T)    (ECS_CAST(T*, ecs_get_mut_id(world, entity, ecs_id(T))))
 
#define ecs_get_mut_pair(world, subject, First, second)
 
#define ecs_get_mut_pair_second(world, subject, first, Second)
 
#define ecs_get_mut_pair_object   ecs_get_mut_pair_second
 
#define ecs_modified(world, entity, component)    ecs_modified_id(world, entity, ecs_id(component))
 
#define ecs_modified_pair(world, subject, first, second)    ecs_modified_id(world, subject, ecs_pair(first, second))
 
#define ecs_singleton_add(world, comp)    ecs_add(world, ecs_id(comp), comp)
 
#define ecs_singleton_remove(world, comp)    ecs_remove(world, ecs_id(comp), comp)
 
#define ecs_singleton_get(world, comp)    ecs_get(world, ecs_id(comp), comp)
 
#define ecs_singleton_set(world, comp, ...)    ecs_set(world, ecs_id(comp), comp, __VA_ARGS__)
 
#define ecs_singleton_get_mut(world, comp)    ecs_get_mut(world, ecs_id(comp), comp)
 
#define ecs_singleton_modified(world, comp)    ecs_modified(world, ecs_id(comp), comp)
 
#define ecs_has(world, entity, T)    ecs_has_id(world, entity, ecs_id(T))
 
#define ecs_has_pair(world, entity, first, second)    ecs_has_id(world, entity, ecs_pair(first, second))
 
#define ecs_owns_id(world, entity, id)    (ecs_search(world, ecs_get_table(world, entity), id, 0) != -1)
 
#define ecs_owns_pair(world, entity, first, second)    ecs_owns_id(world, entity, ecs_pair(first, second))
 
#define ecs_owns(world, entity, T)    ecs_owns_id(world, entity, ecs_id(T))
 
#define ecs_shares_id(world, entity, id)
 
#define ecs_shares_pair(world, entity, first, second)    (ecs_shares_id(world, entity, ecs_pair(first, second)))
 
#define ecs_shares(world, entity, T)    (ecs_shares_id(world, entity, ecs_id(T)))
 
#define ecs_enable_component(world, entity, T, enable)    ecs_enable_id(world, entity, ecs_id(T), enable)
 
#define ecs_is_enabled_component(world, entity, T)    ecs_is_enabled_id(world, entity, ecs_id(T))
 
#define ecs_enable_pair(world, entity, First, second, enable)    ecs_enable_id(world, entity, ecs_pair(ecs_id(First), second), enable)
 
#define ecs_is_enabled_pair(world, entity, First, second)    ecs_is_enabled_id(world, entity, ecs_pair(ecs_id(First), second))
 
#define ecs_lookup_path(world, parent, path)    ecs_lookup_path_w_sep(world, parent, path, ".", NULL, true)
 
#define ecs_lookup_fullpath(world, path)    ecs_lookup_path_w_sep(world, 0, path, ".", NULL, true)
 
#define ecs_get_path(world, parent, child)    ecs_get_path_w_sep(world, parent, child, ".", NULL)
 
#define ecs_get_fullpath(world, child)    ecs_get_path_w_sep(world, 0, child, ".", NULL)
 
#define ecs_get_fullpath_buf(world, child, buf)    ecs_get_path_w_sep_buf(world, 0, child, ".", NULL, buf)
 
#define ecs_new_from_path(world, parent, path)    ecs_new_from_path_w_sep(world, parent, path, ".", NULL)
 
#define ecs_new_from_fullpath(world, path)    ecs_new_from_path_w_sep(world, 0, path, ".", NULL)
 
#define ecs_add_path(world, entity, parent, path)    ecs_add_path_w_sep(world, entity, parent, path, ".", NULL)
 
#define ecs_add_fullpath(world, entity, path)    ecs_add_path_w_sep(world, entity, 0, path, ".", NULL)
 
#define ecs_set_hooks(world, T, ...)    ecs_set_hooks_id(world, ecs_id(T), &(ecs_type_hooks_t)__VA_ARGS__)
 
#define ecs_get_hooks(world, T)    ecs_get_hooks_id(world, ecs_id(T));
 
#define ECS_CTOR(type, var, ...)    ECS_XTOR_IMPL(type, ctor, var, __VA_ARGS__)
 Declare a constructor. More...
 
#define ECS_DTOR(type, var, ...)    ECS_XTOR_IMPL(type, dtor, var, __VA_ARGS__)
 Declare a destructor. More...
 
#define ECS_COPY(type, dst_var, src_var, ...)    ECS_COPY_IMPL(type, dst_var, src_var, __VA_ARGS__)
 Declare a copy action. More...
 
#define ECS_MOVE(type, dst_var, src_var, ...)    ECS_MOVE_IMPL(type, dst_var, src_var, __VA_ARGS__)
 Declare a move action. More...
 
#define ECS_ON_ADD(type, ptr, ...)    ECS_HOOK_IMPL(type, ecs_on_add(type), ptr, __VA_ARGS__)
 Declare component hooks. More...
 
#define ECS_ON_REMOVE(type, ptr, ...)    ECS_HOOK_IMPL(type, ecs_on_remove(type), ptr, __VA_ARGS__)
 
#define ECS_ON_SET(type, ptr, ...)    ECS_HOOK_IMPL(type, ecs_on_set(type), ptr, __VA_ARGS__)
 
#define ecs_ctor(type)   type##_ctor
 
#define ecs_dtor(type)   type##_dtor
 
#define ecs_copy(type)   type##_copy
 
#define ecs_move(type)   type##_move
 
#define ecs_on_set(type)   type##_on_set
 
#define ecs_on_add(type)   type##_on_add
 
#define ecs_on_remove(type)   type##_on_remove
 
#define ecs_count(world, type)    ecs_count_id(world, ecs_id(type))
 
#define ecs_field(it, T, index)    (ECS_CAST(T*, ecs_field_w_size(it, sizeof(T), index)))
 
#define ecs_table_get(world, table, T, offset)    (ECS_CAST(T*, ecs_table_get_id(world, table, ecs_id(T), offset)))
 
#define ecs_table_get_pair(world, table, First, second, offset)    (ECS_CAST(First*, ecs_table_get_id(world, table, ecs_pair(ecs_id(First), second), offset)))
 
#define ecs_table_get_pair_second(world, table, first, Second, offset)    (ECS_CAST(Second*, ecs_table_get_id(world, table, ecs_pair(first, ecs_id(Second)), offset)))
 
#define ecs_value(T, ptr)   ((ecs_value_t){ecs_id(T), ptr})
 
#define ecs_value_new_t(world, T)   ecs_value_new(world, ecs_id(T))
 
#define ecs_sort_table(id)   ecs_id(id##_sort_table)
 
#define ecs_compare(id)   ecs_id(id##_compare_fn)
 
#define ECS_SORT_TABLE_WITH_COMPARE(id, op_name, compare_fn, ...)
 
#define ECS_SORT_TABLE(id, ...)    ECS_SORT_TABLE_WITH_COMPARE(id, ecs_sort_table(id), ecs_compare(id), __VA_ARGS__)
 
#define ECS_COMPARE(id, ...)
 
#define ecs_isa(e)   ecs_pair(EcsIsA, e)
 
#define ecs_childof(e)   ecs_pair(EcsChildOf, e)
 
#define ecs_dependson(e)   ecs_pair(EcsDependsOn, e)
 
#define ecs_query_new(world, q_expr)
 
#define ecs_rule_new(world, q_expr)
 

Detailed Description

Extends the core API with convenience macros for C applications.

Definition in file flecs_c.h.