Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs
9{
10
14template <typename Self>
16
17 using entity_view::entity_view;
18
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
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
56 const Self& add(id_t component) const {
57 ecs_add_id(this->world_, this->id_, component);
58 return to_base();
59 }
60
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
78 template<typename First, typename Second>
79 const Self& add() const {
80 return this->add<First>(_::type<Second>::id(this->world_));
81 }
82
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
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 Second>
434 const Self& auto_override_second(flecs::entity_t first) const {
435 return this->auto_override(first, _::type<Second>::id(this->world_));
436 }
437
444 template <typename T>
445 const Self& set_auto_override(const T& val) const {
446 this->auto_override<T>();
447 return this->set<T>(val);
448 }
449
456 template <typename T>
457 const Self& set_auto_override(T&& val) const {
458 this->auto_override<T>();
459 return this->set<T>(FLECS_FWD(val));
460 }
461
469 template <typename First>
470 const Self& set_auto_override(flecs::entity_t second, const First& val) const {
471 this->auto_override<First>(second);
472 return this->set<First>(second, val);
473 }
474
482 template <typename First>
483 const Self& set_auto_override(flecs::entity_t second, First&& val) const {
484 this->auto_override<First>(second);
485 return this->set<First>(second, FLECS_FWD(val));
486 }
487
495 template <typename First, typename Second, typename P = pair<First, Second>,
496 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
497 const Self& set_auto_override(const A& val) const {
498 this->auto_override<First, Second>();
499 return this->set<First, Second>(val);
500 }
501
509 template <typename First, typename Second, typename P = pair<First, Second>,
510 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
511 const Self& set_auto_override(A&& val) const {
512 this->auto_override<First, Second>();
513 return this->set<First, Second>(FLECS_FWD(val));
514 }
515
522 template <typename T, typename ... Args>
523 const Self& emplace_auto_override(Args&&... args) const {
524 this->auto_override<T>();
525
526 flecs::emplace<T>(this->world_, this->id_,
527 _::type<T>::id(this->world_), FLECS_FWD(args)...);
528
529 return to_base();
530 }
531
539 template <typename First, typename Second, typename P = pair<First, Second>,
540 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0,
541 typename ... Args>
542 const Self& emplace_auto_override(Args&&... args) const {
543 this->auto_override<First, Second>();
544
545 flecs::emplace<A>(this->world_, this->id_,
546 ecs_pair(_::type<First>::id(this->world_),
547 _::type<Second>::id(this->world_)),
548 FLECS_FWD(args)...);
549
550 return to_base();
551 }
552
557 const Self& enable() const {
558 ecs_enable(this->world_, this->id_, true);
559 return to_base();
560 }
561
566 const Self& disable() const {
567 ecs_enable(this->world_, this->id_, false);
568 return to_base();
569 }
570
580 const Self& enable(flecs::id_t id, bool toggle = true) const {
581 ecs_enable_id(this->world_, this->id_, id, toggle);
582 return to_base();
583 }
584
590 template<typename T>
591 const Self& enable() const {
592 return this->enable(_::type<T>::id(this->world_));
593 }
594
601 const Self& enable(flecs::id_t first, flecs::id_t second) const {
602 return this->enable(ecs_pair(first, second));
603 }
604
611 template<typename First>
612 const Self& enable(flecs::id_t second) const {
613 return this->enable(_::type<First>::id(world_), second);
614 }
615
622 template<typename First, typename Second>
623 const Self& enable() const {
624 return this->enable<First>(_::type<Second>::id(world_));
625 }
626
636 const Self& disable(flecs::id_t id) const {
637 return this->enable(id, false);
638 }
639
645 template<typename T>
646 const Self& disable() const {
647 return this->disable(_::type<T>::id(world_));
648 }
649
656 const Self& disable(flecs::id_t first, flecs::id_t second) const {
657 return this->disable(ecs_pair(first, second));
658 }
659
666 template<typename First>
667 const Self& disable(flecs::id_t second) const {
668 return this->disable(_::type<First>::id(world_), second);
669 }
670
677 template<typename First, typename Second>
678 const Self& disable() const {
679 return this->disable<First>(_::type<Second>::id(world_));
680 }
681
682 const Self& set_ptr(entity_t comp, size_t size, const void *ptr) const {
683 ecs_set_id(this->world_, this->id_, comp, size, ptr);
684 return to_base();
685 }
686
687 const Self& set_ptr(entity_t comp, const void *ptr) const {
688
689 const ecs_type_info_t *type_info = ecs_get_type_info(this->world_, comp);
690
691 /* Can't set if it's not a component */
692 ecs_assert(type_info != NULL, ECS_INVALID_PARAMETER, NULL);
693
694 return set_ptr(comp, type_info->size, ptr);
695 }
696
704 template<typename T, if_t<is_actual<T>::value> = 0 >
705 const Self& set(T&& value) const {
706 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
707 return to_base();
708 }
709
717 template<typename T, if_t<is_actual<T>::value > = 0>
718 const Self& set(const T& value) const {
719 flecs::set<T>(this->world_, this->id_, value);
720 return to_base();
721 }
722
730 template<typename T, typename A = actual_type_t<T>, if_not_t<
731 is_actual<T>::value > = 0>
732 const Self& set(A&& value) const {
733 flecs::set<T>(this->world_, this->id_, FLECS_FWD(value));
734 return to_base();
735 }
736
744 template<typename T, typename A = actual_type_t<T>, if_not_t<
745 is_actual<T>::value > = 0>
746 const Self& set(const A& value) const {
747 flecs::set<T>(this->world_, this->id_, value);
748 return to_base();
749 }
750
759 template <typename First, typename Second, typename P = pair<First, Second>,
760 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
761 const Self& set(A&& value) const {
762 flecs::set<P>(this->world_, this->id_, FLECS_FWD(value));
763 return to_base();
764 }
765
774 template <typename First, typename Second, typename P = pair<First, Second>,
775 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
776 const Self& set(const A& value) const {
777 flecs::set<P>(this->world_, this->id_, value);
778 return to_base();
779 }
780
789 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
790 const Self& set(Second second, const First& value) const {
791 auto first = _::type<First>::id(this->world_);
792 flecs::set(this->world_, this->id_, value,
793 ecs_pair(first, second));
794 return to_base();
795 }
796
805 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
806 const Self& set(Second second, First&& value) const {
807 auto first = _::type<First>::id(this->world_);
808 flecs::set(this->world_, this->id_, FLECS_FWD(value),
809 ecs_pair(first, second));
810 return to_base();
811 }
812
821 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
822 const Self& set(Second constant, const First& value) const {
823 const auto& et = enum_type<Second>(this->world_);
824 flecs::entity_t second = et.entity(constant);
825 return set<First>(second, value);
826 }
827
836 template <typename Second>
837 const Self& set_second(entity_t first, const Second& value) const {
838 auto second = _::type<Second>::id(this->world_);
839 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
840 ECS_INVALID_PARAMETER, "pair is not a component");
841 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
842 ECS_INVALID_PARAMETER, "type of pair is not Second");
843 flecs::set(this->world_, this->id_, value,
844 ecs_pair(first, second));
845 return to_base();
846 }
847
856 template <typename Second>
857 const Self& set_second(entity_t first, Second&& value) const {
858 auto second = _::type<Second>::id(this->world_);
859 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
860 ECS_INVALID_PARAMETER, "pair is not a component");
861 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
862 ECS_INVALID_PARAMETER, "type of pair is not Second");
863 flecs::set(this->world_, this->id_, FLECS_FWD(value),
864 ecs_pair(first, second));
865 return to_base();
866 }
867
876 template <typename First, typename Second>
877 const Self& set_second(const Second& value) const {
878 flecs::set<pair_object<First, Second>>(this->world_, this->id_, value);
879 return to_base();
880 }
881
882
890 template<typename T, if_t<is_actual<T>::value> = 0 >
891 const Self& assign(T&& value) const {
892 flecs::assign<T>(this->world_, this->id_, FLECS_FWD(value));
893 return to_base();
894 }
895
903 template<typename T, if_t<is_actual<T>::value > = 0>
904 const Self& assign(const T& value) const {
905 flecs::assign<T>(this->world_, this->id_, value);
906 return to_base();
907 }
908
916 template<typename T, typename A = actual_type_t<T>, if_not_t<
917 is_actual<T>::value > = 0>
918 const Self& assign(A&& value) const {
919 flecs::assign<T>(this->world_, this->id_, FLECS_FWD(value));
920 return to_base();
921 }
922
930 template<typename T, typename A = actual_type_t<T>, if_not_t<
931 is_actual<T>::value > = 0>
932 const Self& assign(const A& value) const {
933 flecs::assign<T>(this->world_, this->id_, value);
934 return to_base();
935 }
936
945 template <typename First, typename Second, typename P = pair<First, Second>,
946 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
947 const Self& assign(A&& value) const {
948 flecs::assign<P>(this->world_, this->id_, FLECS_FWD(value));
949 return to_base();
950 }
951
960 template <typename First, typename Second, typename P = pair<First, Second>,
961 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
962 const Self& assign(const A& value) const {
963 flecs::assign<P>(this->world_, this->id_, value);
964 return to_base();
965 }
966
975 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
976 const Self& assign(Second second, const First& value) const {
977 auto first = _::type<First>::id(this->world_);
978 flecs::assign(this->world_, this->id_, value,
979 ecs_pair(first, second));
980 return to_base();
981 }
982
991 template <typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
992 const Self& assign(Second second, First&& value) const {
993 auto first = _::type<First>::id(this->world_);
994 flecs::assign(this->world_, this->id_, FLECS_FWD(value),
995 ecs_pair(first, second));
996 return to_base();
997 }
998
1007 template <typename First, typename Second, if_t< is_enum<Second>::value > = 0>
1008 const Self& assign(Second constant, const First& value) const {
1009 const auto& et = enum_type<Second>(this->world_);
1010 flecs::entity_t second = et.entity(constant);
1011 return assign<First>(second, value);
1012 }
1013
1022 template <typename Second>
1023 const Self& assign_second(entity_t first, const Second& value) const {
1024 auto second = _::type<Second>::id(this->world_);
1025 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
1026 ECS_INVALID_PARAMETER, "pair is not a component");
1027 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
1028 ECS_INVALID_PARAMETER, "type of pair is not Second");
1029 flecs::assign(this->world_, this->id_, value,
1030 ecs_pair(first, second));
1031 return to_base();
1032 }
1033
1042 template <typename Second>
1043 const Self& assign_second(entity_t first, Second&& value) const {
1044 auto second = _::type<Second>::id(this->world_);
1045 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
1046 ECS_INVALID_PARAMETER, "pair is not a component");
1047 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
1048 ECS_INVALID_PARAMETER, "type of pair is not Second");
1049 flecs::assign(this->world_, this->id_, FLECS_FWD(value),
1050 ecs_pair(first, second));
1051 return to_base();
1052 }
1053
1054 template <typename First, typename Second>
1055 const Self& assign_second(const Second& value) const {
1056 flecs::assign<pair_object<First, Second>>(this->world_, this->id_, value);
1057 return to_base();
1058 }
1059
1060
1076 template <typename Func>
1077 const Self& insert(const Func& func) const;
1078
1086 template<typename T, typename ... Args, typename A = actual_type_t<T>>
1087 const Self& emplace(Args&&... args) const {
1088 flecs::emplace<A>(this->world_, this->id_,
1089 _::type<T>::id(this->world_), FLECS_FWD(args)...);
1090 return to_base();
1091 }
1092
1093 template <typename First, typename Second, typename ... Args, typename P = pair<First, Second>,
1094 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
1095 const Self& emplace(Args&&... args) const {
1096 flecs::emplace<A>(this->world_, this->id_,
1097 ecs_pair(_::type<First>::id(this->world_),
1098 _::type<Second>::id(this->world_)),
1099 FLECS_FWD(args)...);
1100 return to_base();
1101 }
1102
1103 template <typename First, typename ... Args>
1104 const Self& emplace_first(flecs::entity_t second, Args&&... args) const {
1105 auto first = _::type<First>::id(this->world_);
1106 flecs::emplace<First>(this->world_, this->id_,
1107 ecs_pair(first, second),
1108 FLECS_FWD(args)...);
1109 return to_base();
1110 }
1111
1112 template <typename Second, typename ... Args>
1113 const Self& emplace_second(flecs::entity_t first, Args&&... args) const {
1114 auto second = _::type<Second>::id(this->world_);
1115 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second)) != NULL,
1116 ECS_INVALID_PARAMETER, "pair is not a component");
1117 ecs_assert( ecs_get_type_info(world_, ecs_pair(first, second))->component == second,
1118 ECS_INVALID_PARAMETER, "type of pair is not Second");
1119 flecs::emplace<Second>(this->world_, this->id_,
1120 ecs_pair(first, second),
1121 FLECS_FWD(args)...);
1122 return to_base();
1123 }
1124
1130 template <typename Func>
1131 const Self& with(const Func& func) const {
1132 ecs_id_t prev = ecs_set_with(this->world_, this->id_);
1133 func();
1134 ecs_set_with(this->world_, prev);
1135 return to_base();
1136 }
1137
1144 template <typename First, typename Func>
1145 const Self& with(const Func& func) const {
1146 with(_::type<First>::id(this->world_), func);
1147 return to_base();
1148 }
1149
1156 template <typename Func>
1157 const Self& with(entity_t first, const Func& func) const {
1158 ecs_id_t prev = ecs_set_with(this->world_,
1159 ecs_pair(first, this->id_));
1160 func();
1161 ecs_set_with(this->world_, prev);
1162 return to_base();
1163 }
1164
1166 template <typename Func>
1167 const Self& scope(const Func& func) const {
1168 ecs_entity_t prev = ecs_set_scope(this->world_, this->id_);
1169 func();
1170 ecs_set_scope(this->world_, prev);
1171 return to_base();
1172 }
1173
1176 return scoped_world(world_, id_);
1177 }
1178
1179 /* Set the entity name.
1180 */
1181 const Self& set_name(const char *name) const {
1182 ecs_set_name(this->world_, this->id_, name);
1183 return to_base();
1184 }
1185
1186 /* Set entity alias.
1187 */
1188 const Self& set_alias(const char *name) const {
1189 ecs_set_alias(this->world_, this->id_, name);
1190 return to_base();
1191 }
1192
1193# ifdef FLECS_DOC
1194# include "../doc/entity_builder.inl"
1195# endif
1196
1197# ifdef FLECS_META
1199# endif
1200
1201# ifdef FLECS_JSON
1203# endif
1204
1206
1207protected:
1208 const Self& to_base() const {
1209 return *static_cast<const Self*>(this);
1210 }
1211};
1212
1213}
component< T > & constant(const char *name, T value)
Add constant.
Definition component.inl:31
Doc entity builder mixin.
Event entity mixin.
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Remove a component from an entity.
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) id to an entity.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t component)
Create new entities with specified component.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
#define ecs_check(condition, error_code,...)
Check.
Definition log.h:412
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_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:361
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:354
void ecs_enable_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, bool enable)
Enable or disable component.
void ecs_enable(ecs_world_t *world, ecs_entity_t entity, bool enabled)
Enable or disable entity.
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.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity has a component.
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.
const ecs_id_t ECS_AUTO_OVERRIDE
Automatically override component when it is inherited.
void ecs_set_alias(ecs_world_t *world, ecs_entity_t entity, const char *alias)
Set alias for entity.
ecs_entity_t ecs_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Set the name of an entity.
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
JSON entity mixin.
Meta entity builder mixin.
Type that contains component information (passed to ctors/dtors/...)
Definition flecs.h:995
ecs_size_t size
Size of type.
Definition flecs.h:996
Component class.
Entity builder.
Definition builder.hpp:15
const Self & emplace_auto_override(Args &&... args) const
Emplace pair, mark pair for auto-overriding.
Definition builder.hpp:542
const Self & disable() const
Disable an entity.
Definition builder.hpp:566
const Self & add(E value) const
Add pair for enum constant.
Definition builder.hpp:42
const Self & set(Second constant, const First &value) const
Set a pair for an entity.
Definition builder.hpp:822
const Self & auto_override(flecs::entity_t second) const
Mark pair for auto-overriding.
Definition builder.hpp:412
const Self & enable(flecs::id_t second) const
Enable a pair.
Definition builder.hpp:612
const Self & remove(Second constant) const
Remove a pair.
Definition builder.hpp:368
const Self & remove(entity_t first, entity_t second) const
Remove a pair.
Definition builder.hpp:323
const Self & add_if(bool cond, E constant) const
Conditional add.
Definition builder.hpp:204
const Self & remove(Second second) const
Remove a pair.
Definition builder.hpp:346
const Self & emplace(Args &&... args) const
Emplace component.
Definition builder.hpp:1087
const Self & set_auto_override(flecs::entity_t second, const First &val) const
Set pair, mark component for auto-overriding.
Definition builder.hpp:470
const Self & assign(const A &value) const
Assign a component for an entity.
Definition builder.hpp:932
const Self & disable(flecs::id_t first, flecs::id_t second) const
Disable a pair.
Definition builder.hpp:656
const Self & emplace_auto_override(Args &&... args) const
Emplace component, mark component for auto-overriding.
Definition builder.hpp:523
const Self & assign(Second second, First &&value) const
Assign a pair for an entity.
Definition builder.hpp:992
const Self & add() const
Add a pair.
Definition builder.hpp:79
const Self & is_a() const
Shortcut for add(IsA, entity).
Definition builder.hpp:222
const Self & enable() const
Enable an entity.
Definition builder.hpp:557
const Self & remove_second(flecs::entity_t first) const
Removes a pair.
Definition builder.hpp:357
const Self & slot_of(entity_t second) const
Shortcut for add(SlotOf, entity).
Definition builder.hpp:257
const Self & auto_override() const
Mark component for auto-overriding.
Definition builder.hpp:401
const Self & enable() const
Enable a component.
Definition builder.hpp:591
scoped_world scope() const
Return world scoped to entity.
Definition builder.hpp:1175
const Self & set(const T &value) const
Set a component for an entity.
Definition builder.hpp:718
const Self & child_of() const
Shortcut for add(ChildOf, entity).
Definition builder.hpp:276
const Self & set(A &&value) const
Set a pair for an entity.
Definition builder.hpp:761
const Self & set_auto_override(A &&val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:511
const Self & set(const A &value) const
Set a component for an entity.
Definition builder.hpp:746
const Self & enable() const
Enable a pair.
Definition builder.hpp:623
const Self & enable(flecs::id_t first, flecs::id_t second) const
Enable a pair.
Definition builder.hpp:601
const Self & remove() const
Remove a component from an entity.
Definition builder.hpp:303
const Self & disable(flecs::id_t id) const
Disable an id.
Definition builder.hpp:636
const Self & slot() const
Shortcut for add(SlotOf, target(ChildOf)).
Definition builder.hpp:263
const Self & assign(const A &value) const
Assign a pair for an entity.
Definition builder.hpp:962
const Self & assign(A &&value) const
Assign a pair for an entity.
Definition builder.hpp:947
const Self & assign(const T &value) const
Assign a component for an entity.
Definition builder.hpp:904
const Self & set(Second second, const First &value) const
Set a pair for an entity.
Definition builder.hpp:790
const Self & assign(T &&value) const
Assign a component for an entity.
Definition builder.hpp:891
const Self & add_if(bool cond) const
Conditional add.
Definition builder.hpp:193
const Self & is_a(entity_t second) const
Shortcut for add(IsA, entity).
Definition builder.hpp:213
const Self & add(Second constant) const
Add a pair.
Definition builder.hpp:104
const Self & depends_on(E second) const
Shortcut for add(DependsOn, entity).
Definition builder.hpp:247
const Self & add_if(bool cond, flecs::entity_t first, flecs::entity_t second) const
Conditional add.
Definition builder.hpp:158
const Self & set_second(entity_t first, Second &&value) const
Set a pair for an entity.
Definition builder.hpp:857
const Self & set_auto_override(T &&val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:457
const Self & add_if(bool cond) const
Conditional add.
Definition builder.hpp:143
const Self & remove() const
Removes a pair.
Definition builder.hpp:335
const Self & disable() const
Disable a component.
Definition builder.hpp:646
const Self & add(id_t component) const
Add an entity to an entity.
Definition builder.hpp:56
const Self & add(entity_t first, entity_t second) const
Add a pair.
Definition builder.hpp:67
const Self & with(entity_t first, const Func &func) const
Entities created in function will have (first, this).
Definition builder.hpp:1157
const Self & set(Second second, First &&value) const
Set a pair for an entity.
Definition builder.hpp:806
const Self & assign(Second second, const First &value) const
Assign a pair for an entity.
Definition builder.hpp:976
const Self & insert(const Func &func) const
Set 1..N components.
Definition impl.hpp:23
const Self & scope(const Func &func) const
The function will be ran with the scope set to the current entity.
Definition builder.hpp:1167
const Self & add_if(bool cond, flecs::entity_t second) const
Conditional add.
Definition builder.hpp:181
const Self & assign_second(entity_t first, Second &&value) const
Assign a pair for an entity.
Definition builder.hpp:1043
const Self & add_second(flecs::entity_t first) const
Add a pair.
Definition builder.hpp:118
const Self & add_if(bool cond, flecs::id_t component) const
Conditional add.
Definition builder.hpp:128
const Self & with(const Func &func) const
Entities created in function will have (First, this).
Definition builder.hpp:1145
const Self & disable(flecs::id_t second) const
Disable a pair.
Definition builder.hpp:667
const Self & set_second(const Second &value) const
Set a pair for an entity.
Definition builder.hpp:877
const Self & set_auto_override(const T &val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:445
const Self & assign(A &&value) const
Assign a component for an entity.
Definition builder.hpp:918
const Self & remove(entity_t entity) const
Remove an entity from an entity.
Definition builder.hpp:312
const Self & assign(Second constant, const First &value) const
Assign a pair for an entity.
Definition builder.hpp:1008
const Self & set_auto_override(flecs::entity_t second, First &&val) const
Set pair, mark component for auto-overriding.
Definition builder.hpp:483
const Self & set(A &&value) const
Set a component for an entity.
Definition builder.hpp:732
const Self & enable(flecs::id_t id, bool toggle=true) const
Enable an id.
Definition builder.hpp:580
const Self & child_of(entity_t second) const
Shortcut for add(ChildOf, entity).
Definition builder.hpp:230
const Self & set(T &&value) const
Set a component for an entity.
Definition builder.hpp:705
const Self & depends_on(entity_t second) const
Shortcut for add(DependsOn, entity).
Definition builder.hpp:238
const Self & depends_on() const
Shortcut for add(DependsOn, entity).
Definition builder.hpp:285
const Self & auto_override(flecs::id_t id) const
Mark id for auto-overriding.
Definition builder.hpp:381
const Self & set(const A &value) const
Set a pair for an entity.
Definition builder.hpp:776
const Self & disable() const
Disable a pair.
Definition builder.hpp:678
const Self & auto_override(flecs::entity_t first, flecs::entity_t second) const
Mark pair for auto-overriding.
Definition builder.hpp:391
const Self & auto_override() const
Mark pair for auto-overriding.
Definition builder.hpp:423
const Self & slot_of() const
Shortcut for add(SlotOf, entity).
Definition builder.hpp:294
const Self & add() const
Add a component to an entity.
Definition builder.hpp:25
const Self & auto_override_second(flecs::entity_t first) const
Mark pair for auto-overriding.
Definition builder.hpp:434
const Self & assign_second(entity_t first, const Second &value) const
Assign a pair for an entity.
Definition builder.hpp:1023
const Self & add(Second second) const
Add a pair.
Definition builder.hpp:90
const Self & set_auto_override(const A &val) const
Set component, mark component for auto-overriding.
Definition builder.hpp:497
const Self & with(const Func &func) const
Entities created in function will have the current entity.
Definition builder.hpp:1131
const Self & set_second(entity_t first, const Second &value) const
Set a pair for an entity.
Definition builder.hpp:837
flecs::string_view name() const
Return the entity name.
flecs::entity target(int32_t index=0) const
Get target for a given pair.
Definition impl.hpp:36
Entity.
Definition entity.hpp:30
flecs::entity second() const
Get second element from a pair.
Definition impl.hpp:31
flecs::entity first() const
Get first element from a pair.
Definition impl.hpp:20
Type that represents a pair.
Definition pair.hpp:36
Scoped world.
Definition world.hpp:1446