Flecs v4.0
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...

This graph shows which files directly or indirectly include this file:

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.
 
#define ECS_ENTITY_DEFINE(world, id_, ...)
 Define a forward declared entity.
 
#define ECS_ENTITY(world, id, ...)
 Declare & define an entity.
 
#define ECS_TAG_DECLARE   ECS_DECLARE
 Forward declare a tag.
 
#define ECS_TAG_DEFINE(world, id)   ECS_ENTITY_DEFINE(world, id, 0)
 Define a forward declared tag.
 
#define ECS_TAG(world, id)   ECS_ENTITY(world, id, 0)
 Declare & define a tag.
 
#define ECS_PREFAB_DECLARE   ECS_DECLARE
 Forward declare a prefab.
 
#define ECS_PREFAB_DEFINE(world, id, ...)   ECS_ENTITY_DEFINE(world, id, Prefab, __VA_ARGS__)
 Define a forward declared prefab.
 
#define ECS_PREFAB(world, id, ...)   ECS_ENTITY(world, id, Prefab, __VA_ARGS__)
 Declare & define a prefab.
 
#define ECS_COMPONENT_DECLARE(id)   ecs_entity_t ecs_id(id)
 Forward declare a component.
 
#define ECS_COMPONENT_DEFINE(world, id_)
 Define a forward declared component.
 
#define ECS_COMPONENT(world, id)
 Declare & define a component.
 
#define ECS_OBSERVER_DECLARE(id)   ecs_entity_t ecs_id(id)
 
#define ECS_OBSERVER_DEFINE(world, id_, kind, ...)
 Define a forward declared observer.
 
#define ECS_OBSERVER(world, id, kind, ...)
 Declare & define an observer.
 
#define ECS_QUERY_DECLARE(name)   ecs_query_t* name
 
#define ECS_QUERY_DEFINE(world, name_, ...)
 Define a forward declared observer.
 
#define ECS_QUERY(world, name, ...)
 Declare & define an observer.
 
#define ecs_entity(world, ...)    ecs_entity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
 Shorthand for creating an entity with ecs_entity_init().
 
#define ecs_component(world, ...)    ecs_component_init(world, &(ecs_component_desc_t) __VA_ARGS__ )
 Shorthand for creating a component with ecs_component_init().
 
#define ecs_component_t(world, T)
 Shorthand for creating a component from a type.
 
#define ecs_query(world, ...)    ecs_query_init(world, &(ecs_query_desc_t) __VA_ARGS__ )
 Shorthand for creating a query with ecs_query_cache_init.
 
#define ecs_observer(world, ...)    ecs_observer_init(world, &(ecs_observer_desc_t) __VA_ARGS__ )
 Shorthand for creating an observer with ecs_observer_init().
 
#define ecs_new_w(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_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_auto_override(world, entity, T)    ecs_auto_override_id(world, entity, ecs_id(T))
 
#define ecs_auto_override_pair(world, subject, first, second)    ecs_auto_override_id(world, subject, ecs_pair(first, second))
 
#define ecs_insert(world, ...)    ecs_entity(world, { .set = ecs_values(__VA_ARGS__)})
 
#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_override(world, entity, T, ...)
 
#define ecs_emplace(world, entity, T, is_new)    (ECS_CAST(T*, ecs_emplace_id(world, entity, ecs_id(T), is_new)))
 
#define ecs_emplace_pair(world, entity, First, second, is_new)    (ECS_CAST(First*, ecs_emplace_id(world, entity, ecs_pair_t(First, second), is_new)))
 
#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_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(world, entity, T)    (ECS_CAST(T*, ecs_get_mut_id(world, entity, ecs_id(T))))
 
#define ecs_ensure(world, entity, T)    (ECS_CAST(T*, ecs_ensure_id(world, entity, ecs_id(T))))
 
#define ecs_ensure_pair(world, subject, First, second)
 
#define ecs_ensure_pair_second(world, subject, first, Second)
 
#define ecs_ensure(world, entity, T)    (ECS_CAST(T*, ecs_ensure_id(world, entity, ecs_id(T))))
 
#define ecs_ensure_pair(world, subject, First, second)
 
#define ecs_ensure_pair_second(world, subject, first, 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_record_get(world, record, T)    (ECS_CAST(const T*, ecs_record_get_id(world, record, ecs_id(T))))
 
