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

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

Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8namespace flecs
9{
10
12 * @ingroup cpp_entities
13 */
14template <typename Self>
15 struct entity_builder : entity_view {
16
17 using entity_view::entity_view;
18
21
24 template <typename T>
25 const Self& add() const {
26 flecs_static_assert(is_flecs_constructible<T>::value,
27 "cannot default construct type: add T::T() or use emplace<T>()");
28 ecs_add_id(this->world_, this->id_, _::type<T>::id(this->world_));
29 return to_base();
30 }
31
32 /** Add pair for enum constant.
33 * This operation will add a pair to the entity where the first element is
34 * the enumeration type, and the second element the enumeration constant.
35 *
36 * The operation may be used with regular (C style) enumerations as well as
37 * enum classes.
38 *
39 * @param value The enumeration value.
40 */
41 template <typename E, if_t< is_enum<E>::value > = 0>
42 const Self& add(E value) const {
43 flecs::entity_t first = _::type<E>::id(this->world_);
44 const auto& et = enum_type<E>(this->world_);
45 flecs::entity_t second = et.entity(value);
46
47 ecs_assert(second, ECS_INVALID_PARAMETER, "Component was not found in reflection data.");
48 return this->add(first, second);
49 }
50
51
53 *
54 * @param component The component to add.
55 */
56 const Self& add(id_t component) const {
57 ecs_add_id(this->world_, this->id_, component);
58 return to_base();
59 }
60
62 * This operation adds a pair to the entity.
63 *
64 * @param first The first element of the pair.
65 * @param second The second element of the pair.
66 */
67 const Self& add(entity_t first, entity_t second) const {
68 ecs_add_pair(this->world_, this->id_, first, second);
69 return to_base();
70 }
71
73 * This operation adds a pair to the entity.
74 *
75 * @tparam First The first element of the pair
76 * @tparam Second The second element of the pair
77 */
78 template<typename First, typename Second>
79 const Self& add() const {
80 return this->add<First>(_::type<Second>::id(this->world_));
81 }
82
83
85 *
86 * @tparam First The first element of the pair
87 * @param second The second element of the pair.
88 */
89 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
90 const Self& add(Second second) const {
91 flecs_static_assert(is_flecs_constructible<First>::value,
92 "cannot default construct type: add T::T() or use emplace<T>()");
93 return this->add(_::type<First>::id(this->world_), second);
94 }
95
96
98 * combined with an enum constant.
99 *
100 * @tparam First The first element of the pair
101 * @param constant the enum constant.
102 */
103 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
104 const Self& add(Second constant) const {
105 flecs_static_assert(is_flecs_constructible<First>::value,
106 "cannot default construct type: add T::T() or use emplace<T>()");
107 const auto& et = enum_type<Second>(this->world_);
108 return this->add<First>(et.entity(constant));
109 }
110
117 template<typename Second>
118 const Self& add_second(flecs::entity_t first) const {
119 return this->add(first, _::type<Second>::id(this->world_));
120 }
121
128 const Self& add_if(bool cond, flecs::id_t component) const {
129 if (cond) {
130 return this->add(component);
131 } else {
132 return this->remove(component);
133 }
134 }
135
142 template <typename T>
143 const Self& add_if(bool cond) const {
144 if (cond) {
145 return this->add<T>();
146 } else {
147 return this->remove<T>();
148 }
149 }
150
158 const Self& add_if(bool cond, flecs::entity_t first, flecs::entity_t second) const {
159 if (cond) {
160 return this->add(first, second);
161 } else {
162 /* If second is 0 or if relationship is exclusive, use wildcard for
163 * second which will remove all instances of the relationship.
164 * Replacing 0 with Wildcard will make it possible to use the second
165 * as the condition. */
166 if (!second || ecs_has_id(this->world_, first, flecs::Exclusive)) {
167 second = flecs::Wildcard;
168 }
169 return this->remove(first, second);
170 }
171 }
172
180 template <typename First>
181 const Self& add_if(bool cond, flecs::entity_t second) const {
182 return this->add_if(cond, _::type<First>::id(this->world_), second);
183 }
184
192 template <typename First, typename Second>
193 const Self& add_if(bool cond) const {
194 return this->add_if<First>(cond, _::type<Second>::id(this->world_));
195 }
196
203 template <typename E, if_t< is_enum<E>::value > = 0>
204 const Self& add_if(bool cond, E constant) const {
205 const auto& et = enum_type<E>(this->world_);
206 return this->add_if<E>(cond, et.entity(constant));
207 }
208
213 const Self& is_a(entity_t second) const {
214 return this->add(flecs::IsA, second);
215 }
216
221 template <typename T>
222 const Self& is_a() const {
223 return this->add(flecs::IsA, _::type<T>::id(this->world_));
224 }
225
230 const Self& child_of(entity_t second) const {
231 return this->add(flecs::ChildOf, second);
232 }
233
238 const Self& depends_on(entity_t second) const {
239 return this->add(flecs::DependsOn, second);
240 }
241
246 template <typename E, if_t<is_enum<E>::value> = 0>
247 const Self& depends_on(E second) const {
248 const auto& et = enum_type<E>(this->world_);
249 flecs::entity_t target = et.entity(second);
250 return depends_on(target);
251 }
252
257 const Self& slot_of(entity_t second) const {
258 return this->add(flecs::SlotOf, second);
259 }
260
263 const Self& slot() const {
264 ecs_check(ecs_get_target(world_, id_, flecs::ChildOf, 0),
265 ECS_INVALID_PARAMETER, "add ChildOf pair before using slot()");
266 return this->slot_of(this->target(flecs::ChildOf));
267 error:
268 return to_base();
269 }
270
275 template <typename T>
276 const Self& child_of() const {
277 return this->child_of(_::type<T>::id(this->world_));
278 }
279
284 template <typename T>
285 const Self& depends_on() const {
286 return this->depends_on(_::type<T>::id(this->world_));
287 }
288
293 template <typename T>
294 const Self& slot_of() const {
295 return this->slot_of(_::type<T>::id(this->world_));
296 }
297
302 template <typename T>
303 const Self& remove() const {
304 ecs_remove_id(this->world_, this->id_, _::type<T>::id(this->world_));
305 return to_base();
306 }
307
312 const Self& remove(entity_t entity) const {
313 ecs_remove_id(this->world_, this->id_, entity);
314 return to_base();
315 }
316
323 const Self& remove(entity_t first, entity_t second) const {
324 ecs_remove_pair(this->world_, this->id_, first, second);
325 return to_base();
326 }
327
334 template<typename First, typename Second>
335 const Self& remove() const {
336 return this->remove<First>(_::type<Second>::id(this->world_));
337 }
338
345 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
346 const Self& remove(Second second) const {
347 return this->remove(_::type<First>::id(this->world_), second);
348 }
349
356 template<typename Second>
357 const Self& remove_second(flecs::entity_t first) const {
358 return this->remove(first, _::type<Second>::id(this->world_));
359 }
360
367 template<typename First, typename Second, if_t< is_enum<Second>::value > = 0>
368 const Self& remove(Second constant) const {
369 const auto& et = enum_type<Second>(this->world_);
370 flecs::entity_t second = et.entity(constant);
371 return this->remove<First>(second);
372 }
373
381 const Self& auto_override(flecs::id_t id) const {
382 return this->add(ECS_AUTO_OVERRIDE | id);
383 }
384
391 const Self& auto_override(flecs::entity_t first, flecs::entity_t second) const {
392 return this->auto_override(ecs_pair(first, second));
393 }
394
400 template <typename T>
401 const Self& auto_override() const {
402 return this->auto_override(_::type<T>::id(this->world_));
403 }
404
411 template <typename First>
412 const Self& auto_override(flecs::entity_t second) const {
413 return this->auto_override(_::type<First>::id(this->world_), second);
414 }
415
422 template <typename First, typename Second>
423 const Self& auto_override() const {
424 return this->auto_override<First>(_::type<Second>::id(this->world_));
425 }
426
433 template <typename T>
434 const Self& set_auto_override(const T& val) const {
435 this->auto_override<T>();
436 return this->set<T>(val);
437 }
438
445 template <typename T>
446 const Self& set_auto_override(T&& val) const {
447 this->auto_override<T>();
448 return this->set<T>(FLECS_FWD(val));
449 }
450
458 template <typename First>
459 const Self& set_auto_override(flecs::entity_t second, const First& val) const {
460 this->auto_override<First>(second);
461 return this->set<First>(second, val);
462 }
463
471 template <typename First>
472 const Self& set_auto_override(flecs::entity_t second, First&& val) const {
473 this->auto_override<First>(second);
474 return this->set<First>(second, FLECS_FWD(val));
475 }
476
484 template <typename First, typename Second, typename P = pair<First, Second>,
485 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
486 const Self& set_auto_override(const A& val) const {
487 this->auto_override<First, Second>();
488 return this->set<First, Second>(val);
489 }
490
498 template <typename First, typename Second, typename P = pair<First, Second>,
499 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
500 const Self& set_auto_override(A&& val) const {
501 this->auto_override<First, Second>();
502 return this->set<First, Second>(FLECS_FWD(val));
503 }
504
511 template <typename T, typename ... Args>
512 const Self& emplace_auto_override(Args&&... args) const {
513 this->auto_override<T>();
514
515 flecs::emplace<T>(this->world_, this->id_,
516 _::type<T>::id(this->world_), FLECS_FWD(args)...);
517
518 return to_base();
519 }
520
528 template <typename First, typename Second, typename P = pair<First, Second>,
529 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0,
530 typename ... Args>
531 const Self& emplace_auto_override(Args&&... args) const {
532 this->auto_override<First, Second>();
533
534 flecs::emplace<A>(this->world_, this->id_,
535 ecs_pair(_::type<First>::id(this->world_),
536 _::type<Second>::id(this->world_)),
537 FLECS_FWD(args)...);
538
539 return to_base();
540 }
541
546 const Self& enable() const {
547 ecs_enable(this->world_, this->id_, true);
548 return to_base();
549 }
550
555 const Self& disable() const {
556 ecs_enable(this->world_, this->id_, false);
557 return to_base();
558 }
559
569 const Self& enable(flecs::id_t id, bool toggle = true) const {
570 ecs_enable_id(this->world_, this->id_, id, toggle);
571 return to_base();
572 }
573
579 template<typename T>
580 const Self& enable() const {
581 return this->enable(_::type<T>::id(this->world_));
582 }
583
590 const Self& enable(flecs::id_t first, flecs::id_t second) const {
591 return this->enable(ecs_pair(first, second));
592 }
593
600 template<typename First>
601 const Self& enable(flecs::id_t second) const {
602 return this->enable(_::type<First>::id(world_), second);
603 }
604
611 template<typename First, typename Second>
612 const Self& enable() const {
613 return this->enable<First>(_::type<Second>::id(world_));
614 }
615
625 const Self& disable(flecs::id_t id) const {
626 return this->enable(id, false);
627 }
628
634 template<typename T>
635 const Self& disable() const {
636 return this->disable(_::type<T>::id(world_));
637 }
638
645 const Self& disable(flecs::id_t first, flecs::id_t second) const {
646 return this->disable(ecs_pair(first, second));
647 }
648
655 template<typename First>
656 const Self& disable(flecs::id_t second) const {
657 return this->disable(_::type<First>::id(world_), second);
658 }
659
666 template<typename First, typename Second>
667 const Self& disable() const {
668 return this->disable<First>(_::type<Second>::id(world_));
669 }
670
671 const Self& set_ptr(entity_t comp, size_t size, const void *ptr) const {
672 ecs_set_id(this->world_, this->id_, comp, size, ptr);
673 return to_base();
674 }
675
676 const Self& set_ptr(entity_t comp, const void *ptr) const {
677 const flecs::Component *cptr = ecs_get(
678 this->world_, comp, EcsComponent);
679
680 /* Can't set if it's not a component */
681 ecs_assert(cptr != NULL, ECS_INVALID_PARAMETER, NULL);
682
683 return set_ptr(comp, cptr->size, ptr);
684 }
685
693 template<typename T, if_t<is_actual<T>::value> = 0 >
694 const Self& set(T&& value) const {
695 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
696 return to_base();
697 }
698
706 template<typename T, if_t<is_actual<T>::value > = 0>
707 const Self& set(const T& value) const {
708 flecs::set<T>(this->world_, this->id_, value);
709 return to_base();
710 }
711
719 template<typename T, typename A = actual_type_t<T>, if_not_t<
720 is_actual<T>::value > = 0>
721 const Self& set(A&& value) const {
722 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
723 return to_base();
724 }
725
733 template<typename T, typename A = actual_type_t<T>, if_not_t<
734 is_actual<T>::value > = 0>
735 const Self& set(const A& value) const {
736 flecs::set<T>(this->world_, this->id_, value);
737 return to_base();
738 }
739
748 template <typename First, typename Second, typename P = pair<First, Second>,
749 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
750 const Self& set(A&& value) const {
751 flecs::set<P>(this->world_, this->id_, FLECS_FWD(value));
752 return to_base();
753 }
754
763 template <typename First, typename Second, typename P = pair<First, Second>,
764 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
765 const Self& set(const A& value) const {
766 flecs::set<P>(this->world_, this->id_, value);
767 return to_base();
768 }
769
778 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
779 const Self& set(Second second, const First& value) const {
780 auto first = _::type<First>::id(this->world_);
781 flecs::set(this->world_, this->id_, value,
782 ecs_pair(first, second));
783 return to_base();
784 }
785
794 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
795 const Self& set(Second second, First&& value) const {
796 auto first = _::type<First>::id(this->world_);
797 flecs::set(this->world_, this->id_, FLECS_FWD(value),
798 ecs_pair(first, second));
799 return to_base();
800 }
801
810 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
811 const Self& set(Second constant, const First& value) const {
812 const auto& et = enum_type<Second>(this->world_);
813 flecs::entity_t second = et.entity(constant);
814 return set<First>(second, value);
815 }
816
825 template <typename Second>
826 const Self& set_second(entity_t first, const Second& value) const {
827 auto second = _::type<Second>::id(this->world_);
828 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
829 ECS_INVALID_PARAMETER, "pair is not a component");
830 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
831 ECS_INVALID_PARAMETER, "type of pair is not Second");
832 flecs::set(this->world_, this->id_, value,
833 ecs_pair(first, second));
834 return to_base();
835 }
836
845 template <typename Second>
846 const Self& set_second(entity_t first, Second&& value) const {
847 auto second = _::type<Second>::id(this->world_);
848 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
849 ECS_INVALID_PARAMETER, "pair is not a component");
850 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
851 ECS_INVALID_PARAMETER, "type of pair is not Second");
852 flecs::set(this->world_, this->id_, FLECS_FWD(value),
853 ecs_pair(first, second));
854 return to_base();
855 }
856
865 template <typename First, typename Second>
866 const Self& set_second(const Second& value) const {
867 flecs::set<pair_object<First, Second>>(this->world_, this->id_, value);
868 return to_base();
869 }
870
871
879 template<typename T, if_t<is_actual<T>::value> = 0 >
880 const Self& assign(T&& value) const {
881 flecs::assign<T>(this->world_, this->id_, FLECS_FWD(value));
882 return to_base();
883 }
884
892 template<typename T, if_t<is_actual<T>::value > = 0>
893 const Self& assign(const T& value) const {
894 flecs::assign<T>(this->world_, this->id_, value);
895 return to_base();
896 }
897
905 template<typename T, typename A = actual_type_t<T>, if_not_t<
906 is_actual<T>::value > = 0>
907 const Self& assign(A&& value) const {
908 flecs::assign<T>(this->world_, this->id_, FLECS_FWD(value));
909 return to_base();
910 }
911
919 template<typename T, typename A = actual_type_t<T>, if_not_t<
920 is_actual<T>::value > = 0>
921 const Self& assign(const A& value) const {
922 flecs::assign<T>(this->world_, this->id_, value);
923 return to_base();
924 }
925
934 template <typename First, typename Second, typename P = pair<First, Second>,
935 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
936 const Self& assign(A&& value) const {
937 flecs::assign<P>(this->world_, this->id_, FLECS_FWD(value));
938 return to_base();
939 }
940
949 template <typename First, typename Second, typename P = pair<First, Second>,
950 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
951 const Self& assign(const A& value) const {
952 flecs::assign<P>(this->world_, this->id_, value);
953 return to_base();
954 }
955
964 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
965 const Self& assign(Second second, const First& value) const {
966 auto first = _::type<First>::id(this->world_);
967 flecs::assign(this->world_, this->id_, value,
968 ecs_pair(first, second));
969 return to_base();
970 }
971
980 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
981 const Self& assign(Second second, First&& value) const {
982 auto first = _::type<First>::id(this->world_);
983 flecs::assign(this->world_, this->id_, FLECS_FWD(value),
984 ecs_pair(first, second));
985 return to_base();
986 }
987
996 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
997 const Self& assign(Second constant, const First& value) const {
998 const auto& et = enum_type<Second>(this->world_);
999 flecs::entity_t second = et.entity(constant);
1000 return assign<First>(second, value);
1001 }
1002
1011 template <typename Second>
1012 const Self& assign_second(entity_t first, const Second& value) const {
1013 auto second = _::type<Second>::id(this->world_);
1014 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
1015 ECS_INVALID_PARAMETER, "pair is not a component");
1016 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
1017 ECS_INVALID_PARAMETER, "type of pair is not Second");
1018 flecs::assign(this->world_, this->id_, value,
1019 ecs_pair(first, second));
1020 return to_base();
1021 }
1022
1031 template <typename Second>
1032 const Self& assign_second(entity_t first, Second&& value) const {
1033 auto second = _::type<Second>::id(this->world_);
1034 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
1035 ECS_INVALID_PARAMETER, "pair is not a component");
1036 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
1037 ECS_INVALID_PARAMETER, "type of pair is not Second");
1038 flecs::assign(this->world_, this->id_, FLECS_FWD(value),
1039 ecs_pair(first, second));
1040 return to_base();
1041 }
1042
1043 template <typename First, typename Second>
1044 const Self& assign_second(const Second& value) const {
1045 flecs::assign<pair_object<First, Second>>(this->world_, this->id_, value);
1046 return to_base();
1047 }
1048
1049
1065 template <typename Func>
1066 const Self& insert(const Func& func) const;
1067
1075 template<typename T, typename ... Args, typename A = actual_type_t<T>>
1076 const Self& emplace(Args&&... args) const {
1077 flecs::emplace<A>(this->world_, this->id_,
1078 _::type<T>::id(this->world_), FLECS_FWD(args)...);
1079 return to_base();
1080 }
1081
1082 template <typename First, typename Second, typename ... Args, typename P = pair<First, Second>,
1083 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
1084 const Self& emplace(Args&&... args) const {
1085 flecs::emplace<A>(this->world_, this->id_,
1086 ecs_pair(_::type<First>::id(this->world_),
1087 _::type<Second>::id(this->world_)),
1088 FLECS_FWD(args)...);
1089 return to_base();
1090 }
1091
1092 template <typename First, typename ... Args>
1093 const Self& emplace_first(flecs::entity_t second, Args&&... args) const {
1094 auto first = _::type<First>::id(this->world_);
1095 flecs::emplace<First>(this->world_, this->id_,
1096 ecs_pair(first, second),
1097 FLECS_FWD(args)...);
1098 return to_base();
1099 }
1100
1101 template <typename Second, typename ... Args>
1102 const Self& emplace_second(flecs::entity_t first, Args&&... args) const {
1103 auto second = _::type<Second>::id(this->world_);
1104 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
1105 ECS_INVALID_PARAMETER, "pair is not a component");
1106 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
1107 ECS_INVALID_PARAMETER, "type of pair is not Second");
1108 flecs::emplace<Second>(this->world_, this->id_,
1109 ecs_pair(first, second),
1110 FLECS_FWD(args)...);
1111 return to_base();
1112 }
1113
1119 template <typename Func>
1120 const Self& with(const Func& func) const {
1121 ecs_id_t prev = ecs_set_with(this->world_, this->id_);
1122 func();
1123 ecs_set_with(this->world_, prev);
1124 return to_base();
1125 }
1126
1133 template <typename First, typename Func>
1134 const Self& with(const Func& func) const {
1135 with(_::type<First>::id(this->world_), func);
1136 return to_base();
1137 }
1138
1145 template <typename Func>
1146 const Self& with(entity_t first, const Func& func) const {
1147 ecs_id_t prev = ecs_set_with(this->world_,
1148 ecs_pair(first, this->id_));
1149 func();
1150 ecs_set_with(this->world_, prev);
1151 return to_base();
1152 }
1153
1155 template <typename Func>
1156 const Self& scope(const Func& func) const {
1157 ecs_entity_t prev = ecs_set_scope(this->world_, this->id_);
1158 func();
1159 ecs_set_scope(this->world_, prev);
1160 return to_base();
1161 }
1162
1164 scoped_world scope() const {
1165 return scoped_world(world_, id_);
1166 }
1167
1168 /* Set the entity name.
1169 */
1170 const Self& set_name(const char *name) const {
1171 ecs_set_name(this->world_, this->id_, name);
1172 return to_base();
1173 }
1174
1175 /* Set entity alias.
1176 */
1177 const Self& set_alias(const char *name) const {
1178 ecs_set_alias(this->world_, this->id_, name);
1179 return to_base();
1180 }
1181
1182# ifdef FLECS_DOC
1183# include "../doc/entity_builder.inl"
1184# endif
1185
1186# ifdef FLECS_META
1187# include "../meta/entity_builder.inl"
1188# endif
1189
1190# ifdef FLECS_JSON
1191# include "../json/entity_builder.inl"
1192# endif
1193
1194# include "../event/entity_builder.inl"
1195
1196protected:
1197 const Self& to_base() const {
1198 return *static_cast<const Self*>(this);
1199 }
1200};
1201
1202}
entity_builder.inl
Doc entity builder mixin.
entity_builder.inl
Event entity mixin.
ecs_remove_id
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Remove a component from an entity.
ecs_add_id
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) id to an entity.
ecs_set_with
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t component)
Create new entities with specified component.
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
ecs_check
#define ecs_check(condition, error_code,...)
Check.
Definition log.h:412
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 an component.
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:361
ecs_id_t
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:354
flecs::component::constant
untyped_component & constant(const char *name, T value)
Add constant.
Definition untyped_component.inl:192
ecs_enable_id
void ecs_enable_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, bool enable)
Enable or disable component.
ecs_enable
void ecs_enable(ecs_world_t *world, ecs_entity_t entity, bool enabled)
Enable or disable entity.
ecs_get_target
ecs_entity_t ecs_get_target(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, int32_t index)
Get the target of a 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_set_id
void ecs_set_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, size_t size, const void *ptr)
Set the value of a component.
ECS_AUTO_OVERRIDE
const ecs_id_t ECS_AUTO_OVERRIDE
Automatically override component when it is inherited.
ecs_set_alias
void ecs_set_alias(ecs_world_t *world, ecs_entity_t entity, const char *alias)
Set alias for entity.
ecs_set_name
ecs_entity_t ecs_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Set the name of an entity.
ecs_set_scope
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
entity_builder.inl
JSON entity mixin.
entity_builder.inl
Meta entity builder mixin.
EcsComponent
Component information.
Definition flecs.h:1537
EcsComponent::size
ecs_size_t size
Component size.
Definition flecs.h:1538
flecs::_::type
Definition flecs.hpp:39
flecs::component
Component class.
Definition component.hpp:382
flecs::entity_builder
Entity builder.
Definition builder.hpp:15
flecs::entity_builder::emplace_auto_override
const Self & emplace_auto_override(Args &&... args) const
Emplace pair, mark pair for auto-overriding.
Definition builder.hpp:531
flecs::entity_builder::disable
const Self & disable() const
Disable an entity.
Definition builder.hpp:555
flecs::entity_builder::add
const Self & add(E value) const
Add pair for enum constant.
Definition builder.hpp:42
flecs::entity_builder::set
const Self & set(Second constant, const First &value) const
Set a pair for an entity.
Definition builder.hpp:811
flecs::entity_builder::auto_override
const Self & auto_override(flecs::entity_t second) const
Mark pair for auto-overriding.
Definition builder.hpp:412
flecs::entity_builder::enable
const Self & enable(flecs::id_t second) const
Enable a pair.
Definition builder.hpp:601
flecs::entity_builder::remove
const Self & remove(Second constant) const
Remove a pair.
Definition builder.hpp:368
flecs::entity_builder::remove
const Self & remove(entity_t first, entity_t second) const
Remove a pair.
Definition builder.hpp:323
flecs::entity_builder::add_if
const Self & add_if(bool cond, E constant) const
Conditional add.
Definition builder.hpp:204
flecs::entity_builder::remove
const Self & remove(Second second) const
Remove a pair.
Definition builder.hpp:346
flecs::entity_builder::emplace
const Self & emplace(Args &&... args) const
Emplace component.
Definition builder.hpp:1076
flecs::entity_builder::set_auto_override
const Self & set_auto_override(flecs::entity_t second, const First &val) const
Set pair, mark component for auto-overriding.
Definition builder.hpp:459
flecs::entity_builder::assign
const Self & assign(const A &value) const
Assign a component for an entity.
Definition builder.hpp:921
flecs::entity_builder::disable
const Self & disable(flecs::id_t first, flecs::id_t second) const
Disable a pair.
Definition builder.hpp:645
flecs::entity_builder::emplace_auto_override
const Self & emplace_auto_override(Args &&... args) const
Emplace component, mark component for auto-overriding.
Definition builder.hpp:512
flecs::entity_builder::assign
const Self & assign(Second second, First &&value) const
Assign a pair for an entity.
Definition builder.hpp:981
flecs::entity_builder::add
const Self & add() const
Add a pair.
Definition builder.hpp:79
flecs::entity_builder::is_a
const Self & is_a() const
Shortcut for add(IsA, entity).
Definition builder.hpp:222
flecs::entity_builder::enable
const Self & enable() const
Enable an entity.
Definition builder.hpp:546
flecs::entity_builder::remove_second
const Self & remove_second(flecs::entity_t first) const
Removes a pair.
Definition builder.hpp:357
flecs::entity_builder::slot_of
const Self & slot_of(entity_t second) const
Shortcut for add(SlotOf, entity).
Definition builder.hpp:257
flecs::entity_builder::auto_override
const Self & auto_override() const
Mark component for auto-overriding.
Definition builder.hpp:401
flecs::entity_builder::enable
const Self & enable() const
Enable a component.
Definition builder.hpp:580
flecs::entity_builder::scope
scoped_world scope() const
Return world scoped to entity.
Definition builder.hpp:1164
flecs::entity_builder::set
const Self & set(const T &value) const
Set a component for an entity.
Definition builder.hpp:707
flecs::entity_builder::child_of
const Self & child_of() const
Shortcut for add(ChildOf, entity).
Definition builder.hpp:276
flecs::entity_builder::set
const Self & set(A &&value) const
Set a pair for an entity.
Definition builder.hpp:750
flecs::entity_builder::set_auto_override
const Self & set_auto_override(A &&val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:500
flecs::entity_builder::set
const Self & set(const A &value) const
Set a component for an entity.
Definition builder.hpp:735
flecs::entity_builder::enable
const Self & enable() const
Enable a pair.
Definition builder.hpp:612
flecs::entity_builder::enable
const Self & enable(flecs::id_t first, flecs::id_t second) const
Enable a pair.
Definition builder.hpp:590
flecs::entity_builder::remove
const Self & remove() const
Remove a component from an entity.
Definition builder.hpp:303
flecs::entity_builder::disable
const Self & disable(flecs::id_t id) const
Disable an id.
Definition builder.hpp:625
flecs::entity_builder::slot
const Self & slot() const
Shortcut for add(SlotOf, target(ChildOf)).
Definition builder.hpp:263
flecs::entity_builder::assign
const Self & assign(const A &value) const
Assign a pair for an entity.
Definition builder.hpp:951
flecs::entity_builder::assign
const Self & assign(A &&value) const
Assign a pair for an entity.
Definition builder.hpp:936
flecs::entity_builder::assign
const Self & assign(const T &value) const
Assign a component for an entity.
Definition builder.hpp:893
flecs::entity_builder::set
const Self & set(Second second, const First &value) const
Set a pair for an entity.
Definition builder.hpp:779
flecs::entity_builder::assign
const Self & assign(T &&value) const
Assign a component for an entity.
Definition builder.hpp:880
flecs::entity_builder::add_if
const Self & add_if(bool cond) const
Conditional add.
Definition builder.hpp:193
flecs::entity_builder::is_a
const Self & is_a(entity_t second) const
Shortcut for add(IsA, entity).
Definition builder.hpp:213
flecs::entity_builder::add
const Self & add(Second constant) const
Add a pair.
Definition builder.hpp:104
flecs::entity_builder::depends_on
const Self & depends_on(E second) const
Shortcut for add(DependsOn, entity).
Definition builder.hpp:247
flecs::entity_builder::add_if
const Self & add_if(bool cond, flecs::entity_t first, flecs::entity_t second) const
Conditional add.
Definition builder.hpp:158
flecs::entity_builder::set_second
const Self & set_second(entity_t first, Second &&value) const
Set a pair for an entity.
Definition builder.hpp:846
flecs::entity_builder::set_auto_override
const Self & set_auto_override(T &&val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:446
flecs::entity_builder::add_if
const Self & add_if(bool cond) const
Conditional add.
Definition builder.hpp:143
flecs::entity_builder::remove
const Self & remove() const
Removes a pair.
Definition builder.hpp:335
flecs::entity_builder::disable
const Self & disable() const
Disable a component.
Definition builder.hpp:635
flecs::entity_builder::add
const Self & add(id_t component) const
Add an entity to an entity.
Definition builder.hpp:56
flecs::entity_builder::add
const Self & add(entity_t first, entity_t second) const
Add a pair.
Definition builder.hpp:67
flecs::entity_builder::with
const Self & with(entity_t first, const Func &func) const
Entities created in function will have (first, this).
Definition builder.hpp:1146
flecs::entity_builder::set
const Self & set(Second second, First &&value) const
Set a pair for an entity.
Definition builder.hpp:795
flecs::entity_builder::assign
const Self & assign(Second second, const First &value) const
Assign a pair for an entity.
Definition builder.hpp:965
flecs::entity_builder::insert
const Self & insert(const Func &func) const
Set 1..N components.
Definition impl.hpp:23
flecs::entity_builder::scope
const Self & scope(const Func &func) const
The function will be ran with the scope set to the current entity.
Definition builder.hpp:1156
flecs::entity_builder::add_if
const Self & add_if(bool cond, flecs::entity_t second) const
Conditional add.
Definition builder.hpp:181
flecs::entity_builder::assign_second
const Self & assign_second(entity_t first, Second &&value) const
Assign a pair for an entity.
Definition builder.hpp:1032
flecs::entity_builder::add_second
const Self & add_second(flecs::entity_t first) const
Add a pair.
Definition builder.hpp:118
flecs::entity_builder::add_if
const Self & add_if(bool cond, flecs::id_t component) const
Conditional add.
Definition builder.hpp:128
flecs::entity_builder::with
const Self & with(const Func &func) const
Entities created in function will have (First, this).
Definition builder.hpp:1134
flecs::entity_builder::disable
const Self & disable(flecs::id_t second) const
Disable a pair.
Definition builder.hpp:656
flecs::entity_builder::set_second
const Self & set_second(const Second &value) const
Set a pair for an entity.
Definition builder.hpp:866
flecs::entity_builder::set_auto_override
const Self & set_auto_override(const T &val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:434
flecs::entity_builder::assign
const Self & assign(A &&value) const
Assign a component for an entity.
Definition builder.hpp:907
flecs::entity_builder::remove
const Self & remove(entity_t entity) const
Remove an entity from an entity.
Definition builder.hpp:312
flecs::entity_builder::assign
const Self & assign(Second constant, const First &value) const
Assign a pair for an entity.
Definition builder.hpp:997
flecs::entity_builder::set_auto_override
const Self & set_auto_override(flecs::entity_t second, First &&val) const
Set pair, mark component for auto-overriding.
Definition builder.hpp:472
flecs::entity_builder::set
const Self & set(A &&value) const
Set a component for an entity.
Definition builder.hpp:721
flecs::entity_builder::enable
const Self & enable(flecs::id_t id, bool toggle=true) const
Enable an id.
Definition builder.hpp:569
flecs::entity_builder::child_of
const Self & child_of(entity_t second) const
Shortcut for add(ChildOf, entity).
Definition builder.hpp:230
flecs::entity_builder::set
const Self & set(T &&value) const
Set a component for an entity.
Definition builder.hpp:694
flecs::entity_builder::depends_on
const Self & depends_on(entity_t second) const
Shortcut for add(DependsOn, entity).
Definition builder.hpp:238
flecs::entity_builder::depends_on
const Self & depends_on() const
Shortcut for add(DependsOn, entity).
Definition builder.hpp:285
flecs::entity_builder::auto_override
const Self & auto_override(flecs::id_t id) const
Mark id for auto-overriding.
Definition builder.hpp:381
flecs::entity_builder::set
const Self & set(const A &value) const
Set a pair for an entity.
Definition builder.hpp:765
flecs::entity_builder::disable
const Self & disable() const
Disable a pair.
Definition builder.hpp:667
flecs::entity_builder::auto_override
const Self & auto_override(flecs::entity_t first, flecs::entity_t second) const
Mark pair for auto-overriding.
Definition builder.hpp:391
flecs::entity_builder::auto_override
const Self & auto_override() const
Mark pair for auto-overriding.
Definition builder.hpp:423
flecs::entity_builder::slot_of
const Self & slot_of() const
Shortcut for add(SlotOf, entity).
Definition builder.hpp:294
flecs::entity_builder::add
const Self & add() const
Add a component to an entity.
Definition builder.hpp:25
flecs::entity_builder::assign_second
const Self & assign_second(entity_t first, const Second &value) const
Assign a pair for an entity.
Definition builder.hpp:1012
flecs::entity_builder::add
const Self & add(Second second) const
Add a pair.
Definition builder.hpp:90
flecs::entity_builder::set_auto_override
const Self & set_auto_override(const A &val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:486
flecs::entity_builder::with
const Self & with(const Func &func) const
Entities created in function will have the current entity.
Definition builder.hpp:1120
flecs::entity_builder::set_second
const Self & set_second(entity_t first, const Second &value) const
Set a pair for an entity.
Definition builder.hpp:826
flecs::entity_view::name
flecs::string_view name() const
Return the entity name.
Definition entity_view.hpp:84
flecs::entity_view::target
flecs::entity target(int32_t index=0) const
Get target for a given pair.
Definition impl.hpp:36
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id::second
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
flecs::id::first
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
flecs::pair
Type that represents a pair.
Definition pair.hpp:36
flecs::scoped_world
Scoped world.
Definition world.hpp:1419