Flecs: include/flecs/addons/cpp/world.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
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
358 bool defer_begin() const {
359 return ecs_defer_begin(world_);
360 }
361
376 bool defer_end() const {
377 return ecs_defer_end(world_);
378 }
379
391 bool is_deferred() const {
392 return ecs_is_deferred(world_);
393 }
394
410 void set_stage_count(int32_t stages) const {
411 ecs_set_stage_count(world_, stages);
412 }
413
422 int32_t get_stage_count() const {
423 return ecs_get_stage_count(world_);
424 }
425
432 int32_t get_stage_id() const {
433 return ecs_stage_get_id(world_);
434 }
435
442 bool is_stage() const {
443 ecs_assert(
444 flecs_poly_is(world_, ecs_world_t) ||
445 flecs_poly_is(world_, ecs_stage_t),
446 ECS_INVALID_PARAMETER,
447 "flecs::world instance contains invalid reference to world or stage");
448 return flecs_poly_is(world_, ecs_stage_t);
449 }
450
461 void merge() const {
462 ecs_merge(world_);
463 }
464
479 flecs::world get_stage(int32_t stage_id) const {
480 return flecs::world(ecs_get_stage(world_, stage_id));
481 }
482
498 flecs::world async_stage() const {
499 ecs_world_t *as = ecs_stage_new(world_);
500 flecs_poly_release(as); // world object will claim
501 return flecs::world(as);
502 }
503
510 flecs::world get_world() const {
511 /* Safe cast, mutability is checked */
512 return flecs::world(
513 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
514 }
515
526 bool is_readonly() const {
527 return ecs_stage_is_readonly(world_);
528 }
529
541 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
542 ecs_set_ctx(world_, ctx, ctx_free);
543 }
544
554 void* get_ctx() const {
555 return ecs_get_ctx(world_);
556 }
557
569 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
570 ecs_set_binding_ctx(world_, ctx, ctx_free);
571 }
572
582 void* get_binding_ctx() const {
583 return ecs_get_binding_ctx(world_);
584 }
585
593 void dim(int32_t entity_count) const {
594 ecs_dim(world_, entity_count);
595 }
596
605 void set_entity_range(entity_t min, entity_t max) const {
606 ecs_set_entity_range(world_, min, max);
607 }
608
619 void enable_range_check(bool enabled = true) const {
620 ecs_enable_range_check(world_, enabled);
621 }
622
631 flecs::entity set_scope(const flecs::entity_t scope) const;
632
640 flecs::entity get_scope() const;
641
647 template <typename T>
648 flecs::entity set_scope() const;
649
655 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
656 return ecs_set_lookup_path(world_, search_path);
657 }
658
665 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
666
669 template <typename T, if_t< !is_callable<T>::value > = 0>
670 void set(const T& value) const {
671 flecs::set<T>(world_, _::type<T>::id(world_), value);
672 }
673
676 template <typename T, if_t< !is_callable<T>::value > = 0>
677 void set(T&& value) const {
678 flecs::set<T>(world_, _::type<T>::id(world_),
679 FLECS_FWD(value));
680 }
681
684 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
685 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
686 void set(const A& value) const {
687 flecs::set<P>(world_, _::type<First>::id(world_), value);
688 }
689
692 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
693 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
694 void set(A&& value) const {
695 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
696 }
697
700 template <typename First, typename Second>
701 void set(Second second, const First& value) const;
702
705 template <typename First, typename Second>
706 void set(Second second, First&& value) const;
707
710 template <typename Func, if_t< is_callable<Func>::value > = 0 >
711 void set(const Func& func) const;
712
713 template <typename T, typename ... Args>
714 void emplace(Args&&... args) const {
715 flecs::id_t component_id = _::type<T>::id(world_);
716 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
717 }
718
721 #ifndef ensure
722 template <typename T>
723 T& ensure() const;
724 #endif
725
728 template <typename T>
729 void modified() const;
730
733 template <typename T>
734 ref<T> get_ref() const;
735
736
737 /* try_get */
738
741 const void* try_get(flecs::id_t id) const;
742
745 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
746
749 template <typename T>
750 const T* try_get() const;
751
754 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
755 typename A = actual_type_t<P>>
756 const A* try_get() const;
757
760 template <typename First, typename Second>
761 const First* try_get(Second second) const;
762
763
764 /* get */
765
768 const void* get(flecs::id_t id) const;
769
772 const void* get(flecs::entity_t r, flecs::entity_t t) const;
773
774 template <typename T>
775 const T& get() const;
776
779 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
780 typename A = actual_type_t<P>>
781 const A& get() const;
782
785 template <typename First, typename Second>
786 const First& get(Second second) const;
787
790 template <typename Func, if_t< is_callable<Func>::value > = 0 >
791 void get(const Func& func) const;
792
793
794 /* try_get_mut */
795
798 void* try_get_mut(flecs::id_t id) const;
799
802 void* try_get_mut(flecs::entity_t r, flecs::entity_t t) const;
803
804 template <typename T>
805 T* try_get_mut() const;
806
809 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
810 typename A = actual_type_t<P>>
811 A* try_get_mut() const;
812
815 template <typename First, typename Second>
816 First* try_get_mut(Second second) const;
817
818
819 /* get_mut */
820
823 void* get_mut(flecs::id_t id) const;
824
827 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
828
829 template <typename T>
830 T& get_mut() const;
831
834 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
835 typename A = actual_type_t<P>>
836 A& get_mut() const;
837
840 template <typename First, typename Second>
841 First& get_mut(Second second) const;
842
843
849 template <typename T>
850 bool has() const;
851
858 template <typename First, typename Second>
859 bool has() const;
860
867 template <typename First>
868 bool has(flecs::id_t second) const;
869
876 bool has(flecs::id_t first, flecs::id_t second) const;
877
884 template <typename E, if_t< is_enum<E>::value > = 0>
885 bool has(E value) const;
886
889 template <typename T>
890 void add() const;
891
897 template <typename First, typename Second>
898 void add() const;
899
905 template <typename First>
906 void add(flecs::entity_t second) const;
907
913 void add(flecs::entity_t first, flecs::entity_t second) const;
914
920 template <typename E, if_t< is_enum<E>::value > = 0>
921 void add(E value) const;
922
925 template <typename T>
926 void remove() const;
927
933 template <typename First, typename Second>
934 void remove() const;
935
941 template <typename First>
942 void remove(flecs::entity_t second) const;
943
949 void remove(flecs::entity_t first, flecs::entity_t second) const;
950
958 template <typename Func>
959 void children(Func&& f) const;
960
963 template <typename T>
964 flecs::entity singleton() const;
965
974 template<typename First>
975 flecs::entity target(int32_t index = 0) const;
976
985 template<typename T>
986 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
987
996 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
997
1004 template <typename T>
1005 flecs::entity use(const char *alias = nullptr) const;
1006
1012 flecs::entity use(const char *name, const char *alias = nullptr) const;
1013
1019 void use(flecs::entity entity, const char *alias = nullptr) const;
1020
1025 int count(flecs::id_t component_id) const {
1026 return ecs_count_id(world_, component_id);
1027 }
1028
1034 int count(flecs::entity_t first, flecs::entity_t second) const {
1035 return ecs_count_id(world_, ecs_pair(first, second));
1036 }
1037
1042 template <typename T>
1043 int count() const {
1044 return count(_::type<T>::id(world_));
1045 }
1046
1052 template <typename First>
1053 int count(flecs::entity_t second) const {
1054 return count(_::type<First>::id(world_), second);
1055 }
1056
1062 template <typename First, typename Second>
1063 int count() const {
1064 return count(
1065 _::type<First>::id(world_),
1066 _::type<Second>::id(world_));
1067 }
1068
1071 template <typename Func>
1072 void with(id_t with_id, const Func& func) const {
1073 ecs_id_t prev = ecs_set_with(world_, with_id);
1074 func();
1075 ecs_set_with(world_, prev);
1076 }
1077
1080 template <typename T, typename Func>
1081 void with(const Func& func) const {
1082 with(this->id<T>(), func);
1083 }
1084
1087 template <typename First, typename Second, typename Func>
1088 void with(const Func& func) const {
1089 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
1090 }
1091
1094 template <typename First, typename Func>
1095 void with(id_t second, const Func& func) const {
1096 with(ecs_pair(this->id<First>(), second), func);
1097 }
1098
1101 template <typename Func>
1102 void with(id_t first, id_t second, const Func& func) const {
1103 with(ecs_pair(first, second), func);
1104 }
1105
1109 template <typename Func>
1110 void scope(id_t parent, const Func& func) const {
1111 ecs_entity_t prev = ecs_set_scope(world_, parent);
1112 func();
1113 ecs_set_scope(world_, prev);
1114 }
1115
1118 template <typename T, typename Func>
1119 void scope(const Func& func) const {
1120 flecs::id_t parent = _::type<T>::id(world_);
1121 scope(parent, func);
1122 }
1123
1127 flecs::scoped_world scope(id_t parent) const;
1128
1129 template <typename T>
1130 flecs::scoped_world scope() const;
1131
1132 flecs::scoped_world scope(const char* name) const;
1133
1135 void delete_with(id_t the_id) const {
1136 ecs_delete_with(world_, the_id);
1137 }
1138
1140 void delete_with(entity_t first, entity_t second) const {
1141 delete_with(ecs_pair(first, second));
1142 }
1143
1145 template <typename T>
1146 void delete_with() const {
1147 delete_with(_::type<T>::id(world_));
1148 }
1149
1151 template <typename First, typename Second>
1152 void delete_with() const {
1153 delete_with(_::type<First>::id(world_), _::type<Second>::id(world_));
1154 }
1155
1157 template <typename First>
1158 void delete_with(entity_t second) const {
1159 delete_with(_::type<First>::id(world_), second);
1160 }
1161
1163 void remove_all(id_t the_id) const {
1164 ecs_remove_all(world_, the_id);
1165 }
1166
1168 void remove_all(entity_t first, entity_t second) const {
1169 remove_all(ecs_pair(first, second));
1170 }
1171
1173 template <typename T>
1174 void remove_all() const {
1175 remove_all(_::type<T>::id(world_));
1176 }
1177
1179 template <typename First, typename Second>
1180 void remove_all() const {
1181 remove_all(_::type<First>::id(world_), _::type<Second>::id(world_));
1182 }
1183
1185 template <typename First>
1186 void remove_all(entity_t second) const {
1187 remove_all(_::type<First>::id(world_), second);
1188 }
1189
1198 template <typename Func>
1199 void defer(const Func& func) const {
1200 ecs_defer_begin(world_);
1201 func();
1202 ecs_defer_end(world_);
1203 }
1204
1214 void defer_suspend() const {
1215 ecs_defer_suspend(world_);
1216 }
1217
1227 void defer_resume() const {
1228 ecs_defer_resume(world_);
1229 }
1230
1237 bool exists(flecs::entity_t e) const {
1238 return ecs_exists(world_, e);
1239 }
1240
1247 bool is_alive(flecs::entity_t e) const {
1248 return ecs_is_alive(world_, e);
1249 }
1250
1258 bool is_valid(flecs::entity_t e) const {
1259 return ecs_is_valid(world_, e);
1260 }
1261
1267 flecs::entity get_alive(flecs::entity_t e) const;
1268
1272 flecs::entity make_alive(flecs::entity_t e) const;
1273
1278 void set_version(flecs::entity_t e) const {
1279 ecs_set_version(world_, e);
1280 }
1281
1282 /* Run callback after completing frame */
1283 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1284 ecs_run_post_frame(world_, action, ctx);
1285 }
1286
1291 const flecs::world_info_t* get_info() const{
1292 return ecs_get_world_info(world_);
1293 }
1294
1296 ecs_ftime_t delta_time() const {
1297 return get_info()->delta_time;
1298 }
1299
1304 void shrink() const {
1305 ecs_shrink(world_);
1306 }
1307
1313 void exclusive_access_begin(const char *thread_name = nullptr) {
1314 ecs_exclusive_access_begin(world_, thread_name);
1315 }
1316
1322 void exclusive_access_end(bool lock_world = false) {
1323 ecs_exclusive_access_end(world_, lock_world);
1324 }
1325
1332 template <typename T>
1333 flecs::id_t id_if_registered() {
1334 if (_::type<T>::registered(world_)) {
1335 return _::type<T>::id(world_);
1336 }
1337 else {
1338 return 0;
1339 }
1340 }
1341
1343 const flecs::type_info_t* type_info(flecs::id_t component) {
1344 return ecs_get_type_info(world_, component);
1345 }
1346
1348 const flecs::type_info_t* type_info(flecs::entity_t r, flecs::entity_t t) {
1349 return ecs_get_type_info(world_, ecs_pair(r, t));
1350 }
1351
1353 template <typename T>
1354 const flecs::type_info_t* type_info() {
1355 return ecs_get_type_info(world_, _::type<T>::id(world_));
1356 }
1357
1359 template <typename R>
1360 const flecs::type_info_t* type_info(flecs::entity_t t) {
1361 return type_info(_::type<R>::id(world_), t);
1362 }
1363
1365 template <typename R, typename T>
1366 const flecs::type_info_t* type_info() {
1367 return type_info<R>(_::type<T>::id(world_));
1368 }
1369
1370# include "mixins/id/mixin.inl"
1371# include "mixins/component/mixin.inl"
1372# include "mixins/entity/mixin.inl"
1373# include "mixins/event/mixin.inl"
1374# include "mixins/term/mixin.inl"
1375# include "mixins/observer/mixin.inl"
1376# include "mixins/query/mixin.inl"
1377# include "mixins/enum/mixin.inl"
1378
1379# ifdef FLECS_MODULE
1380# include "mixins/module/mixin.inl"
1381# endif
1382# ifdef FLECS_PIPELINE
1383# include "mixins/pipeline/mixin.inl"
1384# endif
1385# ifdef FLECS_SYSTEM
1386# include "mixins/system/mixin.inl"
1387# endif
1388# ifdef FLECS_TIMER
1389# include "mixins/timer/mixin.inl"
1390# endif
1391# ifdef FLECS_SCRIPT
1392# include "mixins/script/mixin.inl"
1393# endif
1394# ifdef FLECS_META
1395# include "mixins/meta/world.inl"
1396# endif
1397# ifdef FLECS_JSON
1398# include "mixins/json/world.inl"
1399# endif
1400# ifdef FLECS_APP
1401# include "mixins/app/mixin.inl"
1402# endif
1403# ifdef FLECS_METRICS
1404# include "mixins/metrics/mixin.inl"
1405# endif
1406# ifdef FLECS_ALERTS
1407# include "mixins/alerts/mixin.inl"
1408# endif
1409
1410public:
1411 void init_builtin_components();
1412
1413 world_t *world_;
1414};
1415
1419 struct scoped_world : world {
1420 scoped_world(
1421 flecs::world_t *w,
1422 flecs::entity_t s) : world(w)
1423 {
1424 prev_scope_ = ecs_set_scope(w, s);
1425 }
1426
1427 ~scoped_world() {
1428 ecs_set_scope(world_, prev_scope_);
1429 }
1430
1431 scoped_world(const scoped_world& obj) : world(nullptr) {
1432 prev_scope_ = obj.prev_scope_;
1433 world_ = obj.world_;
1434 flecs_poly_claim(world_);
1435 }
1436
1437 flecs::entity_t prev_scope_;
1438};
1439
1441
1442} // 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_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:2726
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:1419
flecs::world
The world.
Definition world.hpp:158
flecs::world::is_stage
bool is_stage() const
Test if is a stage.
Definition world.hpp:442
flecs::world::shrink
void shrink() const
Free unused memory.
Definition world.hpp:1304
flecs::world::delete_with
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1146
flecs::world::remove_all
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:1163
flecs::world::delete_with
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1158
flecs::world::merge
void merge() const
Merge world or stage.
Definition world.hpp:461
flecs::world::delete_with
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1135
flecs::world::get_info
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1291
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:694
flecs::world::delta_time
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1296
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:1354
flecs::world::set_entity_range
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:605
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:1088
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:1043
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:1313
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:1199
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:1247
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:358
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:655
flecs::world::defer_suspend
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1214
flecs::world::set
void set(const A &value) const
Set singleton pair.
Definition world.hpp:686
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:1258
flecs::world::async_stage
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:498
flecs::world::is_deferred
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:391
flecs::world::get_binding_ctx
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:582
flecs::world::get_stage_id
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:432
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:1119
flecs::world::defer_resume
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1227
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:593
flecs::world::set_version
void set_version(flecs::entity_t e) const
Set version of entity to provided.
Definition world.hpp:1278
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:410
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:1072
flecs::world::get_ctx
void * get_ctx() const
Get world context.
Definition world.hpp:554
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:1348
flecs::world::count
int count() const
Count entities matching a pair.
Definition world.hpp:1063
flecs::world::remove_all
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1180
flecs::world::defer_end
bool defer_end() const
End block of operations to defer.
Definition world.hpp:376
flecs::world::count
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1034
flecs::world::remove_all
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1186
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:510
flecs::world::scope
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:1110
flecs::world::with
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:1081
flecs::world::remove_all
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1168
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:619
flecs::world::count
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1053
flecs::world::id_if_registered
flecs::id_t id_if_registered()
Return component id if it has been registered.
Definition world.hpp:1333
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:526
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:670
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:1102
flecs::world::get_stage
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:479
flecs::world::set
void set(T &&value) const
Set singleton component.
Definition world.hpp:677
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:1237
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:569
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:1343
flecs::world::get_stage_count
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:422
flecs::world::delete_with
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1140
flecs::world::delete_with
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1152
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:1322
flecs::world::with
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:1095
flecs::world::set_ctx
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:541
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:1025
flecs::world::type_info
const flecs::type_info_t * type_info()
Return type info.
Definition world.hpp:1366
flecs::world::type_info
const flecs::type_info_t * type_info(flecs::entity_t t)
Return type info.
Definition world.hpp:1360
flecs::world::remove_all
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1174
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