#define ecs_record_has(world, record, T)    (ecs_record_has_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_ensure(world, record, T)    (ECS_CAST(T*, ecs_record_ensure_id(world, record, ecs_id(T))))
 
#define ecs_record_ensure_pair(world, record, First, second)
 
#define ecs_record_ensure_pair_second(world, record, first, 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(T*, ecs_ref_get_id(world, ref, ecs_id(T))))
 
#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_ptr(world, comp, ptr)    ecs_set_ptr(world, ecs_id(comp), comp, ptr)
 
#define ecs_singleton_set(world, comp, ...)    ecs_set(world, ecs_id(comp), comp, __VA_ARGS__)
 
#define ecs_singleton_ensure(world, comp)    ecs_ensure(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_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_get_target_for(world, entity, rel, T)    ecs_get_target_for_id(world, entity, rel, ecs_id(T))
 
#define ecs_enable_component(world, entity, T, enable)    ecs_enable_id(world, entity, ecs_id(T), enable)
 
#define ecs_is_enabled(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_from(world, parent, path)    ecs_lookup_path_w_sep(world, parent, path, ".", NULL, true)
 
#define ecs_get_path_from(world, parent, child)    ecs_get_path_w_sep(world, parent, child, ".", NULL)
 
#define ecs_get_path(world, child)    ecs_get_path_w_sep(world, 0, child, ".", NULL)
 
#define ecs_get_path_buf(world, child, buf)    ecs_get_path_w_sep_buf(world, 0, child, ".", NULL, buf, false)
 
#define ecs_new_from_path(world, parent, path)    ecs_new_from_path_w_sep(world, parent, 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.
 
#define ECS_DTOR(type, var, ...)    ECS_XTOR_IMPL(type, dtor, var, __VA_ARGS__)
 Declare a destructor.
 
#define ECS_COPY(type, dst_var, src_var, ...)    ECS_COPY_IMPL(type, dst_var, src_var, __VA_ARGS__)
 Declare a copy action.
 
#define ECS_MOVE(type, dst_var, src_var, ...)    ECS_MOVE_IMPL(type, dst_var, src_var, __VA_ARGS__)
 Declare a move action.
 
#define ECS_ON_ADD(type, ptr, ...)    ECS_HOOK_IMPL(type, ecs_on_add(type), ptr, __VA_ARGS__)
 Declare component hooks.
 
#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_field_self(it, T, index)    (ECS_CAST(T*, ecs_field_self_w_size(it, sizeof(T), index)))
 
#define ecs_field_at(it, T, index, row)    (ECS_CAST(T*, ecs_field_at_w_size(it, sizeof(T), index, row)))
 
#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_ids(...)   (ecs_id_t[]){ __VA_ARGS__, 0 }
 Convenience macro for creating compound literal id array.
 
#define ecs_values(...)   (ecs_value_t[]){ __VA_ARGS__, {0, 0}}
 Convenience macro for creating compound literal values array.
 
#define ecs_value_ptr(T, ptr)   ((ecs_value_t){ecs_id(T), ptr})
 Convenience macro for creating compound literal value.
 
#define ecs_value_pair(R, t, ...)   ((ecs_value_t){ecs_pair_t(R, t), &(R)__VA_ARGS__})
 Convenience macro for creating compound literal pair value.
 
#define ecs_value_pair_2nd(r, T, ...)   ((ecs_value_t){ecs_pair(r, ecs_id(T)), &(T)__VA_ARGS__})
 Convenience macro for creating compound literal pair value.
 
#define ecs_value_new_t(world, T)   ecs_value_new(world, ecs_id(T))
 Convenience macro for creating heap allocated value.
 
#define ecs_value(T, ...)   ((ecs_value_t){ecs_id(T), &(T)__VA_ARGS__})
 Convenience macro for creating compound literal value literal.
 
#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_with(e)   ecs_pair(EcsWith, e)
 
#define ecs_each(world, id)   ecs_each_id(world, ecs_id(id))
 
#define ecs_each_pair(world, r, t)   ecs_each_id(world, ecs_pair(r, t))
 
#define ecs_each_pair_t(world, R, t)   ecs_each_id(world, ecs_pair(ecs_id(R), t))
 

Detailed Description

Extends the core API with convenience macros for C applications.

Definition in file flecs_c.h.