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&&), T = not constructible
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 if (!ecs_is_deferred(world)) {
20 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
21 dst = FLECS_MOV(value);
22
23 ecs_modified_id(world, entity, id);
24 } else {
25 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
26 dst = FLECS_MOV(value);
27 }
28}
29
30// set(const T&), T = not constructible
31template <typename T>
32 inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
33 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
34 "operation invalid for empty type");
35
36 if (!ecs_is_deferred(world)) {
37 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
38 dst = FLECS_MOV(value);
39
40 ecs_modified_id(world, entity, id);
41 } else {
42 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
43 dst = FLECS_MOV(value);
44 }
45}
46
47// set(T&&)
48template <typename T, typename A>
49inline void set(world_t *world, entity_t entity, A&& value) {
50 id_t id = _::type<T>::id(world);
51 flecs::set(world, entity, FLECS_FWD(value), id);
52}
53
54// set(const T&)
55template <typename T, typename A>
56inline void set(world_t *world, entity_t entity, const A& value) {
57 id_t id = _::type<T>::id(world);
58 flecs::set(world, entity, value, id);
59}
60
61// set(T&&), T = not constructible
62 template <typename T>
63inline void assign(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
64 using ActualType = remove_reference_t<T>;
65
66 ecs_assert(_::type<ActualType>::size() != 0, ECS_INVALID_PARAMETER,
67 "operation invalid for empty type");
68
69 if (!ecs_is_deferred(world)) {
70 ActualType *dst_ptr = static_cast<ActualType*>(ecs_get_mut_id(world, entity, id));
71 ecs_assert(dst_ptr != nullptr, ECS_INVALID_OPERATION,
72 "entity does not have component, use set() instead");
73
74 ActualType& dst = *dst_ptr;
75 dst = FLECS_MOV(value);
76
77 ecs_modified_id(world, entity, id);
78 } else {
79 ActualType *dst_ptr = static_cast<ActualType*>(ecs_get_mut_modified_id(world, entity, id));
80 ecs_assert(dst_ptr != nullptr, ECS_INVALID_OPERATION,
81 "entity does not have component, use set() instead");
82
83 ActualType& dst = *dst_ptr;
84 dst = FLECS_MOV(value);
85 }
86}
87
88// set(const T&), T = not constructible
89template <typename T>
90inline void assign(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
91 using ActualType = remove_reference_t<T>;
92
93 ecs_assert(_::type<ActualType>::size() != 0, ECS_INVALID_PARAMETER,
94 "operation invalid for empty type");
95
96 if (!ecs_is_deferred(world)) {
97 ActualType *dst_ptr = static_cast<ActualType*>(ecs_get_mut_id(world, entity, id));
98 ecs_assert(dst_ptr != nullptr, ECS_INVALID_OPERATION,
99 "entity does not have component, use set() instead");
100
101 ActualType& dst = *dst_ptr;
102 dst = FLECS_MOV(value);
103
104 ecs_modified_id(world, entity, id);
105 } else {
106 ActualType *dst_ptr = static_cast<ActualType*>(ecs_get_mut_modified_id(world, entity, id));
107 ecs_assert(dst_ptr != nullptr, ECS_INVALID_OPERATION,
108 "entity does not have component, use set() instead");
109
110 ActualType& dst = *dst_ptr;
111 dst = FLECS_MOV(value);
112 }
113}
114
115// set(T&&)
116template <typename T, typename A>
117inline void assign(world_t *world, entity_t entity, A&& value) {
118 id_t id = _::type<T>::id(world);
119 flecs::assign(world, entity, FLECS_FWD(value), id);
120}
121
122// set(const T&)
123template <typename T, typename A>
124inline void assign(world_t *world, entity_t entity, const A& value) {
125 id_t id = _::type<T>::id(world);
126 flecs::assign(world, entity, value, id);
127}
128
129
130// emplace for T(Args...)
131template <typename T, typename ... Args, if_t<
132 std::is_constructible<actual_type_t<T>, Args...>::value ||
133 std::is_default_constructible<actual_type_t<T>>::value > = 0>
134inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
135 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
136 "operation invalid for empty type");
137 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id, nullptr));
138
139 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
140
141 ecs_modified_id(world, entity, id);
142}
143
148 inline flecs::id_t strip_generation(flecs::entity_t e) {
149 return ecs_strip_generation(e);
150}
151
154 inline uint32_t get_generation(flecs::entity_t e) {
155 return ECS_GENERATION(e);
156}
157
158struct scoped_world;
159
167
172 struct world {
175 explicit world()
176 : world_( ecs_init() ) {
177 init_builtin_components();
178 }
179
184 explicit world(int argc, char *argv[])
185 : world_( ecs_init_w_args(argc, argv) ) {
186 init_builtin_components();
187 }
188
191 explicit world(world_t *w)
192 : world_( w ) {
193 if (w) {
194 flecs_poly_claim(w);
195 }
196 }
197
200 world(const world& obj) {
201 this->world_ = obj.world_;
202 flecs_poly_claim(this->world_);
203 }
204
205 world& operator=(const world& obj) noexcept {
206 release();
207 this->world_ = obj.world_;
208 flecs_poly_claim(this->world_);
209 return *this;
210 }
211
212 world(world&& obj) noexcept {
213 world_ = obj.world_;
214 obj.world_ = nullptr;
215 }
216
217 world& operator=(world&& obj) noexcept {
218 release();
219 world_ = obj.world_;
220 obj.world_ = nullptr;
221 return *this;
222 }
223
224 /* Releases the underlying world object. If this is the last handle, the world
225 will be finalized. */
226 void release() {
227 if (world_) {
228 if (!flecs_poly_release(world_)) {
229 if (ecs_stage_get_id(world_) == -1) {
230 ecs_stage_free(world_);
231 } else {
232 // before we call ecs_fini(), we increment the reference count back to 1
233 // otherwise, copies of this object created during ecs_fini (e.g. a component on_remove hook)
234 // would call again this destructor and ecs_fini().
235 flecs_poly_claim(world_);
236 ecs_fini(world_);
237 }
238 }
239 world_ = nullptr;
240 }
241 }
242
243 ~world() {
244 release();
245 }
246
247 /* Implicit conversion to world_t* */
248 operator world_t*() const { return world_; }
249
257 void make_owner() {
258 flecs_poly_release(world_);
259 }
260
262 void reset() {
263 /* Make sure there's only one reference to the world */
264 ecs_assert(flecs_poly_refcount(world_) == 1, ECS_INVALID_OPERATION,
265 "reset would invalidate other handles");
266 ecs_fini(world_);
267 world_ = ecs_init();
268 }
269
272 world_t* c_ptr() const {
273 return world_;
274 }
275
279 void quit() const {
280 ecs_quit(world_);
281 }
282
285 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
286 ecs_atfini(world_, action, ctx);
287 }
288
291 bool should_quit() const {
292 return ecs_should_quit(world_);
293 }
294
316 ecs_ftime_t frame_begin(float delta_time = 0) const {
317 return ecs_frame_begin(world_, delta_time);
318 }
319
329 void frame_end() const {
330 ecs_frame_end(world_);
331 }
332
343 bool readonly_begin(bool multi_threaded = false) const {
344 return ecs_readonly_begin(world_, multi_threaded);
345 }
346
353 void readonly_end() const {
354 ecs_readonly_end(world_);
355 }
356
372 bool defer_begin() const {
373 return ecs_defer_begin(world_);
374 }
375
390 bool defer_end() const {
391 return ecs_defer_end(world_);
392 }
393
405 bool is_deferred() const {
406 return ecs_is_deferred(world_);
407 }
408
424 void set_stage_count(int32_t stages) const {
425 ecs_set_stage_count(world_, stages);
426 }
427
436 int32_t get_stage_count() const {
437 return ecs_get_stage_count(world_);
438 }
439
446 int32_t get_stage_id() const {
447 return ecs_stage_get_id(world_);
448 }
449
456 bool is_stage() const {
457 ecs_assert(
458 flecs_poly_is(world_, ecs_world_t) ||
459 flecs_poly_is(world_, ecs_stage_t),
460 ECS_INVALID_PARAMETER,
461 "flecs::world instance contains invalid reference to world or stage");
462 return flecs_poly_is(world_, ecs_stage_t);
463 }
464
475 void merge() const {
476 ecs_merge(world_);
477 }
478
493 flecs::world get_stage(int32_t stage_id) const {
494 return flecs::world(ecs_get_stage(world_, stage_id));
495 }
496
512 flecs::world async_stage() const {
513 ecs_world_t *as = ecs_stage_new(world_);
514 flecs_poly_release(as); // world object will claim
515 return flecs::world(as);
516 }
517
524 flecs::world get_world() const {
525 /* Safe cast, mutability is checked */
526 return flecs::world(
527 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
528 }
529
540 bool is_readonly() const {
541 return ecs_stage_is_readonly(world_);
542 }
543
555 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
556 ecs_set_ctx(world_, ctx, ctx_free);
557 }
558
568 void* get_ctx() const {
569 return ecs_get_ctx(world_);
570 }
571
583 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
584 ecs_set_binding_ctx(world_, ctx, ctx_free);
585 }
586
596 void* get_binding_ctx() const {
597 return ecs_get_binding_ctx(world_);
598 }
599
607 void dim(int32_t entity_count) const {
608 ecs_dim(world_, entity_count);
609 }
610
619 void set_entity_range(entity_t min, entity_t max) const {
620 ecs_set_entity_range(world_, min, max);
621 }
622
633 void enable_range_check(bool enabled = true) const {
634 ecs_enable_range_check(world_, enabled);
635 }
636
645 flecs::entity set_scope(const flecs::entity_t scope) const;
646
654 flecs::entity get_scope() const;
655
661 template <typename T>
662 flecs::entity set_scope() const;
663
669 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
670 return ecs_set_lookup_path(world_, search_path);
671 }
672
679 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
680
683 template <typename T, if_t< !is_callable<T>::value > = 0>
684 void set(const T& value) const {
685 flecs::set<T>(world_, _::type<T>::id(world_), value);
686 }
687
690 template <typename T, if_t< !is_callable<T>::value > = 0>
691 void set(T&& value) const {
692 flecs::set<T>(world_, _::type<T>::id(world_),
693 FLECS_FWD(value));
694 }
695
698 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
699 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
700 void set(const A& value) const {
701 flecs::set<P>(world_, _::type<First>::id(world_), value);
702 }
703
706 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
707 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
708 void set(A&& value) const {
709 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
710 }
711
714 template <typename First, typename Second>
715 void set(Second second, const First& value) const;
716
719 template <typename First, typename Second>
720 void set(Second second, First&& value) const;
721
724 template <typename Func, if_t< is_callable<Func>::value > = 0 >
725 void set(const Func& func) const;
726
727 template <typename T, typename ... Args>
728 void emplace(Args&&... args) const {
729 flecs::id_t component_id = _::type<T>::id(world_);
730 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
731 }
732
735 #ifndef ensure
736 template <typename T>
737 T& ensure() const;
738 #endif
739
742 template <typename T>
743 void modified() const;
744
747 template <typename T>
748 ref<T> get_ref() const;
749
750
751 /* try_get */
752
755 const void* try_get(flecs::id_t id) const;
756
759 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
760
763 template <typename T>
764 const T* try_get() const;
765
768 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
769 typename A = actual_type_t<P>>
770 const A* try_get() const;
771
774 template <typename First, typename Second>
775 const First* try_get(Second second) const;
776
777
778 /* get */
779
782 const void* get(flecs::id_t id) const;
783
786 const void* get(flecs::entity_t r, flecs::entity_t t) const;
787
788 template <typename T>
789 const T& get() const;
790
793 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
794 typename A = actual_type_t<P>>
795 const A& get() const;
796
799 template <typename First, typename Second>
800 const First& get(Second second) const;
801
804 template <typename Func, if_t< is_callable<Func>::value > = 0 >
805 void get(const Func& func) const;
806
807
808 /* try_get_mut */
809
812 void* try_get_mut(flecs::id_t id) const;
813
816 void* try_get_mut(flecs::entity_t r, flecs::entity_t t) const;
817
818 template <typename T>
819 T* try_get_mut() const;
820
823 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
824 typename A = actual_type_t<P>>
825 A* try_get_mut() const;
826
829 template <typename First, typename Second>
830 First* try_get_mut(Second second) const;
831
832
833 /* get_mut */
834
837 void* get_mut(flecs::id_t id) const;
838
841 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
842
843 template <typename T>
844 T& get_mut() const;
845
848 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
849 typename A = actual_type_t<P>>
850 A& get_mut() const;
851
854 template <typename First, typename Second>
855 First& get_mut(Second second) const;
856
857
860 template <typename T>
861 bool has() const;
862
868 template <typename First, typename Second>
869 bool has() const;
870
876 template <typename First>
877 bool has(flecs::id_t second) const;
878
884 bool has(flecs::id_t first, flecs::id_t second) const;
885
888 template <typename T>
889 void add() const;
890
896 template <typename First, typename Second>
897 void add() const;
898
904 template <typename First>
905 void add(flecs::entity_t second) const;
906
912 void add(flecs::entity_t first, flecs::entity_t second) const;
913
916 template <typename T>
917 void remove() const;
918
924 template <typename First, typename Second>
925 void remove() const;
926
932 template <typename First>
933 void remove(flecs::entity_t second) const;
934
940 void remove(flecs::entity_t first, flecs::entity_t second) const;
941
949 template <typename Func>
950 void children(Func&& f) const;
951
954 template <typename T>
955 flecs::entity singleton() const;
956
965 template<typename First>
966 flecs::entity target(int32_t index = 0) const;
967
976 template<typename T>
977 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
978
987 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
988
995 template <typename T>
996 flecs::entity use(const char *alias = nullptr) const;
997
1003 flecs::entity use(const char *name, const char *alias = nullptr) const;
1004
1010 void use(flecs::entity entity, const char *alias = nullptr) const;
1011
1016 int count(flecs::id_t component_id) const {
1017 return ecs_count_id(world_, component_id);
1018 }
1019
1025 int count(flecs::entity_t first, flecs::entity_t second) const {
1026 return ecs_count_id(world_, ecs_pair(first, second));
1027 }
1028
1033 template <typename T>
1034 int count() const {
1035 return count(_::type<T>::id(world_));
1036 }
1037
1043 template <typename First>
1044 int count(flecs::entity_t second) const {
1045 return count(_::type<First>::id(world_), second);
1046 }
1047
1053 template <typename First, typename Second>
1054 int count() const {
1055 return count(
1056 _::type<First>::id(world_),
1057 _::type<Second>::id(world_));
1058 }
1059
1062 template <typename Func>
1063 void with(id_t with_id, const Func& func) const {
1064 ecs_id_t prev = ecs_set_with(world_, with_id);
1065 func();
1066 ecs_set_with(world_, prev);
1067 }
1068
1071 template <typename T, typename Func>
1072 void with(const Func& func) const {
1073 with(this->id<T>(), func);
1074 }
1075
1078 template <typename First, typename Second, typename Func>
1079 void with(const Func& func) const {
1080 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
1081 }
1082
1085 template <typename First, typename Func>
1086 void with(id_t second, const Func& func) const {
1087 with(ecs_pair(this->id<First>(), second), func);
1088 }
1089
1092 template <typename Func>
1093 void with(id_t first, id_t second, const Func& func) const {
1094 with(ecs_pair(first, second), func);
1095 }
1096
1100 template <typename Func>
1101 void scope(id_t parent, const Func& func) const {
1102 ecs_entity_t prev = ecs_set_scope(world_, parent);
1103 func();
1104 ecs_set_scope(world_, prev);
1105 }
1106
1109 template <typename T, typename Func>
1110 void scope(const Func& func) const {
1111 flecs::id_t parent = _::type<T>::id(world_);
1112 scope(parent, func);
1113 }
1114
1118 flecs::scoped_world scope(id_t parent) const;
1119
1120 template <typename T>
1121 flecs::scoped_world scope() const;
1122
1123 flecs::scoped_world scope(const char* name) const;
1124
1126 void delete_with(id_t the_id) const {
1127 ecs_delete_with(world_, the_id);
1128 }
1129
1131 void delete_with(entity_t first, entity_t second) const {
1132 delete_with(ecs_pair(first, second));
1133 }
1134
1136 template <typename T>
1137 void delete_with() const {
1138 delete_with(_::type<T>::id(world_));
1139 }
1140
1142 template <typename First, typename Second>
1143 void delete_with() const {
1144 delete_with(_::type<First>::id(world_), _::type<Second>::id(world_));
1145 }
1146
1148 template <typename First>
1149 void delete_with(entity_t second) const {
1150 delete_with(_::type<First>::id(world_), second);
1151 }
1152
1154 void remove_all(id_t the_id) const {
1155 ecs_remove_all(world_, the_id);
1156 }
1157
1159 void remove_all(entity_t first, entity_t second) const {
1160 remove_all(ecs_pair(first, second));
1161 }
1162
1164 template <typename T>
1165 void remove_all() const {
1166 remove_all(_::type<T>::id(world_));
1167 }
1168
1170 template <typename First, typename Second>
1171 void remove_all() const {
1172 remove_all(_::type<First>::id(world_), _::type<Second>::id(world_));
1173 }
1174
1176 template <typename First>
1177 void remove_all(entity_t second) const {
1178 remove_all(_::type<First>::id(world_), second);
1179 }
1180
1189 template <typename Func>
1190 void defer(const Func& func) const {
1191 ecs_defer_begin(world_);
1192 func();
1193 ecs_defer_end(world_);
1194 }
1195
1205 void defer_suspend() const {
1206 ecs_defer_suspend(world_);
1207 }
1208
1218 void defer_resume() const {
1219 ecs_defer_resume(world_);
1220 }
1221
1228 bool exists(flecs::entity_t e) const {
1229 return ecs_exists(world_, e);
1230 }
1231
1238 bool is_alive(flecs::entity_t e) const {
1239 return ecs_is_alive(world_, e);
1240 }
1241
1249 bool is_valid(flecs::entity_t e) const {
1250 return ecs_is_valid(world_, e);
1251 }
1252
1258 flecs::entity get_alive(flecs::entity_t e) const;
1259
1263 flecs::entity make_alive(flecs::entity_t e) const;
1264
1269 void set_version(flecs::entity_t e) const {
1270 ecs_set_version(world_, e);
1271 }
1272
1273 /* Run callback after completing frame */
1274 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1275 ecs_run_post_frame(world_, action, ctx);
1276 }
1277
1282 const flecs::world_info_t* get_info() const{
1283 return ecs_get_world_info(world_);
1284 }
1285
1287 ecs_ftime_t delta_time() const {
1288 return get_info()->delta_time;
1289 }
1290
1295 void shrink() const {
1296 ecs_shrink(world_);
1297 }
1298
1304 void exclusive_access_begin(const char *thread_name = nullptr) {
1305 ecs_exclusive_access_begin(world_, thread_name);
1306 }
1307
1313 void exclusive_access_end(bool lock_world = false) {
1314 ecs_exclusive_access_end(world_, lock_world);
1315 }
1316
1317# include "mixins/id/mixin.inl"
1318# include "mixins/component/mixin.inl"
1319# include "mixins/entity/mixin.inl"
1320# include "mixins/event/mixin.inl"
1321# include "mixins/term/mixin.inl"
1322# include "mixins/observer/mixin.inl"
1323# include "mixins/query/mixin.inl"
1324# include "mixins/enum/mixin.inl"
1325
1326# ifdef FLECS_MODULE
1327# include "mixins/module/mixin.inl"
1328# endif
1329# ifdef FLECS_PIPELINE
1330# include "mixins/pipeline/mixin.inl"
1331# endif
1332# ifdef FLECS_SYSTEM
1333# include "mixins/system/mixin.inl"
1334# endif
1335# ifdef FLECS_TIMER
1336# include "mixins/timer/mixin.inl"
1337# endif
1338# ifdef FLECS_SCRIPT
1339# include "mixins/script/mixin.inl"
1340# endif
1341# ifdef FLECS_META
1342# include "mixins/meta/world.inl"
1343# endif
1344# ifdef FLECS_JSON
1345# include "mixins/json/world.inl"
1346# endif
1347# ifdef FLECS_APP
1348# include "mixins/app/mixin.inl"
1349# endif
1350# ifdef FLECS_METRICS
1351# include "mixins/metrics/mixin.inl"
1352# endif
1353# ifdef FLECS_ALERTS
1354# include "mixins/alerts/mixin.inl"
1355# endif
1356
1357public:
1358 void init_builtin_components();
1359
1360 world_t *world_;
1361};
1362
1366 struct scoped_world : world {
1367 scoped_world(
1368 flecs::world_t *w,
1369 flecs::entity_t s) : world(w)
1370 {
1371 prev_scope_ = ecs_set_scope(w, s);
1372 }
1373
1374 ~scoped_world() {
1375 ecs_set_scope(world_, prev_scope_);
1376 }
1377
1378 scoped_world(const scoped_world& obj) : world(nullptr) {
1379 prev_scope_ = obj.prev_scope_;
1380 world_ = obj.world_;
1381 flecs_poly_claim(world_);
1382 }
1383
1384 flecs::entity_t prev_scope_;
1385};
1386
1388
1389} // 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_set_with
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
ecs_remove_all
void ecs_remove_all(ecs_world_t *world, ecs_id_t id)
Remove all instances of the specified (component) id.
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 *world)
Merge world or 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_stage_t
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition flecs.h:427
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:380
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:424
ecs_id_t
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:373
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 id)
Delete all entities with the specified id.
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:618
ecs_ctx_free_t
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:623
ecs_get_mut_id
void * ecs_get_mut_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
ecs_emplace_id
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, bool *is_new)
Emplace a component.
ecs_ensure_id
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
ecs_ensure_modified_id
void * ecs_ensure_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Combines ensure + modified in single operation.
ecs_modified_id
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
ecs_get_mut_modified_id
void * ecs_get_mut_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Combines get_mut + modified in single operation.
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:2725
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:1453
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::scoped_world
Scoped world.
Definition world.hpp:1366
flecs::world
The world.
Definition world.hpp:172
flecs::world::is_stage
bool is_stage() const
Test if is a stage.
Definition world.hpp:456
flecs::world::shrink
void shrink() const
Free unused memory.
Definition world.hpp:1295
flecs::world::delete_with
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1137
flecs::world::remove_all
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:1154
flecs::world::delete_with
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1149
flecs::world::merge
void merge() const
Merge world or stage.
Definition world.hpp:475
flecs::world::delete_with
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1126
flecs::world::get_info
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1282
flecs::world::get_scope
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:81
flecs::world::remove
void remove() const
Remove singleton component.
Definition world.hpp:286
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:90
flecs::world::set
void set(A &&value) const
Set singleton pair.
Definition world.hpp:708
flecs::world::delta_time
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1287
flecs::world::quit
void quit() const
Signal application should quit.
Definition world.hpp:279
flecs::world::get_alive
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition world.hpp:356
flecs::world::set_entity_range
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:619
flecs::world::readonly_end
void readonly_end() const
End readonly mode.
Definition world.hpp:353
flecs::world::with
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:1079
flecs::world::make_alive
flecs::entity make_alive(flecs::entity_t e) const
Definition world.hpp:361
flecs::world::count
int count() const
Count entities matching a component.
Definition world.hpp:1034
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:1304
flecs::world::target
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:319
flecs::world::get
const A & get() const
Get singleton pair.
Definition world.hpp:172
flecs::world::defer
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:1190
flecs::world::should_quit
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:291
flecs::world::is_alive
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1238
flecs::world::c_ptr
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:272
flecs::world::try_get
const T * try_get() const
Get singleton component.
Definition world.hpp:138
flecs::world::defer_begin
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:372
flecs::world::reset
void reset()
Deletes and recreates the world.
Definition world.hpp:262
flecs::world::set_lookup_path
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:669
flecs::world::defer_suspend
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1205
flecs::world::set
void set(const A &value) const
Set singleton pair.
Definition world.hpp:700
flecs::world::make_owner
void make_owner()
Make current world object owner of the world.
Definition world.hpp:257
flecs::world::is_valid
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1249
flecs::world::async_stage
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:512
flecs::world::is_deferred
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:405
flecs::world::get_binding_ctx
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:596
flecs::world::get_stage_id
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:446
flecs::world::world
world(const world &obj)
Not allowed to copy a world.
Definition world.hpp:200
flecs::world::scope
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:1110
flecs::world::defer_resume
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1218
flecs::world::set_scope
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:86
flecs::world::dim
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition world.hpp:607
flecs::world::set_version
void set_version(flecs::entity_t e) const
Set version of entity to provided.
Definition world.hpp:1269
flecs::world::try_get_mut
A * try_get_mut() const
Get mutable singleton pair.
Definition world.hpp:200
flecs::world::set_stage_count
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:424
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:1063
flecs::world::get_ctx
void * get_ctx() const
Get world context.
Definition world.hpp:568
flecs::world::count
int count() const
Count entities matching a pair.
Definition world.hpp:1054
flecs::world::remove_all
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1171
flecs::world::defer_end
bool defer_end() const
End block of operations to defer.
Definition world.hpp:390
flecs::world::count
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1025
flecs::world::remove_all
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1177
flecs::world::world
world(world_t *w)
Create world from C world.
Definition world.hpp:191
flecs::world::children
void children(Func &&f) const
Iterate entities in root of world Accepts a callback with the following signature:
Definition world.hpp:309
flecs::world::get_world
flecs::world get_world() const
Get actual world.
Definition world.hpp:524
flecs::world::scope
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:1101
flecs::world::with
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:1072
flecs::world::remove_all
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1159
flecs::world::modified
void modified() const
Mark singleton component as modified.
Definition world.hpp:104
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:633
flecs::world::count
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1044
flecs::world::frame_begin
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:316
flecs::world::use
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition world.hpp:48
flecs::world::is_readonly
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:540
flecs::world::add
void add() const
Add singleton component.
Definition world.hpp:263
flecs::world::ensure
T & ensure() const
Ensure singleton component.
Definition world.hpp:97
flecs::world::readonly_begin
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:343
flecs::world::get_mut
A & get_mut() const
Get mutable singleton pair.
Definition world.hpp:228
flecs::world::set
void set(const T &value) const
Set singleton component.
Definition world.hpp:684
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:1093
flecs::world::get_stage
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:493
flecs::world::set
void set(T &&value) const
Set singleton component.
Definition world.hpp:691
flecs::world::has
bool has() const
Test if world has singleton component.
Definition world.hpp:240
flecs::world::exists
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1228
flecs::world::world
world()
Create world.
Definition world.hpp:175
flecs::world::frame_end
void frame_end() const
End frame.
Definition world.hpp:329
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:583
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:285
flecs::world::get_stage_count
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:436
flecs::world::delete_with
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1131
flecs::world::delete_with
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1143
flecs::world::singleton
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:314
flecs::world::exclusive_access_end
void exclusive_access_end(bool lock_world=false)
End exclusive access.
Definition world.hpp:1313
flecs::world::with
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:1086
flecs::world::set_ctx
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:555
flecs::world::world
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:184
flecs::world::count
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:1016
flecs::world::remove_all
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1165
flecs::world::get_ref
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:122
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:148
flecs::get_generation
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:154