Flecs: include/flecs/addons/cpp/entity_view.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
entity_view.hpp
Go to the documentation of this file.
1
12
13#pragma once
14
15#include "entity_component_tuple.hpp"
16
19
20
21
22namespace flecs
23{
24
29 */
30 struct entity_view : public id {
31
33 entity_view() : flecs::id() { }
34
35 /** Wrap an existing entity ID.
36 *
37 * @param world The world in which the entity is created.
38 * @param id The entity ID.
39 */
40 explicit entity_view(flecs::world_t *world, flecs::id_t id)
41 : flecs::id(world
42 ? const_cast<flecs::world_t*>(ecs_get_world(world))
43 : nullptr
44 , id ) { }
45
46 /** Implicit conversion from flecs::entity_t to flecs::entity_view. */
47 entity_view(entity_t id)
48 : flecs::id( nullptr, id ) { }
49
53 entity_t id() const {
54 return id_;
55 }
56
61 * - the entity is alive (see is_alive())
62 *
63 * @return True if the entity is valid, false otherwise.
64 * @see ecs_is_valid()
65 */
66 bool is_valid() const {
67 return world_ && ecs_is_valid(world_, id_);
68 }
69
71 explicit operator bool() const {
72 return is_valid();
73 }
74
80 bool is_alive() const {
81 return world_ && ecs_is_alive(world_, id_);
82 }
83
84
88 flecs::string_view name() const {
89 return flecs::string_view(ecs_get_name(world_, id_));
90 }
91
94 * @return The entity symbol.
95 */
96 flecs::string_view symbol() const {
97 return flecs::string_view(ecs_get_symbol(world_, id_));
98 }
99
101
106 flecs::string path(const char *sep = "::", const char *init_sep = "::") const {
107 return path_from(0, sep, init_sep);
108 }
109
117 flecs::string path_from(flecs::entity_t parent, const char *sep = "::", const char *init_sep = "::") const {
118 char *path = ecs_get_path_w_sep(world_, parent, id_, sep, init_sep);
119 return flecs::string(path);
120 }
121
129 template <typename Parent>
130 flecs::string path_from(const char *sep = "::", const char *init_sep = "::") const {
131 return path_from(_::type<Parent>::id(world_), sep, init_sep);
132 }
133
138 bool enabled() const {
139 return !ecs_has_id(world_, id_, flecs::Disabled);
140 }
141
146 flecs::type type() const;
147
152 flecs::table table() const;
153
161 flecs::table_range range() const;
162
172 template <typename Func>
173 void each(const Func& func) const;
174
186 template <typename Func>
187 void each(flecs::id_t first, flecs::id_t second, const Func& func) const;
188
199 template <typename Func>
200 void each(const flecs::entity_view& rel, const Func& func) const;
201
212 template <typename First, typename Func>
213 void each(const Func& func) const {
214 return each(_::type<First>::id(world_), func);
215 }
216
227 template <typename Func>
228 void children(flecs::entity_t rel, Func&& func) const {
229 /* When the entity is a wildcard, this would attempt to query for all
230 * entities with (ChildOf, *) or (ChildOf, _) instead of querying for
231 * the children of the wildcard entity. */
232 if (id_ == flecs::Wildcard || id_ == flecs::Any) {
233 /* This is correct, wildcard entities don't have children. */
234 return;
235 }
236
237 flecs::world world(world_);
238
239 ecs_iter_t it = ecs_children_w_rel(world_, rel, id_);
240 while (ecs_children_next(&it)) {
241 _::each_delegate<Func>(FLECS_MOV(func)).invoke(&it);
242 }
243 }
244
255 template <typename Rel, typename Func>
256 void children(Func&& func) const {
257 children(_::type<Rel>::id(world_), FLECS_MOV(func));
258 }
259
271 template <typename Func>
272 void children(Func&& func) const {
273 children(flecs::ChildOf, FLECS_MOV(func));
274 }
275
276
277 /* try_get */
278
285 template <typename T, if_t< is_actual<T>::value > = 0>
286 const T* try_get() const {
287 auto comp_id = _::type<T>::id(world_);
288 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
289 "operation invalid for empty type");
290 return static_cast<const T*>(ecs_get_id(world_, id_, comp_id));
291 }
292
301 template <typename T, typename A = actual_type_t<T>,
302 if_t< flecs::is_pair<T>::value > = 0>
303 const A* try_get() const {
304 auto comp_id = _::type<T>::id(world_);
305 ecs_assert(_::type<A>::size() != 0, ECS_INVALID_PARAMETER,
306 "operation invalid for empty type");
307 return static_cast<const A*>(ecs_get_id(world_, id_, comp_id));
308 }
309
317 template <typename First, typename Second, typename P = pair<First, Second>,
318 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
319 const A* try_get() const {
320 return this->try_get<P>();
321 }
322
330 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
331 const First* try_get(Second second) const {
332 auto first = _::type<First>::id(world_);
333 ecs_assert(_::type<First>::size() != 0, ECS_INVALID_PARAMETER,
334 "operation invalid for empty type");
335 return static_cast<const First*>(
336 ecs_get_id(world_, id_, ecs_pair(first, second)));
337 }
338
346 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
347 const First* try_get(Second constant) const {
348 const auto& et = enum_type<Second>(this->world_);
349 flecs::entity_t target = et.entity(constant);
350 return try_get<First>(target);
351 }
352
359 const void* try_get(flecs::id_t comp) const {
360 return ecs_get_id(world_, id_, comp);
361 }
362
372 const void* try_get(flecs::entity_t first, flecs::entity_t second) const {
373 return ecs_get_id(world_, id_, ecs_pair(first, second));
374 }
375
381 template<typename... Ts>
382 auto try_get_n() const {
383 flecs_static_assert(sizeof...(Ts) > 1, "try_get_n requires at least two components");
384 flecs_static_assert(sizeof...(Ts) < 9, "try_get_n cannot fetch more than eight components");
385 return typename tuple_builder<sizeof...(Ts), Ts...>::type_const_ptr {try_get<Ts>()...};
386 }
387
396 template<typename Second>
397 const Second* try_get_second(flecs::entity_t first) const {
398 auto second = _::type<Second>::id(world_);
399 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
400 ECS_INVALID_PARAMETER, "pair is not a component");
401 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
402 ECS_INVALID_PARAMETER, "type of pair is not Second");
403 ecs_assert(_::type<Second>::size() != 0, ECS_INVALID_PARAMETER,
404 "operation invalid for empty type");
405 return static_cast<const Second*>(
406 ecs_get_id(world_, id_, ecs_pair(first, second)));
407 }
408
417 template<typename First, typename Second>
418 const Second* try_get_second() const {
419 return try_get<pair_object<First, Second>>();
420 }
421
422
423 /* get */
424
431 template <typename T, if_t< is_actual<T>::value > = 0>
432 const T& get() const {
433 const T *r = try_get<T>();
434 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
435 "invalid get: entity does not have component '%s' (use try_get)",
436 flecs::_::type_name<T>());
437 return *r;
438 }
439
448 template <typename T, typename A = actual_type_t<T>,
449 if_t< flecs::is_pair<T>::value > = 0>
450 const A& get() const {
451 const A *r = try_get<T>();
452 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
453 "invalid get: entity does not have component '%s' (use try_get)",
454 flecs::_::type_name<T>());
455 return *r;
456 }
457
466 template <typename First, typename Second, typename P = pair<First, Second>,
467 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
468 const A& get() const {
469 return this->get<P>();
470 }
471
480 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
481 const First& get(Second second) const {
482 const First *r = try_get<First>(second);
483 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
484 "invalid get: entity does not have pair (use try_get)");
485 return *r;
486 }
487
496 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
497 const First& get(Second constant) const {
498 const auto& et = enum_type<Second>(this->world_);
499 flecs::entity_t target = et.entity(constant);
500 return get<First>(target);
501 }
502
509 const void* get(flecs::id_t comp) const {
510 const void *r = ecs_get_id(world_, id_, comp);
511 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
512 "invalid get: entity does not have component (use try_get)");
513 return r;
514 }
515
526 const void* get(flecs::entity_t first, flecs::entity_t second) const {
527 const void *r = ecs_get_id(world_, id_, ecs_pair(first, second));
528 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
529 "invalid get: entity does not have pair (use try_get)");
530 return r;
531 }
532
567 template <typename Func, if_t< is_callable<Func>::value > = 0>
568 bool get(const Func& func) const;
569
575 template<typename... Ts>
576 auto get_n() const {
577 flecs_static_assert(sizeof...(Ts) > 1, "get_n requires at least two components");
578 flecs_static_assert(sizeof...(Ts) < 9, "get_n cannot fetch more than eight components");
579 return typename tuple_builder<sizeof...(Ts), Ts...>::type_const {get<Ts>()...};
580 }
581
591 template<typename Second>
592 const Second& get_second(flecs::entity_t first) const {
593 const Second *r = try_get_second<Second>(first);
594 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
595 "invalid get_second: entity does not have pair (use try_get_second)");
596 return *r;
597 }
598
608 template<typename First, typename Second>
609 const Second& get_second() const {
610 const Second *r = try_get<First, Second>();
611 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
612 "invalid get_second: entity does not have pair (use try_get_second)");
613 return *r;
614 }
615
616
617 /* try_get_mut */
618
625 template <typename T, if_t< is_actual<T>::value > = 0>
626 T* try_get_mut() const {
627 auto comp_id = _::type<T>::id(world_);
628 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
629 "operation invalid for empty type");
630 return static_cast<T*>(ecs_get_mut_id(world_, id_, comp_id));
631 }
632
641 template <typename T, typename A = actual_type_t<T>,
642 if_t< flecs::is_pair<T>::value > = 0>
643 A* try_get_mut() const {
644 auto comp_id = _::type<T>::id(world_);
645 ecs_assert(_::type<A>::size() != 0, ECS_INVALID_PARAMETER,
646 "operation invalid for empty type");
647 return static_cast<A*>(ecs_get_mut_id(world_, id_, comp_id));
648 }
649
657 template <typename First, typename Second, typename P = pair<First, Second>,
658 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
659 A* try_get_mut() const {
660 return this->try_get_mut<P>();
661 }
662
670 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
671 First* try_get_mut(Second second) const {
672 auto first = _::type<First>::id(world_);
673 ecs_assert(_::type<First>::size() != 0, ECS_INVALID_PARAMETER,
674 "operation invalid for empty type");
675 return static_cast<First*>(
676 ecs_get_mut_id(world_, id_, ecs_pair(first, second)));
677 }
678
686 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
687 First* try_get_mut(Second constant) const {
688 const auto& et = enum_type<Second>(this->world_);
689 flecs::entity_t target = et.entity(constant);
690 return try_get_mut<First>(target);
691 }
692
699 void* try_get_mut(flecs::id_t comp) const {
700 return ecs_get_mut_id(world_, id_, comp);
701 }
702
712 void* try_get_mut(flecs::entity_t first, flecs::entity_t second) const {
713 return ecs_get_mut_id(world_, id_, ecs_pair(first, second));
714 }
715
721 template<typename... Ts>
722 auto try_get_mut_n() const {
723 flecs_static_assert(sizeof...(Ts) > 1, "try_get_mut_n requires at least two components");
724 flecs_static_assert(sizeof...(Ts) < 9, "try_get_mut_n cannot fetch more than eight components");
725 return typename tuple_builder<sizeof...(Ts), Ts...>::type_ptr {try_get_mut<Ts>()...};
726 }
727
736 template<typename Second>
737 Second* try_get_mut_second(flecs::entity_t first) const {
738 auto second = _::type<Second>::id(world_);
739 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
740 ECS_INVALID_PARAMETER, "pair is not a component");
741 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
742 ECS_INVALID_PARAMETER, "type of pair is not Second");
743 ecs_assert(_::type<Second>::size() != 0, ECS_INVALID_PARAMETER,
744 "operation invalid for empty type");
745 return static_cast<Second*>(
746 ecs_get_mut_id(world_, id_, ecs_pair(first, second)));
747 }
748
757 template<typename First, typename Second>
758 Second* try_get_mut_second() const {
759 return try_get_mut<pair_object<First, Second>>();
760 }
761
762
763 /* get_mut */
764
771 template <typename T, if_t< is_actual<T>::value > = 0>
772 T& get_mut() const {
773 T* r = try_get_mut<T>();
774 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
775 "invalid get_mut: entity does not have component (use try_get_mut)");
776 return *r;
777 }
778
787 template <typename T, typename A = actual_type_t<T>,
788 if_t< flecs::is_pair<T>::value > = 0>
789 A& get_mut() const {
790 A* r = try_get_mut<T>();
791 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
792 "invalid get_mut: entity does not have component (use try_get_mut)");
793 return *r;
794 }
795
804 template <typename First, typename Second, typename P = pair<First, Second>,
805 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
806 A& get_mut() const {
807 A* r = try_get_mut<First, Second>();
808 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
809 "invalid get_mut: entity does not have pair (use try_get_mut)");
810 return *r;
811 }
812
821 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
822 First& get_mut(Second second) const {
823 First* r = try_get_mut<First>(second);
824 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
825 "invalid get_mut: entity does not have pair (use try_get_mut)");
826 return *r;
827 }
828
837 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
838 First& get_mut(Second constant) const {
839 const auto& et = enum_type<Second>(this->world_);
840 flecs::entity_t target = et.entity(constant);
841 return get_mut<First>(target);
842 }
843
850 void* get_mut(flecs::id_t comp) const {
851 void *r = ecs_get_mut_id(world_, id_, comp);
852 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
853 "invalid get_mut: entity does not have component (use try_get_mut)");
854 return r;
855 }
856
867 void* get_mut(flecs::entity_t first, flecs::entity_t second) const {
868 void *r = ecs_get_mut_id(world_, id_, ecs_pair(first, second));
869 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
870 "invalid get_mut: entity does not have pair (use try_get_mut)");
871 return r;
872 }
873
879 template<typename... Ts>
880 auto get_mut_n() const {
881 flecs_static_assert(sizeof...(Ts) > 1, "get_mut_n requires at least two components");
882 flecs_static_assert(sizeof...(Ts) < 9, "get_mut_n cannot fetch more than eight components");
883 return typename tuple_builder<sizeof...(Ts), Ts...>::type {get_mut<Ts>()...};
884 }
885
895 template<typename Second>
896 Second& get_mut_second(flecs::entity_t first) const {
897 Second *r = try_get_mut_second<Second>(first);
898 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
899 "invalid get_mut_second: entity does not have pair (use try_get_mut_second)");
900 return *r;
901 }
902
912 template<typename First, typename Second>
913 Second& get_mut_second() const {
914 Second *r = try_get_mut_second<First, Second>();
915 ecs_assert(r != nullptr, ECS_INVALID_OPERATION,
916 "invalid get_mut_second: entity does not have pair (use try_get_mut_second)");
917 return *r;
918 }
919
925 template<typename Enum>
926 Enum get_constant() const;
927
937 template<typename First>
938 flecs::entity target(int32_t index = 0) const;
939
949 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
950
970 flecs::entity target_for(flecs::entity_t relationship, flecs::id_t id) const;
971
978 template <typename T>
979 flecs::entity target_for(flecs::entity_t relationship) const;
980
988 template <typename First, typename Second>
989 flecs::entity target_for(flecs::entity_t relationship) const;
990
996 int32_t depth(flecs::entity_t rel) const {
997 return ecs_get_depth(world_, id_, rel);
998 }
999
1005 template<typename Rel>
1006 int32_t depth() const {
1007 return this->depth(_::type<Rel>::id(world_));
1008 }
1009
1015 flecs::entity parent() const;
1016
1025 flecs::entity lookup(const char *path, bool search_path = false) const;
1026
1032 bool has(flecs::id_t e) const {
1033 return ecs_has_id(world_, id_, e);
1034 }
1035
1041 template <typename T>
1042 bool has() const {
1043 flecs::id_t cid = _::type<T>::id(world_);
1044 bool result = ecs_has_id(world_, id_, cid);
1045 if (result) {
1046 return result;
1047 }
1048
1049 if (is_enum<T>::value) {
1050 return ecs_has_pair(world_, id_, cid, flecs::Wildcard);
1051 }
1052
1053 return false;
1054 }
1055
1062 template <typename E, if_t< is_enum<E>::value > = 0>
1063 bool has(E value) const {
1064 auto r = _::type<E>::id(world_);
1065 auto o = enum_type<E>(world_).entity(value);
1066 ecs_assert(o, ECS_INVALID_PARAMETER,
1067 "Constant was not found in Enum reflection data."
1068 " Did you mean to use has<E>() instead of has(E)?");
1069 return ecs_has_pair(world_, id_, r, o);
1070 }
1071
1078 template <typename First, typename Second>
1079 bool has() const {
1080 return this->has<First>(_::type<Second>::id(world_));
1081 }
1082
1089 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
1090 bool has(Second second) const {
1091 auto comp_id = _::type<First>::id(world_);
1092 return ecs_has_id(world_, id_, ecs_pair(comp_id, second));
1093 }
1094
1101 template <typename Second>
1102 bool has_second(flecs::entity_t first) const {
1103 return this->has(first, _::type<Second>::id(world_));
1104 }
1105
1112 template<typename First, typename E, if_t< is_enum<E>::value && !std::is_same<First, E>::value > = 0>
1113 bool has(E value) const {
1114 const auto& et = enum_type<E>(this->world_);
1115 flecs::entity_t second = et.entity(value);
1116 return has<First>(second);
1117 }
1118
1125 bool has(flecs::id_t first, flecs::id_t second) const {
1126 return ecs_has_id(world_, id_, ecs_pair(first, second));
1127 }
1128
1135 bool owns(flecs::id_t e) const {
1136 return ecs_owns_id(world_, id_, e);
1137 }
1138
1145 template <typename First>
1146 bool owns(flecs::id_t second) const {
1147 auto comp_id = _::type<First>::id(world_);
1148 return owns(ecs_pair(comp_id, second));
1149 }
1150
1157 bool owns(flecs::id_t first, flecs::id_t second) const {
1158 return owns(ecs_pair(first, second));
1159 }
1160
1167 template <typename T>
1168 bool owns() const {
1169 return owns(_::type<T>::id(world_));
1170 }
1171
1179 template <typename First, typename Second>
1180 bool owns() const {
1181 return owns(
1182 _::type<First>::id(world_),
1183 _::type<Second>::id(world_));
1184 }
1185
1192 template <typename Second>
1193 bool owns_second(flecs::entity_t first) const {
1194 return owns(first, _::type<Second>::id(world_));
1195 }
1196
1202 bool enabled(flecs::id_t id) const {
1203 return ecs_is_enabled_id(world_, id_, id);
1204 }
1205
1211 template<typename T>
1212 bool enabled() const {
1213 return this->enabled(_::type<T>::id(world_));
1214 }
1215
1222 bool enabled(flecs::id_t first, flecs::id_t second) const {
1223 return this->enabled(ecs_pair(first, second));
1224 }
1225
1232 template <typename First>
1233 bool enabled(flecs::id_t second) const {
1234 return this->enabled(_::type<First>::id(world_), second);
1235 }
1236
1243 template <typename First, typename Second>
1244 bool enabled() const {
1245 return this->enabled<First>(_::type<Second>::id(world_));
1246 }
1247
1255 flecs::entity clone(bool clone_value = true, flecs::entity_t dst_id = 0) const;
1256
1276 flecs::entity mut(const flecs::world& stage) const;
1277
1285 flecs::entity mut(const flecs::iter& it) const;
1286
1295 flecs::entity mut(const flecs::entity_view& e) const;
1296
1297# ifdef FLECS_JSON
1298# include "mixins/json/entity_view.inl"
1299# endif
1300# ifdef FLECS_DOC
1301# include "mixins/doc/entity_view.inl"
1302# endif
1303# ifdef FLECS_ALERTS
1304# include "mixins/alerts/entity_view.inl"
1305# endif
1306
1307# include "mixins/enum/entity_view.inl"
1308# include "mixins/event/entity_view.inl"
1309
1310private:
1311 flecs::entity set_stage(world_t *stage);
1312};
1313
1314}
1315
entity_view.inl
Alerts entity mixin.
entity_view.inl
Doc entity view mixin.
entity_component_tuple.hpp
Utilities to fetch components as tuples from entities.
entity_view.inl
Enum entity view mixin.
entity_view.inl
Event entity mixin.
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
ECS_INVALID_OPERATION
#define ECS_INVALID_OPERATION
Invalid operation error code.
Definition log.h:659
ECS_INVALID_PARAMETER
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:661
ecs_get_type_info
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.
flecs::component::constant
untyped_component & constant(const char *name, T value)
Add a constant.
Definition untyped_component.inl:186
flecs::id_t
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
ecs_children_next
bool ecs_children_next(ecs_iter_t *it)
Progress an iterator created with ecs_children().
ecs_children_w_rel
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 a custom relationship argument.
ecs_is_enabled_id
bool ecs_is_enabled_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if a component is enabled.
ecs_owns_id
bool ecs_owns_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity owns a component.
ecs_get_depth
int32_t ecs_get_depth(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel)
Return the depth for an entity in the tree for the specified relationship.
ecs_has_id
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity has a component.
ecs_has_pair
#define ecs_has_pair(world, entity, first, second)
Test if an entity has a pair.
Definition flecs_c.h:534
ecs_get_id
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.
ecs_get_mut_id
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.
ecs_is_valid
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
ecs_is_alive
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
ecs_get_path_w_sep
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.
ecs_get_symbol
const char * ecs_get_symbol(const ecs_world_t *world, ecs_entity_t entity)
Get the symbol of an entity.
ecs_get_name
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
ecs_get_world
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get the world from a poly.
entity_view.inl
JSON entity mixin.
ecs_iter_t
Iterator.
Definition flecs.h:1166
flecs::_::each_delegate
Definition delegate.hpp:220
flecs::_::type
Definition flecs.hpp:39
flecs::component
Component class.
Definition component.hpp:394
flecs::entity_view
Entity view.
Definition entity_view.hpp:30
flecs::entity_view::owns_second
bool owns_second(flecs::entity_t first) const
Check if entity owns the provided pair.
Definition entity_view.hpp:1193
flecs::entity_view::type
flecs::type type() const
Get the entity's type.
Definition impl.hpp:94
flecs::entity_view::try_get_n
auto try_get_n() const
Get multiple component values as a tuple of const pointers.
Definition entity_view.hpp:382
flecs::entity_view::entity_view
entity_view(entity_t id)
Implicit conversion from flecs::entity_t to flecs::entity_view.
Definition entity_view.hpp:47
flecs::entity_view::depth
int32_t depth(flecs::entity_t rel) const
Get the depth for a given relationship.
Definition entity_view.hpp:996
flecs::entity_view::enabled
bool enabled() const
Test if pair is enabled.
Definition entity_view.hpp:1244
flecs::entity_view::try_get_second
const Second * try_get_second(flecs::entity_t first) const
Get the second part for a pair.
Definition entity_view.hpp:397
flecs::entity_view::has
bool has(flecs::id_t first, flecs::id_t second) const
Check if entity has the provided pair.
Definition entity_view.hpp:1125
flecs::entity_view::get_mut
First & get_mut(Second constant) const
Get a mutable pair.
Definition entity_view.hpp:838
flecs::entity_view::get_mut
T & get_mut() const
Get mutable component value.
Definition entity_view.hpp:772
flecs::entity_view::get_mut
A & get_mut() const
Get mutable component value.
Definition entity_view.hpp:789
flecs::entity_view::name
flecs::string_view name() const
Return the entity name.
Definition entity_view.hpp:88
flecs::entity_view::owns
bool owns(flecs::id_t second) const
Check if entity owns the provided pair.
Definition entity_view.hpp:1146
flecs::entity_view::try_get
const A * try_get() const
Get a pair.
Definition entity_view.hpp:319
flecs::entity_view::is_valid
bool is_valid() const
Check if entity is valid.
Definition entity_view.hpp:66
flecs::entity_view::path
flecs::string path(const char *sep="::", const char *init_sep="::") const
Return the entity path.
Definition entity_view.hpp:106
flecs::entity_view::try_get
const void * try_get(flecs::entity_t first, flecs::entity_t second) const
Get a pair (untyped).
Definition entity_view.hpp:372
flecs::entity_view::symbol
flecs::string_view symbol() const
Return the entity symbol.
Definition entity_view.hpp:96
flecs::entity_view::each
void each(const Func &func) const
Iterate targets for a given relationship.
Definition entity_view.hpp:213
flecs::entity_view::get_mut
A & get_mut() const
Get a mutable pair.
Definition entity_view.hpp:806
flecs::entity_view::range
flecs::table_range range() const
Get table range for the entity.
Definition impl.hpp:102
flecs::entity_view::get_mut
void * get_mut(flecs::entity_t first, flecs::entity_t second) const
Get a mutable pair (untyped).
Definition entity_view.hpp:867
flecs::entity_view::get_second
const Second & get_second(flecs::entity_t first) const
Get the second part for a pair.
Definition entity_view.hpp:592
flecs::entity_view::get_second
const Second & get_second() const
Get the second part for a pair.
Definition entity_view.hpp:609
flecs::entity_view::owns
bool owns() const
Check if entity owns the provided pair.
Definition entity_view.hpp:1180
flecs::entity_view::get
const T & get() const
Get component value.
Definition entity_view.hpp:432
flecs::entity_view::has
bool has(E value) const
Check if entity has the provided pair.
Definition entity_view.hpp:1113
flecs::entity_view::depth
int32_t depth() const
Get the depth for a given relationship.
Definition entity_view.hpp:1006
flecs::entity_view::entity_view
entity_view(flecs::world_t *world, flecs::id_t id)
Wrap an existing entity ID.
Definition entity_view.hpp:40
flecs::entity_view::enabled
bool enabled(flecs::id_t id) const
Test if ID is enabled.
Definition entity_view.hpp:1202
flecs::entity_view::has_second
bool has_second(flecs::entity_t first) const
Check if entity has the provided pair.
Definition entity_view.hpp:1102
flecs::entity_view::try_get
const First * try_get(Second constant) const
Get a pair.
Definition entity_view.hpp:347
flecs::entity_view::get_mut_second
Second & get_mut_second() const
Get the second part for a pair.
Definition entity_view.hpp:913
flecs::entity_view::try_get_mut_second
Second * try_get_mut_second(flecs::entity_t first) const
Get the second part for a pair.
Definition entity_view.hpp:737
flecs::entity_view::get
const First & get(Second second) const
Get a pair.
Definition entity_view.hpp:481
flecs::entity_view::children
void children(Func &&func) const
Iterate children for an entity.
Definition entity_view.hpp:256
flecs::entity_view::try_get
const void * try_get(flecs::id_t comp) const
Get component value (untyped).
Definition entity_view.hpp:359
flecs::entity_view::owns
bool owns(flecs::id_t e) const
Check if entity owns the provided entity.
Definition entity_view.hpp:1135
flecs::entity_view::get_mut_second
Second & get_mut_second(flecs::entity_t first) const
Get the second part for a pair.
Definition entity_view.hpp:896
flecs::entity_view::get
const First & get(Second constant) const
Get a pair.
Definition entity_view.hpp:497
flecs::entity_view::table
flecs::table table() const
Get the entity's table.
Definition impl.hpp:98
flecs::entity_view::path_from
flecs::string path_from(flecs::entity_t parent, const char *sep="::", const char *init_sep="::") const
Return the entity path relative to a parent.
Definition entity_view.hpp:117
flecs::entity_view::enabled
bool enabled(flecs::id_t second) const
Test if pair is enabled.
Definition entity_view.hpp:1233
flecs::entity_view::has
bool has(Second second) const
Check if entity has the provided pair.
Definition entity_view.hpp:1090
flecs::entity_view::try_get_mut
A * try_get_mut() const
Get mutable component value.
Definition entity_view.hpp:643
flecs::entity_view::has
bool has(flecs::id_t e) const
Check if entity has the provided entity.
Definition entity_view.hpp:1032
flecs::entity_view::owns
bool owns() const
Check if entity owns the provided component.
Definition entity_view.hpp:1168
flecs::entity_view::enabled
bool enabled() const
Check if entity is enabled (does not have the Disabled tag).
Definition entity_view.hpp:138
flecs::entity_view::parent
flecs::entity parent() const
Get parent of entity.
Definition impl.hpp:68
flecs::entity_view::entity_view
entity_view()
Default constructor.
Definition entity_view.hpp:33
flecs::entity_view::try_get
const First * try_get(Second second) const
Get a pair.
Definition entity_view.hpp:331
flecs::entity_view::get_mut
void * get_mut(flecs::id_t comp) const
Get mutable component value (untyped).
Definition entity_view.hpp:850
flecs::entity_view::try_get_mut
A * try_get_mut() const
Get a mutable pair.
Definition entity_view.hpp:659
flecs::entity_view::each
void each(const Func &func) const
Iterate (component) IDs of an entity.
Definition impl.hpp:112
flecs::entity_view::get
const void * get(flecs::entity_t first, flecs::entity_t second) const
Get a pair (untyped).
Definition entity_view.hpp:526
flecs::entity_view::is_alive
bool is_alive() const
Check if entity is alive.
Definition entity_view.hpp:80
flecs::entity_view::get
const A & get() const
Get a pair.
Definition entity_view.hpp:468
flecs::entity_view::has
bool has() const
Check if entity has the provided component.
Definition entity_view.hpp:1042
flecs::entity_view::try_get_mut
T * try_get_mut() const
Get mutable component value.
Definition entity_view.hpp:626
flecs::entity_view::owns
bool owns(flecs::id_t first, flecs::id_t second) const
Check if entity owns the provided pair.
Definition entity_view.hpp:1157
flecs::entity_view::try_get_mut
void * try_get_mut(flecs::id_t comp) const
Get mutable component value (untyped).
Definition entity_view.hpp:699
flecs::entity_view::children
void children(Func &&func) const
Iterate children for an entity.
Definition entity_view.hpp:272
flecs::entity_view::get
const A & get() const
Get component value.
Definition entity_view.hpp:450
flecs::entity_view::get_n
auto get_n() const
Get multiple component values as a tuple of const references.
Definition entity_view.hpp:576
flecs::entity_view::get_mut
First & get_mut(Second second) const
Get a mutable pair.
Definition entity_view.hpp:822
flecs::entity_view::try_get_mut_second
Second * try_get_mut_second() const
Get the second part for a pair.
Definition entity_view.hpp:758
flecs::entity_view::try_get_mut
void * try_get_mut(flecs::entity_t first, flecs::entity_t second) const
Get a mutable pair (untyped).
Definition entity_view.hpp:712
flecs::entity_view::try_get_mut
First * try_get_mut(Second second) const
Get a mutable pair.
Definition entity_view.hpp:671
flecs::entity_view::id
entity_t id() const
Get entity ID.
Definition entity_view.hpp:53
flecs::entity_view::target
flecs::entity target(int32_t index=0) const
Get target for a given pair.
Definition impl.hpp:36
flecs::entity_view::try_get
const T * try_get() const
Get component value.
Definition entity_view.hpp:286
flecs::entity_view::get
const void * get(flecs::id_t comp) const
Get component value (untyped).
Definition entity_view.hpp:509
flecs::entity_view::has
bool has() const
Check if entity has the provided pair.
Definition entity_view.hpp:1079
flecs::entity_view::path_from
flecs::string path_from(const char *sep="::", const char *init_sep="::") const
Return the entity path relative to a typed parent.
Definition entity_view.hpp:130
flecs::entity_view::try_get_mut
First * try_get_mut(Second constant) const
Get a mutable pair.
Definition entity_view.hpp:687
flecs::entity_view::try_get_mut_n
auto try_get_mut_n() const
Get multiple mutable component values as a tuple of pointers.
Definition entity_view.hpp:722
flecs::entity_view::enabled
bool enabled() const
Test if component is enabled.
Definition entity_view.hpp:1212
flecs::entity_view::try_get_second
const Second * try_get_second() const
Get the second part for a pair.
Definition entity_view.hpp:418
flecs::entity_view::children
void children(flecs::entity_t rel, Func &&func) const
Iterate children for an entity.
Definition entity_view.hpp:228
flecs::entity_view::get_mut_n
auto get_mut_n() const
Get multiple mutable component values as a tuple of references.
Definition entity_view.hpp:880
flecs::entity_view::has
bool has(E value) const
Check if entity has the provided enum constant.
Definition entity_view.hpp:1063
flecs::entity_view::enabled
bool enabled(flecs::id_t first, flecs::id_t second) const
Test if pair is enabled.
Definition entity_view.hpp:1222
flecs::entity_view::try_get
const A * try_get() const
Get component value.
Definition entity_view.hpp:303
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id::world
flecs::world world() const
Get the world.
Definition impl.hpp:58
flecs::id::id_
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
flecs::id::second
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
flecs::id::world_
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Definition decl.hpp:147
flecs::id::first
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
flecs::iter
Class for iterating over query results.
Definition iter.hpp:68
flecs::string_view
Non-owning string view.
Definition string.hpp:169
flecs::string
Owned string wrapper.
Definition string.hpp:15
flecs::table_range
Table range.
Definition table.hpp:449
flecs::table
Table.
Definition table.hpp:23
flecs::tuple_builder
Builds tuple types for a given number of component types.
Definition entity_component_tuple.hpp:22
flecs::type
Type class.
Definition type.hpp:21
flecs::world
The world.
Definition world.hpp:246