6template <
typename T =
void,
bool Sparse = false,
typename Owner =
void,
typename Construct = T>
9 using construct_type = Construct;
10 static constexpr bool sparse = Sparse;
15 if constexpr (std::is_void_v<Owner>) {
26 if constexpr (is_enum_v<T>) {
37auto resolve_id(
world_t *world, arg_list<T>) {
38 using A = actual_type_t<T>;
39 auto id = _::type<T>::id(world);
40 if constexpr (is_pair_v<T>) {
41 return component_id<A, false, pair_first_t<T>>{id, 0};
43 return component_id<A, true>{id,
id};
47template <
typename First,
typename Second>
48auto resolve_id(
world_t *world, arg_list<First, Second>) {
50 return component_id<actual_type_t<T>,
false, First, First>{
51 _::type<T>::id(world), 0};
54template <
typename First,
typename Second>
55auto resolve_id(
world_t *world, arg_list<First>, Second second) {
56 auto first = _::type<First>::id(world);
57 return component_id<First>{ecs_pair(first, entity_id(world, second)), first};
61auto resolve_id(
world_t *world, arg_list<>, T value) {
62 if constexpr (is_enum_v<T>) {
63 return resolve_id(world, arg_list<T>{}, value);
66 return component_id<>{value, value};
71 return component_id<>{ecs_pair(first, second), first};
74template <
typename... T,
typename... Args>
75auto make_id(
world_t *world, Args... args) {
76 return resolve_id(world, arg_list<T...>{}, args...);
79template <
typename T =
void,
typename Second =
void>
82template <
typename... T>
83using value_type_t =
typename value_type<T...>::type;
85template <
typename... T,
typename A>
87 if constexpr (
sizeof...(T)) {
88 return make_id<T...>(
world);
90 return make_id<A>(
world);
94template <
typename Second>
96 auto second = _::type<Second>::id(world);
97 auto id = ecs_pair(first, second);
100 "type of pair is not Second");
101 return component_id<Second>{id, first};
104template <
typename First,
typename Second>
105auto second_id(
world_t *world) {
106 static_assert(is_empty_v<First>,
"first element of pair must be a tag");
107 return make_id<First, Second>(world);
110template <
typename Id>
112 flecs_static_assert(std::is_void_v<typename Id::construct_type> ||
113 is_flecs_constructible<typename Id::construct_type>::value,
114 "cannot default construct component: use emplace<T>()");
118template <
typename Id>
123 if constexpr (Id::sparse && is_enum_v<typename Id::type>) {
124 return ecs_has_pair(world, entity,
id.
id, flecs::Wildcard);
129template <
bool Mutable,
bool Required,
bool Ensure = false,
typename Id>
131 using T =
typename Id::type;
132 using A = conditional_t<Mutable, T, const T>;
134 if constexpr (Ensure) {
135 if constexpr (std::is_void_v<T>) {
138 return ecs_ensure_id(world, entity,
id.
id,
static_cast<size_t>(ti->size));
142 }
else if constexpr (Id::sparse && !std::is_void_v<T> &&
143 is_get_sparse_component<T>::value)
146 }
else if constexpr (Mutable) {
152 if constexpr (!std::is_void_v<T>) {
154 "operation invalid for empty type");
156 A *ptr =
static_cast<A*
>(get());
157 if constexpr (Required) {
159 "entity does not have component (use try_get or try_get_mut)");
161 if constexpr (Required && !std::is_void_v<T>) {
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_OPERATION
Invalid operation error code.
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t component)
Get the type info for a component.
ecs_entity_t entity_t
Entity type.
ecs_world_t world_t
World type.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity has a component.
#define ecs_has_pair(world, entity, first, second)
Test if an entity has a pair.
const void * ecs_get_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Get an immutable pointer to a component.
void * ecs_get_mut_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Get a mutable pointer to a component.
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, size_t size)
Ensure an entity has a component and return a pointer.
void * ecs_get_sparse_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, size_t size)
Get a pointer to a sparse component.
Get the actual type from a regular type or pair.
entity()
Default constructor.
Class that wraps around a flecs::id_t.
Type that represents a pair.
Trait that marks a component as Sparse at compile time.