Flecs: include/flecs/addons/cpp/world.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
world.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8namespace flecs
9{
10
11/* Static helper functions to assign a component value */
12
13// set(T&&)
14template <typename T>
15 inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
16 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
17 "operation invalid for empty type");
18
19 ecs_cpp_get_mut_t res = ecs_cpp_set(world, entity, id, &value, sizeof(T));
20
21 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
22 if constexpr (std::is_copy_assignable_v<T>) {
23 dst = FLECS_FWD(value);
24 } else {
25 dst = FLECS_MOV(value);
26 }
27
28 if (res.call_modified) {
29 ecs_modified_id(world, entity, id);
30 }
31}
32
33// set(const T&)
34 template <typename T>
35inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
36 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
37 "operation invalid for empty type");
38
39 ecs_cpp_get_mut_t res = ecs_cpp_set(world, entity, id, &value, sizeof(T));
40
41 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
42 dst = value;
43
44 if (res.call_modified) {
45 ecs_modified_id(world, entity, id);
46 }
47}
48
49// set(T&&)
50template <typename T, typename A>
51inline void set(world_t *world, entity_t entity, A&& value) {
52 id_t id = _::type<T>::id(world);
53 flecs::set(world, entity, FLECS_FWD(value), id);
54}
55
56// set(const T&)
57template <typename T, typename A>
58inline void set(world_t *world, entity_t entity, const A& value) {
59 id_t id = _::type<T>::id(world);
60 flecs::set(world, entity, value, id);
61}
62
63// assign(T&&)
64template <typename T>
65inline void assign(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
66 ecs_assert(_::type<remove_reference_t<T>>::size() != 0,
67 ECS_INVALID_PARAMETER, "operation invalid for empty type");
68
69 ecs_cpp_get_mut_t res = ecs_cpp_assign(
70 world, entity, id, &value, sizeof(T));
71
72 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
73 if constexpr (std::is_copy_assignable_v<T>) {
74 dst = FLECS_FWD(value);
75 } else {
76 dst = FLECS_MOV(value);
77 }
78
79 if (res.call_modified) {
80 ecs_modified_id(world, entity, id);
81 }
82}
83
84// assign(const T&)
85template <typename T>
86inline void assign(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
87 ecs_assert(_::type<remove_reference_t<T>>::size() != 0,
88 ECS_INVALID_PARAMETER, "operation invalid for empty type");
89
90 ecs_cpp_get_mut_t res = ecs_cpp_assign(
91 world, entity, id, &value, sizeof(T));
92
93 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
94 dst = value;
95
96 if (res.call_modified) {
97 ecs_modified_id(world, entity, id);
98 }
99}
100
101// set(T&&)
102template <typename T, typename A>
103inline void assign(world_t *world, entity_t entity, A&& value) {
104 id_t id = _::type<T>::id(world);
105 flecs::assign(world, entity, FLECS_FWD(value), id);
106}
107
108// set(const T&)
109template <typename T, typename A>
110inline void assign(world_t *world, entity_t entity, const A& value) {
111 id_t id = _::type<T>::id(world);
112 flecs::assign(world, entity, value, id);
113}
114
115
116// emplace for T(Args...)
117template <typename T, typename ... Args, if_t<
118 std::is_constructible<actual_type_t<T>, Args...>::value ||
119 std::is_default_constructible<actual_type_t<T>>::value > = 0>
120inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
121 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
122 "operation invalid for empty type");
123 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id, sizeof(T), nullptr));
124
125 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
126
127 ecs_modified_id(world, entity, id);
128}
129
134 inline flecs::id_t strip_generation(flecs::entity_t e) {
135 return ecs_strip_generation(e);
136}
137
140 inline uint32_t get_generation(flecs::entity_t e) {
141 return ECS_GENERATION(e);
142}
143
144struct scoped_world;
145
153
158 struct world {
161 explicit world()
162 : world_( ecs_init() ) {
163 init_builtin_components();
164 }
165
170 explicit world(int argc, char *argv[])
171 : world_( ecs_init_w_args(argc, argv) ) {
172 init_builtin_components();
173 }
174
177 explicit world(world_t *w)
178 : world_( w ) {
179 if (w) {
180 flecs_poly_claim(w);
181 }
182 }
183
186 world(const world& obj) {
187 this->world_ = obj.world_;
188 flecs_poly_claim(this->world_);
189 }
190
191 world& operator=(const world& obj) noexcept {
192 release();
193 this->world_ = obj.world_;
194 flecs_poly_claim(this->world_);
195 return *this;
196 }
197
198 world(world&& obj) noexcept {
199 world_ = obj.world_;
200 obj.world_ = nullptr;
201 }
202
203 world& operator=(world&& obj) noexcept {
204 release();
205 world_ = obj.world_;
206 obj.world_ = nullptr;
207 return *this;
208 }
209
210 /* Releases the underlying world object. If this is the last handle, the world
211 will be finalized. */
212 void release() {
213 if (world_) {
214 if (!flecs_poly_release(world_)) {
215 if (ecs_stage_get_id(world_) == -1) {
216 ecs_stage_free(world_);
217 } else {
218 // before we call ecs_fini(), we increment the reference count back to 1
219 // otherwise, copies of this object created during ecs_fini (e.g. a component on_remove hook)
220 // would call again this destructor and ecs_fini().
221 flecs_poly_claim(world_);
222 ecs_fini(world_);
223 }
224 }
225 world_ = nullptr;
226 }
227 }
228
229 ~world() {
230 release();
231 }
232
233 /* Implicit conversion to world_t* */
234 operator world_t*() const { return world_; }
235
243 void make_owner() {
244 flecs_poly_release(world_);
245 }
246
248 void reset() {
249 /* Make sure there's only one reference to the world */
250 ecs_assert(flecs_poly_refcount(world_) == 1, ECS_INVALID_OPERATION,
251 "reset would invalidate other handles");
252 ecs_fini(world_);
253 world_ = ecs_init();
254 }
255
258 world_t* c_ptr() const {
259 return world_;
260 }
261
265 void quit() const {
266 ecs_quit(world_);
267 }
268
271 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
272 ecs_atfini(world_, action, ctx);
273 }
274
277 bool should_quit() const {
278 return ecs_should_quit(world_);
279 }
280
302 ecs_ftime_t frame_begin(float delta_time = 0) const {
303 return ecs_frame_begin(world_, delta_time);
304 }
305
315 void frame_end() const {
316 ecs_frame_end(world_);
317 }
318
329 bool readonly_begin(bool multi_threaded = false) const {
330 return ecs_readonly_begin(world_, multi_threaded);
331 }
332
339 void readonly_end() const {
340 ecs_readonly_end(world_);
341 }
342
359 bool defer_begin() const {
360 return ecs_defer_begin(world_);
361 }
362
378 bool defer_end() const {
379 return ecs_defer_end(world_);
380 }
381
394 bool is_deferred() const {
395 return ecs_is_deferred(world_);
396 }
397
410 bool is_defer_suspended() const {
411 return ecs_is_defer_suspended(world_);
412 }
413
429 void set_stage_count(int32_t stages) const {
430 ecs_set_stage_count(world_, stages);
431 }
432
441 int32_t get_stage_count() const {
442 return ecs_get_stage_count(world_);
443 }
444
451 int32_t get_stage_id() const {
452 return ecs_stage_get_id(world_);
453 }
454
461 bool is_stage() const {
462 ecs_assert(
463 flecs_poly_is(world_, ecs_world_t) ||
464 flecs_poly_is(world_, ecs_stage_t),
465 ECS_INVALID_PARAMETER,
466 "flecs::world instance contains invalid reference to world or stage");
467 return flecs_poly_is(world_, ecs_stage_t);
468 }
469
480 void merge() const {
481 ecs_merge(world_);
482 }
483
498 flecs::world get_stage(int32_t stage_id) const {
499 return flecs::world(ecs_get_stage(world_, stage_id));
500 }
501
517 flecs::world async_stage() const {
518 ecs_world_t *as = ecs_stage_new(world_);
519 flecs_poly_release(as); // world object will claim
520 return flecs::world(as);
521 }
522
529 flecs::world get_world() const {
530 /* Safe cast, mutability is checked */
531 return flecs::world(
532 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
533 }
534
545 bool is_readonly() const {
546 return ecs_stage_is_readonly(world_);
547 }
548
560 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
561 ecs_set_ctx(world_, ctx, ctx_free);
562 }
563
573 void* get_ctx() const {
574 return ecs_get_ctx(world_);
575 }
576
588 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
589 ecs_set_binding_ctx(world_, ctx, ctx_free);
590 }
591
601 void* get_binding_ctx() const {
602 return ecs_get_binding_ctx(world_);
603 }
604
612 void dim(int32_t entity_count) const {
613 ecs_dim(world_, entity_count);
614 }
615
624 void set_entity_range(entity_t min, entity_t max) const {
625 ecs_set_entity_range(world_, min, max);
626 }
627
638 void enable_range_check(bool enabled = true) const {
639 ecs_enable_range_check(world_, enabled);
640 }
641
650 flecs::entity set_scope(const flecs::entity_t scope) const;
651
659 flecs::entity get_scope() const;
660
666 template <typename T>
667 flecs::entity set_scope() const;
668
674 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
675 return ecs_set_lookup_path(world_, search_path);
676 }
677
684 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
685
688 template <typename T, if_t< !is_callable<T>::value > = 0>
689 void set(const T& value) const {
690 flecs::set<T>(world_, _::type<T>::id(world_), value);
691 }
692
695 template <typename T, if_t< !is_callable<T>::value > = 0>
696 void set(T&& value) const {
697 flecs::set<T>(world_, _::type<T>::id(world_),
698 FLECS_FWD(value));
699 }
700
703 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
704 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
705 void set(const A& value) const {
706 flecs::set<P>(world_, _::type<First>::id(world_), value);
707 }
708
711 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
712 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
713 void set(A&& value) const {
714 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
715 }
716
719 template <typename First, typename Second>
720 void set(Second second, const First& value) const;
721
724 template <typename First, typename Second>
725 void set(Second second, First&& value) const;
726
729 template <typename Func, if_t< is_callable<Func>::value > = 0 >
730 void set(const Func& func) const;
731
732 template <typename T, typename ... Args>
733 void emplace(Args&&... args) const {
734 flecs::id_t component_id = _::type<T>::id(world_);
735 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
736 }
737
740 #ifndef ensure
741 template <typename T>
742 T& ensure() const;
743 #endif
744
747 template <typename T>
748 void modified() const;
749
752 template <typename T>
753 ref<T> get_ref() const;
754
755
756 /* try_get */
757
760 const void* try_get(flecs::id_t id) const;
761
764 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
765
768 template <typename T>
769 const T* try_get() const;
770
773 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
774 typename A = actual_type_t<P>>
775 const A* try_get() const;
776
779 template <typename First, typename Second>
780 const First* try_get(Second second) const;
781
782
783 /* get */
784
787 const void* get(flecs::id_t id) const;
788
791 const void* get(flecs::entity_t r, flecs::entity_t t) const;
792
793 template <typename T>
794 const T& get() const;
795
798 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
799 typename A = actual_type_t<P>>
800 const A& get() const;
801
804 template <typename First, typename Second>
805 const First& get(Second second) const;
806
809 template <typename Func, if_t< is_callable<Func>::value > = 0 >
810 void get(const Func& func) const;
811
812
813 /* try_get_mut */
814
817 void* try_get_mut(flecs::id_t id) const;
818
821 void* try_get_mut(flecs::entity_t r, flecs::entity_t t) const;
822
823 template <typename T>
824 T* try_get_mut() const;
825
828 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
829 typename A = actual_type_t<P>>
830 A* try_get_mut() const;
831
834 template <typename First, typename Second>
835 First* try_get_mut(Second second) const;
836
837
838 /* get_mut */
839
842 void* get_mut(flecs::id_t id) const;
843
846 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
847
848 template <typename T>
849 T& get_mut() const;
850
853 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
854 typename A = actual_type_t<P>>
855 A& get_mut() const;
856
859 template <typename First, typename Second>
860 First& get_mut(Second second) const;
861
862
868 template <typename T>
869 bool has() const;
870
877 template <typename First, typename Second>
878 bool has() const;
879
886 template <typename First>
887 bool has(flecs::id_t second) const;
888
895 bool has(flecs::id_t first, flecs::id_t second) const;
896
903 template <typename E, if_t< is_enum<E>::value > = 0>
904 bool has(E value) const;
905
908 template <typename T>
909 void add() const;
910
916 template <typename First, typename Second>
917 void add() const;
918
924 template <typename First>
925 void add(flecs::entity_t second) const;
926
932 void add(flecs::entity_t first, flecs::entity_t second) const;
933
939 template <typename E, if_t< is_enum<E>::value > = 0>
940 void add(E value) const;
941
944 template <typename T>
945 void remove() const;
946
952 template <typename First, typename Second>
953 void remove() const;
954
960 template <typename First>
961 void remove(flecs::entity_t second) const;
962
968 void remove(flecs::entity_t first, flecs::entity_t second) const;
969
977 template <typename Func>
978 void children(Func&& f) const;
979
982 template <typename T>
983 flecs::entity singleton() const;
984
993 template<typename First>
994 flecs::entity target(int32_t index = 0) const;
995
1004 template<typename T>
1005 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1006
1015 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1016
1023 template <typename T>
1024 flecs::entity use(const char *alias = nullptr) const;
1025
1031 flecs::entity use(const char *name, const char *alias = nullptr) const;
1032
1038 void use(flecs::entity entity, const char *alias = nullptr) const;
1039
1044 int count(flecs::id_t component_id) const {
1045 return ecs_count_id(world_, component_id);
1046 }
1047
1053 int count(flecs::entity_t first, flecs::entity_t second) const {
1054 return ecs_count_id(world_, ecs_pair(first, second));
1055 }
1056
1061 template <typename T>
1062 int count() const {
1063 return count(_::type<T>::id(world_));
1064 }
1065
1071 template <typename First>
1072 int count(flecs::entity_t second) const {
1073 return count(_::type<First>::id(world_), second);
1074 }
1075
1081 template <typename First, typename Second>
1082 int count() const {
1083 return count(
1084 _::type<First>::id(world_),
1085 _::type<Second>::id(world_));
1086 }
1087
1090 template <typename Func>
1091 void with(id_t with_id, const Func& func) const {
1092 ecs_id_t prev = ecs_set_with(world_, with_id);
1093 func();
1094 ecs_set_with(world_, prev);
1095 }
1096
1099 template <typename T, typename Func>
1100 void with(const Func& func) const {
1101 with(this->id<T>(), func);
1102 }
1103
1106 template <typename First, typename Second, typename Func>
1107 void with(const Func& func) const {
1108 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
1109 }
1110
1113 template <typename First, typename Func>
1114 void with(id_t second, const Func& func) const {
1115 with(ecs_pair(this->id<First>(), second), func);
1116 }
1117
1120 template <typename Func>
1121 void with(id_t first, id_t second, const Func& func) const {
1122 with(ecs_pair(first, second), func);
1123 }
1124
1128 template <typename Func>
1129 void scope(id_t parent, const Func& func) const {
1130 ecs_entity_t prev = ecs_set_scope(world_, parent);
1131 func();
1132 ecs_set_scope(world_, prev);
1133 }
1134
1137 template <typename T, typename Func>
1138 void scope(const Func& func) const {
1139 flecs::id_t parent = _::type<T>::id(world_);
1140 scope(parent, func);
1141 }
1142
1146 flecs::scoped_world scope(id_t parent) const;
1147
1148 template <typename T>
1149 flecs::scoped_world scope() const;
1150
1151 flecs::scoped_world scope(const char* name) const;
1152
1154 void delete_with(id_t the_id) const {
1155 ecs_delete_with(world_, the_id);
1156 }
1157
1159 void delete_with(entity_t first, entity_t second) const {
1160 delete_with(ecs_pair(first, second));
1161 }
1162
1164 template <typename T>
1165 void delete_with() const {
1166 delete_with(_::type<T>::id(world_));
1167 }
1168
1170 template <typename First, typename Second>
1171 void delete_with() const {
1172 delete_with(_::type<First>::id(world_), _::type<Second>::id(world_));
1173 }
1174
1176 template <typename First>
1177 void delete_with(entity_t second) const {
1178 delete_with(_::type<First>::id(world_), second);
1179 }
1180
1182 void remove_all(id_t the_id) const {
1183 ecs_remove_all(world_, the_id);
1184 }
1185
1187 void remove_all(entity_t first, entity_t second) const {
1188 remove_all(ecs_pair(first, second));
1189 }
1190
1192 template <typename T>
1193 void remove_all() const {
1194 remove_all(_::type<T>::id(world_));
1195 }
1196
1198 template <typename First, typename Second>
1199 void remove_all() const {
1200 remove_all(_::type<First>::id(world_), _::type<Second>::id(world_));
1201 }
1202
1204 template <typename First>
1205 void remove_all(entity_t second) const {
1206 remove_all(_::type<First>::id(world_), second);
1207 }
1208
1217 template <typename Func>
1218 void defer(const Func& func) const {
1219 ecs_defer_begin(world_);
1220 func();
1221 ecs_defer_end(world_);
1222 }
1223
1233 void defer_suspend() const {
1234 ecs_defer_suspend(world_);
1235 }
1236
1246 void defer_resume() const {
1247 ecs_defer_resume(world_);
1248 }
1249
1256 bool exists(flecs::entity_t e) const {
1257 return ecs_exists(world_, e);
1258 }
1259
1266 bool is_alive(flecs::entity_t e) const {
1267 return ecs_is_alive(world_, e);
1268 }
1269
1277 bool is_valid(flecs::entity_t e) const {
1278 return ecs_is_valid(world_, e);
1279 }
1280
1286 flecs::entity get_alive(flecs::entity_t e) const;
1287
1291 flecs::entity make_alive(flecs::entity_t e) const;
1292
1297 void set_version(flecs::entity_t e) const {
1298 ecs_set_version(world_, e);
1299 }
1300
1301 /* Run callback after completing frame */
1302 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1303 ecs_run_post_frame(world_, action, ctx);
1304 }
1305
1310 const flecs::world_info_t* get_info() const{
1311 return ecs_get_world_info(world_);
1312 }
1313
1315 ecs_ftime_t delta_time() const {
1316 return get_info()->delta_time;
1317 }
1318
1323 void shrink() const {
1324 ecs_shrink(world_);
1325 }
1326
1332 void exclusive_access_begin(const char *thread_name = nullptr) {
1333 ecs_exclusive_access_begin(world_, thread_name);
1334 }
1335
1341 void exclusive_access_end(bool lock_world = false) {
1342 ecs_exclusive_access_end(world_, lock_world);
1343 }
1344
1351 template <typename T>
1352 flecs::id_t id_if_registered() {
1353 if (_::type<T>::registered(world_)) {
1354 return _::type<T>::id(world_);
1355 }
1356 else {
1357 return 0;
1358 }
1359 }
1360
1362 const flecs::type_info_t* type_info(flecs::id_t component) {
1363 return ecs_get_type_info(world_, component);
1364 }
1365
1367 const flecs::type_info_t* type_info(flecs::entity_t r, flecs::entity_t t) {
1368 return ecs_get_type_info(world_, ecs_pair(r, t));
1369 }
1370
1372 template <typename T>
1373 const flecs::type_info_t* type_info() {
1374 return ecs_get_type_info(world_, _::type<T>::id(world_));
1375 }
1376
1378 template <typename R>
1379 const flecs::type_info_t* type_info(flecs::entity_t t) {
1380 return type_info(_::type<R>::id(world_), t);
1381 }
1382
1384 template <typename R, typename T>
1385 const flecs::type_info_t* type_info() {
1386 return type_info<R>(_::type<T>::id(world_));
1387 }
1388
1389# include "mixins/id/mixin.inl"
1390# include "mixins/component/mixin.inl"
1391# include "mixins/entity/mixin.inl"
1392# include "mixins/event/mixin.inl"
1393# include "mixins/term/mixin.inl"
1394# include "mixins/observer/mixin.inl"
1395# include "mixins/query/mixin.inl"
1396# include "mixins/enum/mixin.inl"
1397
1398# ifdef FLECS_MODULE
1399# include "mixins/module/mixin.inl"
1400# endif
1401# ifdef FLECS_PIPELINE
1402# include "mixins/pipeline/mixin.inl"
1403# endif
1404# ifdef FLECS_SYSTEM
1405# include "mixins/system/mixin.inl"
1406# endif
1407# ifdef FLECS_TIMER
1408# include "mixins/timer/mixin.inl"
1409# endif
1410# ifdef FLECS_SCRIPT
1411# include "mixins/script/mixin.inl"
1412# endif
1413# ifdef FLECS_META
1414# include "mixins/meta/world.inl"
1415# endif
1416# ifdef FLECS_JSON
1417# include "mixins/json/world.inl"
1418# endif
1419# ifdef FLECS_APP
1420# include "mixins/app/mixin.inl"
1421# endif
1422# ifdef FLECS_METRICS
1423# include "mixins/metrics/mixin.inl"
1424# endif
1425# ifdef FLECS_ALERTS
1426# include "mixins/alerts/mixin.inl"
1427# endif
1428
1429public:
1430 void init_builtin_components();
1431
1432 world_t *world_;
1433};
1434
1438 struct scoped_world : world {
1439 scoped_world(
1440 flecs::world_t *w,
1441 flecs::entity_t s) : world(w)
1442 {
1443 prev_scope_ = ecs_set_scope(w, s);
1444 }
1445
1446 ~scoped_world() {
1447 ecs_set_scope(world_, prev_scope_);
1448 }
1449
1450 scoped_world(const scoped_world& obj) : world(nullptr) {
1451 prev_scope_ = obj.prev_scope_;
1452 world_ = obj.world_;
1453 flecs_poly_claim(world_);
1454 }
1455
1456 flecs::entity_t prev_scope_;
1457};
1458
1460
1461} // namespace flecs
mixin.inl
App world addon mixin.
mixin.inl
Component mixin.
mixin.inl
Entity world mixin.
mixin.inl
Enum world mixin.
mixin.inl
Event world mixin.
ecs_remove_all
void ecs_remove_all(ecs_world_t *world, ecs_id_t component)
Remove all instances of the specified component.
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_stage_new
ecs_world_t * ecs_stage_new(ecs_world_t *world)
Create unmanaged stage.
ecs_defer_end
bool ecs_defer_end(ecs_world_t *world)
End block of operations to defer.
ecs_readonly_begin
bool ecs_readonly_begin(ecs_world_t *world, bool multi_threaded)
Begin readonly mode.
ecs_defer_resume
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
ecs_defer_begin
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until end of frame.
ecs_defer_suspend
void ecs_defer_suspend(ecs_world_t *world)
Suspend deferring but do not flush queue.
ecs_is_deferred
bool ecs_is_deferred(const ecs_world_t *world)
Test if deferring is enabled for current stage.
ecs_stage_free
void ecs_stage_free(ecs_world_t *stage)
Free unmanaged stage.
ecs_merge
void ecs_merge(ecs_world_t *stage)
Merge stage.
ecs_stage_get_id
int32_t ecs_stage_get_id(const ecs_world_t *world)
Get stage id.
ecs_stage_is_readonly
bool ecs_stage_is_readonly(const ecs_world_t *world)
Test whether the current world is readonly.
ecs_get_stage_count
int32_t ecs_get_stage_count(const ecs_world_t *world)
Get number of configured stages.
ecs_get_stage
ecs_world_t * ecs_get_stage(const ecs_world_t *world, int32_t stage_id)
Get stage-specific world pointer.
ecs_set_stage_count
void ecs_set_stage_count(ecs_world_t *world, int32_t stages)
Configure world to have N stages.
ecs_readonly_end
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
ecs_is_defer_suspended
bool ecs_is_defer_suspended(const ecs_world_t *world)
Test if deferring is suspended for current stage.
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_stage_t
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition flecs.h:408
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:361
ecs_world_t
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:405
ecs_id_t
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:354
flecs::world::component
flecs::component< T > component(Args &&... args) const
Find or register component.
Definition impl.hpp:11
flecs::world::entity
flecs::entity entity(Args &&... args) const
Create an entity.
Definition impl.hpp:190
ecs_delete_with
void ecs_delete_with(ecs_world_t *world, ecs_id_t component)
Delete all entities with the specified component.
ecs_count_id
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified id.
ecs_fini_action_t
void(* ecs_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
Definition flecs.h:620
ecs_ctx_free_t
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:625
ecs_emplace_id
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, size_t size, bool *is_new)
Emplace a component.
ecs_modified_id
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Signal that a component has been modified.
ecs_strip_generation
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove generation from entity id.
ecs_is_valid
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
ecs_exists
bool ecs_exists(const ecs_world_t *world, ecs_entity_t entity)
Test whether an entity exists.
ecs_is_alive
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
ecs_set_version
void ecs_set_version(ecs_world_t *world, ecs_entity_t entity)
Override the generation of an entity.
ecs_ftime_t
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
ecs_set_lookup_path
ecs_entity_t * ecs_set_lookup_path(ecs_world_t *world, const ecs_entity_t *lookup_path)
Set search path for lookup operations.
ecs_set_scope
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
ecs_atfini
void ecs_atfini(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed when world is destroyed.
ecs_fini
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_init
ecs_world_t * ecs_init(void)
Create a new world.
ecs_init_w_args
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
ecs_frame_begin
float ecs_frame_begin(ecs_world_t *world, float delta_time)
Begin frame.
ecs_run_post_frame
void ecs_run_post_frame(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed once after frame.
ecs_should_quit
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been requested.
ecs_quit
void ecs_quit(ecs_world_t *world)
Signal exit This operation signals that the application should quit.
ecs_frame_end
void ecs_frame_end(ecs_world_t *world)
End frame.
ecs_get_binding_ctx
void * ecs_get_binding_ctx(const ecs_world_t *world)
Get the world binding context.
ecs_shrink
void ecs_shrink(ecs_world_t *world)
Free unused memory.
ecs_dim
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
ecs_set_entity_range
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issuing new entity ids.
ecs_get_world_info
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
ecs_get_world
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
ecs_set_ctx
void ecs_set_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world context.
ecs_exclusive_access_begin
void ecs_exclusive_access_begin(ecs_world_t *world, const char *thread_name)
Begin exclusive thread access.
ecs_set_binding_ctx
void ecs_set_binding_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world binding context.
flecs_poly_is
#define flecs_poly_is(object, type)
Test if pointer is of specified type.
Definition flecs.h:2743
ecs_enable_range_check
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
ecs_exclusive_access_end
void ecs_exclusive_access_end(ecs_world_t *world, bool lock_world)
End exclusive thread access.
ecs_get_ctx
void * ecs_get_ctx(const ecs_world_t *world)
Get the world context.
mixin.inl
Id world mixin.
world.inl
JSON world mixin.
world.inl
Meta world mixin.
mixin.inl
Module world mixin.
mixin.inl
Observer world mixin.
mixin.inl
Pipeline world mixin.
mixin.inl
Query world mixin.
mixin.inl
Script world mixin.
ecs_world_info_t::delta_time
float delta_time
Time passed to or computed by ecs_progress().
Definition flecs.h:1455
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::scoped_world
Scoped world.
Definition world.hpp:1438
flecs::world
The world.
Definition world.hpp:158
flecs::world::is_stage
bool is_stage() const
Test if is a stage.
Definition world.hpp:461
flecs::world::shrink
void shrink() const
Free unused memory.
Definition world.hpp:1323
flecs::world::delete_with
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1165
flecs::world::remove_all
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:1182
flecs::world::delete_with
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1177
flecs::world::merge
void merge() const
Merge world or stage.
Definition world.hpp:480
flecs::world::delete_with
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1154
flecs::world::get_info
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1310
flecs::world::get_scope
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:84
flecs::world::remove
void remove() const
Remove singleton component.
Definition world.hpp:301
flecs::world::lookup
flecs::entity lookup(const char *name, const char *sep="::", const char *root_sep="::", bool recursive=true) const
Lookup entity by name.
Definition world.hpp:93
flecs::world::set
void set(A &&value) const
Set singleton pair.
Definition world.hpp:713
flecs::world::delta_time
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1315
flecs::world::quit
void quit() const
Signal application should quit.
Definition world.hpp:265
flecs::world::get_alive
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition world.hpp:371
flecs::world::type_info
const flecs::type_info_t * type_info()
Return type info.
Definition world.hpp:1373
flecs::world::set_entity_range
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:624
flecs::world::readonly_end
void readonly_end() const
End readonly mode.
Definition world.hpp:339
flecs::world::with
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:1107
flecs::world::make_alive
flecs::entity make_alive(flecs::entity_t e) const
Definition world.hpp:376
flecs::world::count
int count() const
Count entities matching a component.
Definition world.hpp:1062
flecs::world::id
flecs::id id() const
Get id from a type.
Definition impl.hpp:70
flecs::world::exclusive_access_begin
void exclusive_access_begin(const char *thread_name=nullptr)
Begin exclusive access.
Definition world.hpp:1332
flecs::world::target
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:334
flecs::world::get
const A & get() const
Get singleton pair.
Definition world.hpp:175
flecs::world::defer
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:1218
flecs::world::should_quit
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:277
flecs::world::is_alive
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1266
flecs::world::c_ptr
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:258
flecs::world::try_get
const T * try_get() const
Get singleton component.
Definition world.hpp:141
flecs::world::defer_begin
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:359
flecs::world::reset
void reset()
Deletes and recreates the world.
Definition world.hpp:248
flecs::world::set_lookup_path
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:674
flecs::world::defer_suspend
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1233
flecs::world::set
void set(const A &value) const
Set singleton pair.
Definition world.hpp:705
flecs::world::make_owner
void make_owner()
Make current world object owner of the world.
Definition world.hpp:243
flecs::world::is_valid
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1277
flecs::world::async_stage
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:517
flecs::world::is_deferred
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:394
flecs::world::get_binding_ctx
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:601
flecs::world::get_stage_id
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:451
flecs::world::world
world(const world &obj)
Not allowed to copy a world.
Definition world.hpp:186
flecs::world::scope
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:1138
flecs::world::defer_resume
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1246
flecs::world::set_scope
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:89
flecs::world::dim
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition world.hpp:612
flecs::world::set_version
void set_version(flecs::entity_t e) const
Set version of entity to provided.
Definition world.hpp:1297
flecs::world::try_get_mut
A * try_get_mut() const
Get mutable singleton pair.
Definition world.hpp:203
flecs::world::set_stage_count
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:429
flecs::world::with
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:1091
flecs::world::get_ctx
void * get_ctx() const
Get world context.
Definition world.hpp:573
flecs::world::type_info
const flecs::type_info_t * type_info(flecs::entity_t r, flecs::entity_t t)
Return type info.
Definition world.hpp:1367
flecs::world::count
int count() const
Count entities matching a pair.
Definition world.hpp:1082
flecs::world::remove_all
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1199
flecs::world::defer_end
bool defer_end() const
End block of operations to defer.
Definition world.hpp:378
flecs::world::count
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1053
flecs::world::remove_all
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1205
flecs::world::world
world(world_t *w)
Create world from C world.
Definition world.hpp:177
flecs::world::children
void children(Func &&f) const
Iterate entities in root of world Accepts a callback with the following signature:
Definition world.hpp:324
flecs::world::get_world
flecs::world get_world() const
Get actual world.
Definition world.hpp:529
flecs::world::scope
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:1129
flecs::world::with
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:1100
flecs::world::remove_all
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1187
flecs::world::modified
void modified() const
Mark singleton component as modified.
Definition world.hpp:107
flecs::world::enable_range_check
void enable_range_check(bool enabled=true) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:638
flecs::world::count
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1072
flecs::world::id_if_registered
flecs::id_t id_if_registered()
Return component id if it has been registered.
Definition world.hpp:1352
flecs::world::frame_begin
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:302
flecs::world::use
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition world.hpp:51
flecs::world::is_readonly
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:545
flecs::world::add
void add() const
Add singleton component.
Definition world.hpp:272
flecs::world::ensure
T & ensure() const
Ensure singleton component.
Definition world.hpp:100
flecs::world::readonly_begin
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:329
flecs::world::get_mut
A & get_mut() const
Get mutable singleton pair.
Definition world.hpp:231
flecs::world::set
void set(const T &value) const
Set singleton component.
Definition world.hpp:689
flecs::world::with
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:1121
flecs::world::get_stage
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:498
flecs::world::set
void set(T &&value) const
Set singleton component.
Definition world.hpp:696
flecs::world::has
bool has() const
Test if world has singleton component.
Definition world.hpp:243
flecs::world::exists
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1256
flecs::world::world
world()
Create world.
Definition world.hpp:161
flecs::world::frame_end
void frame_end() const
End frame.
Definition world.hpp:315
flecs::world::set_binding_ctx
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:588
flecs::world::atfini
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:271
flecs::world::type_info
const flecs::type_info_t * type_info(flecs::id_t component)
Return type info.
Definition world.hpp:1362
flecs::world::get_stage_count
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:441
flecs::world::delete_with
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1159
flecs::world::delete_with
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1171
flecs::world::singleton
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:329
flecs::world::exclusive_access_end
void exclusive_access_end(bool lock_world=false)
End exclusive access.
Definition world.hpp:1341
flecs::world::with
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:1114
flecs::world::set_ctx
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:560
flecs::world::is_defer_suspended
bool is_defer_suspended() const
Test whether deferring is suspended.
Definition world.hpp:410
flecs::world::world
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:170
flecs::world::count
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:1044
flecs::world::type_info
const flecs::type_info_t * type_info()
Return type info.
Definition world.hpp:1385
flecs::world::type_info
const flecs::type_info_t * type_info(flecs::entity_t t)
Return type info.
Definition world.hpp:1379
flecs::world::remove_all
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1193
flecs::world::get_ref
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:125
mixin.inl
System module world mixin.
mixin.inl
Term world mixin.
mixin.inl
Timer module mixin.
flecs::strip_generation
flecs::id_t strip_generation(flecs::entity_t e)
Return id without generation.
Definition world.hpp:134
flecs::get_generation
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:140