47 : flecs::
id( nullptr,
id ) { }
69 explicit operator bool()
const {
119 template <
typename Parent>
124 bool enabled()
const {
125 return !
ecs_has_id(world_, id_, flecs::Disabled);
158 template <
typename Func>
159 void each(
const Func& func)
const;
170 template <
typename Func>
171 void each(flecs::id_t
first, flecs::id_t
second,
const Func& func)
const;
183 template <
typename Func>
196 template <
typename First,
typename Func>
197 void each(
const Func& func)
const {
211 template <
typename Func>
212 void children(flecs::entity_t rel, Func&& func)
const {
216 if (id_ == flecs::Wildcard || id_ == flecs::Any) {
239 template <
typename Rel,
typename Func>
255 template <
typename Func>
257 children(flecs::ChildOf, FLECS_MOV(func));
269 template <typename T, if_t< is_actual<T>::value > = 0>
273 "operation invalid for empty type");
274 return static_cast<const T*
>(
ecs_get_id(world_, id_, comp_id));
285 template <
typename T,
typename A = actual_type_t<T>,
286 if_t< flecs::is_pair<T>::value > = 0>
290 "operation invalid for empty type");
291 return static_cast<const A*
>(
ecs_get_id(world_, id_, comp_id));
300 template <
typename First,
typename Second,
typename P = pair<First, Second>,
301 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
303 return this->try_get<P>();
312 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
316 "operation invalid for empty type");
317 return static_cast<const First*
>(
327 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
329 const auto& et = enum_type<Second>(this->world_);
331 return try_get<First>(
target);
356 template<
typename... Ts>
357 auto try_get_n()
const {
358 flecs_static_assert(
sizeof...(Ts) > 1,
"try_get_n requires at least two components");
359 flecs_static_assert(
sizeof...(Ts) < 9,
"try_get_n cannot fetch more than eight components");
360 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_const_ptr {try_get<Ts>()...};
370 template<
typename Second>
374 ECS_INVALID_PARAMETER,
"pair is not a component");
376 ECS_INVALID_PARAMETER,
"type of pair is not Second");
378 "operation invalid for empty type");
379 return static_cast<const Second*
>(
380 ecs_get_id(world_, id_, ecs_pair(first, second)));
390 template<
typename First,
typename Second>
392 return try_get<pair_object<First, Second>>();
404 template <typename T, if_t< is_actual<T>::value > = 0>
406 const T *r = try_get<T>();
407 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
408 "invalid get: entity does not have component '%s' (use try_get)",
409 flecs::_::type_name<T>());
421 template <
typename T,
typename A = actual_type_t<T>,
422 if_t< flecs::is_pair<T>::value > = 0>
424 const A *r = try_get<T>();
425 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
426 "invalid get: entity does not have component '%s' (use try_get)",
427 flecs::_::type_name<T>());
439 template <
typename First,
typename Second,
typename P = pair<First, Second>,
440 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
442 return this->get<P>();
453 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
454 const First&
get(Second second)
const {
455 const First *r = try_get<First>(second);
456 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
457 "invalid get: entity does not have component (use try_get)");
469 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
470 const First&
get(Second constant)
const {
471 const auto& et = enum_type<Second>(this->world_);
472 flecs::entity_t target = et.entity(
constant);
473 return get<First>(target);
482 const void*
get(flecs::id_t comp)
const {
483 const void *r =
ecs_get_id(world_, id_, comp);
484 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
485 "invalid get: entity does not have component (use try_get)");
499 const void*
get(flecs::entity_t first, flecs::entity_t second)
const {
500 const void *r =
ecs_get_id(world_, id_, ecs_pair(first, second));
501 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
502 "invalid get: entity does not have component (use try_get)");
540 template <typename Func, if_t< is_callable<Func>::value > = 0>
541 bool get(
const Func& func)
const;
543 template<
typename... Ts>
545 flecs_static_assert(
sizeof...(Ts) > 1,
"get_n requires at least two components");
546 flecs_static_assert(
sizeof...(Ts) < 9,
"get_n cannot fetch more than eight components");
547 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_const {get<Ts>()...};
557 template<
typename Second>
559 const Second *r = try_get_second<Second>(first);
560 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
561 "invalid get: entity does not have component (use try_get)");
572 template<
typename First,
typename Second>
574 const Second *r = try_get<First, Second>();
575 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
576 "invalid get: entity does not have component (use try_get)");
589 template <typename T, if_t< is_actual<T>::value > = 0>
593 "operation invalid for empty type");
605 template <
typename T,
typename A = actual_type_t<T>,
606 if_t< flecs::is_pair<T>::value > = 0>
610 "operation invalid for empty type");
620 template <
typename First,
typename Second,
typename P = pair<First, Second>,
621 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
623 return this->try_get_mut<P>();
632 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
636 "operation invalid for empty type");
637 return static_cast<First*
>(
647 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
649 const auto& et = enum_type<Second>(this->world_);
650 flecs::entity_t target = et.entity(
constant);
651 return get_mut<First>(target);
672 void*
try_get_mut(flecs::entity_t first, flecs::entity_t second)
const {
676 template<
typename... Ts>
677 auto try_get_mut_n()
const {
678 flecs_static_assert(
sizeof...(Ts) > 1,
"try_get_mut_n requires at least two components");
679 flecs_static_assert(
sizeof...(Ts) < 9,
"try_get_mut_n cannot fetch more than eight components");
680 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_ptr {try_get_mut<Ts>()...};
690 template<
typename Second>
694 ECS_INVALID_PARAMETER,
"pair is not a component");
696 ECS_INVALID_PARAMETER,
"type of pair is not Second");
698 "operation invalid for empty type");
699 return static_cast<Second*
>(
710 template<
typename First,
typename Second>
712 return get_mut<pair_object<First, Second>>();
724 template <typename T, if_t< is_actual<T>::value > = 0>
726 T* r = try_get_mut<T>();
727 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
728 "invalid get_mut: entity does not have component (use try_get_mut)");
740 template <
typename T,
typename A = actual_type_t<T>,
741 if_t< flecs::is_pair<T>::value > = 0>
743 A* r = try_get_mut<T>();
744 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
745 "invalid get_mut: entity does not have component (use try_get_mut)");
755 template <
typename First,
typename Second,
typename P = pair<First, Second>,
756 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
758 A* r = try_get_mut<First, Second>();
759 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
760 "invalid get_mut: entity does not have component (use try_get_mut)");
770 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
772 First* r = try_get_mut<First>(second);
773 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
774 "invalid get_mut: entity does not have component (use try_get_mut)");
784 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
786 const auto& et = enum_type<Second>(this->world_);
787 flecs::entity_t target = et.entity(
constant);
788 return get_mut<First>(target);
799 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
800 "invalid get_mut: entity does not have component (use try_get_mut)");
812 void*
get_mut(flecs::entity_t first, flecs::entity_t second)
const {
814 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
815 "invalid get_mut: entity does not have component (use try_get_mut)");
819 template<
typename... Ts>
820 auto get_mut_n()
const {
821 flecs_static_assert(
sizeof...(Ts) > 1,
"get_mut_n requires at least two components");
822 flecs_static_assert(
sizeof...(Ts) < 9,
"get_mut_n cannot fetch more than eight components");
823 return typename tuple_builder<
sizeof...(Ts), Ts...>::type {get_mut<Ts>()...};
833 template<
typename Second>
835 Second *r = try_get_mut_second<Second>(first);
836 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
837 "invalid get_mut: entity does not have component (use try_get_mut)");
848 template<
typename First,
typename Second>
850 Second *r = try_get_mut_second<First, Second>();
851 ecs_assert(r !=
nullptr, ECS_INVALID_OPERATION,
852 "invalid get_mut: entity does not have component (use try_get_mut)");
857 template<
typename Enum>
858 Enum get_constant()
const;
868 template<
typename First>
879 flecs::entity target(flecs::entity_t first, int32_t index = 0)
const;
899 flecs::entity target_for(flecs::entity_t relationship, flecs::id_t
id)
const;
901 template <
typename T>
902 flecs::entity target_for(flecs::entity_t relationship)
const;
904 template <
typename First,
typename Second>
905 flecs::entity target_for(flecs::entity_t relationship)
const;
912 int32_t
depth(flecs::entity_t rel)
const {
921 template<
typename Rel>
941 flecs::entity lookup(
const char *path,
bool search_path =
false)
const;
948 bool has(flecs::id_t e)
const {
957 template <
typename T>
965 if (is_enum<T>::value) {
966 return ecs_has_pair(world_, id_, cid, flecs::Wildcard);
978 template <typename E, if_t< is_enum<E>::value > = 0>
981 auto o = enum_type<E>(world_).entity(value);
983 "Constant was not found in Enum reflection data."
984 " Did you mean to use has<E>() instead of has(E)?");
985 return ecs_has_pair(world_, id_, r, o);
994 template <
typename First,
typename Second>
1005 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
1006 bool has(Second second)
const {
1008 return ecs_has_id(world_, id_, ecs_pair(comp_id, second));
1017 template <
typename Second>
1028 template<typename First, typename E, if_t< is_enum<E>::value && !std::is_same<First, E>::value > = 0>
1030 const auto& et = enum_type<E>(this->world_);
1031 flecs::entity_t second = et.entity(value);
1032 return has<First>(second);
1041 bool has(flecs::id_t first, flecs::id_t second)
const {
1042 return ecs_has_id(world_, id_, ecs_pair(first, second));
1061 template <
typename First>
1062 bool owns(flecs::id_t second)
const {
1064 return owns(ecs_pair(comp_id, second));
1073 bool owns(flecs::id_t first, flecs::id_t second)
const {
1074 return owns(ecs_pair(first, second));
1083 template <
typename T>
1095 template <
typename First,
typename Second>
1108 template <
typename Second>
1127 template<
typename T>
1138 bool enabled(flecs::id_t first, flecs::id_t second)
const {
1139 return this->enabled(ecs_pair(first, second));
1148 template <
typename First>
1159 template <
typename First,
typename Second>
1164 flecs::entity clone(
bool clone_value =
true, flecs::entity_t dst_id = 0)
const;
component< T > & constant(const char *name, T value)
Add constant.
Utilities to fetch component as tuples from entities.
#define ecs_assert(condition, error_code,...)
Assert.
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.
bool ecs_children_next(ecs_iter_t *it)
Progress an iterator created with ecs_children().
ecs_iter_t ecs_children_w_rel(const ecs_world_t *world, ecs_entity_t relationship, ecs_entity_t parent)
Same as ecs_children() but with custom relationship argument.
bool ecs_is_enabled_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if component is enabled.
bool ecs_owns_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity owns a component.
int32_t ecs_get_depth(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel)
Return depth for entity in tree for the specified relationship.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity has a component.
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.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
char * ecs_get_path_w_sep(const ecs_world_t *world, ecs_entity_t parent, ecs_entity_t child, const char *sep, const char *prefix)
Get a path identifier for an entity.
const char * ecs_get_symbol(const ecs_world_t *world, ecs_entity_t entity)
Get the symbol of an entity.
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
Component added to enum type entities.
bool owns_second(flecs::entity_t first) const
Check if entity owns the provided pair.
flecs::type type() const
Get the entity's type.
entity_view(entity_t id)
Implicit conversion from flecs::entity_t to flecs::entity_view.
int32_t depth(flecs::entity_t rel) const
Get depth for given relationship.
bool enabled() const
Test if pair is enabled.
const Second * try_get_second(flecs::entity_t first) const
Get the second part for a pair.
bool has(flecs::id_t first, flecs::id_t second) const
Check if entity has the provided pair.
First & get_mut(Second constant) const
Get a mutable pair.
T & get_mut() const
Get mutable component value.
A & get_mut() const
Get mutable component value.
flecs::string_view name() const
Return the entity name.
bool owns(flecs::id_t second) const
Check if entity owns the provided pair.
const A * try_get() const
Get a pair.
bool is_valid() const
Check if entity is valid.
flecs::string path(const char *sep="::", const char *init_sep="::") const
Return the entity path.
const void * try_get(flecs::entity_t first, flecs::entity_t second) const
Get a pair (untyped).
flecs::string_view symbol() const
Return the entity symbol.
void each(const Func &func) const
Iterate targets for a given relationship.
A & get_mut() const
Get a mutable pair.
flecs::table_range range() const
Get table range for the entity.
void * get_mut(flecs::entity_t first, flecs::entity_t second) const
Get a mutable pair (untyped).
const Second & get_second(flecs::entity_t first) const
Get the second part for a pair.
const Second & get_second() const
Get the second part for a pair.
bool owns() const
Check if entity owns the provided pair.
const T & get() const
Get component value.
bool has(E value) const
Check if entity has the provided pair.
int32_t depth() const
Get depth for given relationship.
entity_view(flecs::world_t *world, flecs::id_t id)
Wrap an existing entity id.
bool enabled(flecs::id_t id) const
Test if id is enabled.
bool has_second(flecs::entity_t first) const
Check if entity has the provided pair.
const First * try_get(Second constant) const
Get a pair.
Second * try_get_mut_second(flecs::entity_t first) const
Get the second part for a pair.
const First & get(Second second) const
Get a pair.
void children(Func &&func) const
Iterate children for entity.
const void * try_get(flecs::id_t comp) const
Get component value (untyped).
bool owns(flecs::id_t e) const
Check if entity owns the provided entity.
Second & get_mut_second(flecs::entity_t first) const
Get the second part for a pair.
const First & get(Second constant) const
Get a pair.
flecs::table table() const
Get the entity's table.
flecs::string path_from(flecs::entity_t parent, const char *sep="::", const char *init_sep="::") const
Return the entity path relative to a parent.
Second * get_mut_second() const
Get the second part for a pair.
bool enabled(flecs::id_t second) const
Test if pair is enabled.
bool has(Second second) const
Check if entity has the provided pair.
A * try_get_mut() const
Get mutable component value.
bool has(flecs::id_t e) const
Check if entity has the provided entity.
bool owns() const
Check if entity owns the provided component.
flecs::entity parent() const
Get parent of entity.
const First * try_get(Second second) const
Get a pair.
void * get_mut(flecs::id_t comp) const
Get mutable component value (untyped).
A * try_get_mut() const
Get a mutable pair.
void each(const Func &func) const
Iterate (component) ids of an entity.
const void * get(flecs::entity_t first, flecs::entity_t second) const
Get a pair (untyped).
bool is_alive() const
Check if entity is alive.
const A & get() const
Get a pair.
bool has() const
Check if entity has the provided component.
T * try_get_mut() const
Get mutable component value.
bool owns(flecs::id_t first, flecs::id_t second) const
Check if entity owns the provided pair.
void * try_get_mut(flecs::id_t comp) const
Get mutable component value (untyped).
void children(Func &&func) const
Iterate children for entity.
const A & get() const
Get component value.
First & get_mut(Second second) const
Get a mutable pair.
Second * try_get_mut_second() const
Get the second part for a pair.
void * try_get_mut(flecs::entity_t first, flecs::entity_t second) const
Get a mutable pair (untyped).
First * try_get_mut(Second second) const
Get a mutable pair.
entity_t id() const
Get entity id.
flecs::entity target(int32_t index=0) const
Get target for a given pair.
const T * try_get() const
Get component value.
const void * get(flecs::id_t comp) const
Get component value (untyped).
bool has() const
Check if entity has the provided pair.
flecs::string path_from(const char *sep="::", const char *init_sep="::") const
Return the entity path relative to a parent.
First * try_get_mut(Second constant) const
Get a mutable pair.
bool enabled() const
Test if component is enabled.
const Second * try_get_second() const
Get the second part for a pair.
void children(flecs::entity_t rel, Func &&func) const
Iterate children for entity.
bool has(E value) const
Check if entity has the provided enum constant.
bool enabled(flecs::id_t first, flecs::id_t second) const
Test if pair is enabled.
const A * try_get() const
Get component value.
Class that wraps around a flecs::id_t.
flecs::entity second() const
Get second element from a pair.
flecs::entity first() const
Get first element from a pair.
Class for iterating over query results.