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
6#pragma once
7
8namespace flecs
9{
10
21template <typename T>
22inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
24 "operation invalid for empty type");
25
26 ecs_cpp_get_mut_t res = ecs_cpp_set(world, entity, id, &value, sizeof(T));
27
28 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
29 if constexpr (std::is_copy_assignable_v<T>) {
30 dst = FLECS_FWD(value);
31 } else {
32 dst = FLECS_MOV(value);
33 }
34
35 if (res.stage) {
36 flecs_defer_end(res.world, res.stage);
37 }
38
39 if (res.call_modified) {
41 }
42}
43
52template <typename T>
53inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
55 "operation invalid for empty type");
56
57 ecs_cpp_get_mut_t res = ecs_cpp_set(world, entity, id, &value, sizeof(T));
58
59 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
60 dst = value;
61
62 if (res.stage) {
63 flecs_defer_end(res.world, res.stage);
64 }
65
66 if (res.call_modified) {
68 }
69}
70
79template <typename T, typename A>
80inline void set(world_t *world, entity_t entity, A&& value) {
82 flecs::set(world, entity, FLECS_FWD(value), id);
83}
84
93template <typename T, typename A>
94inline void set(world_t *world, entity_t entity, const A& value) {
96 flecs::set(world, entity, value, id);
97}
98
108template <typename T>
109inline void assign(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
110 ecs_assert(_::type<remove_reference_t<T>>::size() != 0,
111 ECS_INVALID_PARAMETER, "operation invalid for empty type");
112
113 ecs_cpp_get_mut_t res = ecs_cpp_assign(
114 world, entity, id, &value, sizeof(T));
115
116 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
117 if constexpr (std::is_copy_assignable_v<T>) {
118 dst = FLECS_FWD(value);
119 } else {
120 dst = FLECS_MOV(value);
121 }
122
123 if (res.stage) {
124 flecs_defer_end(res.world, res.stage);
125 }
126
127 if (res.call_modified) {
129 }
130}
131
141template <typename T>
142inline void assign(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
143 ecs_assert(_::type<remove_reference_t<T>>::size() != 0,
144 ECS_INVALID_PARAMETER, "operation invalid for empty type");
145
146 ecs_cpp_get_mut_t res = ecs_cpp_assign(
147 world, entity, id, &value, sizeof(T));
148
149 T& dst = *static_cast<remove_reference_t<T>*>(res.ptr);
150 dst = value;
151
152 if (res.stage) {
153 flecs_defer_end(res.world, res.stage);
154 }
155
156 if (res.call_modified) {
158 }
159}
160
169template <typename T, typename A>
170inline void assign(world_t *world, entity_t entity, A&& value) {
172 flecs::assign(world, entity, FLECS_FWD(value), id);
173}
174
183template <typename T, typename A>
184inline void assign(world_t *world, entity_t entity, const A& value) {
186 flecs::assign(world, entity, value, id);
187}
188
189
199template <typename T, typename ... Args, if_t<
200 std::is_constructible<actual_type_t<T>, Args...>::value ||
201 std::is_default_constructible<actual_type_t<T>>::value > = 0>
202inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
204 "operation invalid for empty type");
205 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id, sizeof(T), nullptr));
206
207 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
208
210}
211
222
228inline uint32_t get_generation(flecs::entity_t e) {
229 return ECS_GENERATION(e);
230}
231
232struct scoped_world;
233
246struct world {
249 explicit world()
250 : world_( ecs_init() ) {
252 }
253
258 explicit world(int argc, char *argv[])
259 : world_( ecs_init_w_args(argc, argv) ) {
261 }
262
265 explicit world(world_t *w)
266 : world_( w ) {
267 if (w) {
268 flecs_poly_claim(w);
269 }
270 }
271
274 world(const world& obj) {
275 this->world_ = obj.world_;
276 flecs_poly_claim(this->world_);
277 }
278
280 world& operator=(const world& obj) noexcept {
281 release();
282 this->world_ = obj.world_;
283 flecs_poly_claim(this->world_);
284 return *this;
285 }
286
288 world(world&& obj) noexcept {
289 world_ = obj.world_;
290 obj.world_ = nullptr;
291 }
292
294 world& operator=(world&& obj) noexcept {
295 release();
296 world_ = obj.world_;
297 obj.world_ = nullptr;
298 return *this;
299 }
300
304 void release() {
305 if (world_) {
306 if (!flecs_poly_release(world_)) {
307 if (ecs_stage_get_id(world_) == -1) {
309 } else {
310 // Before we call ecs_fini(), we increment the reference count back to 1.
311 // Otherwise, copies of this object created during ecs_fini() (e.g., a component on_remove hook)
312 // would again call this destructor and ecs_fini().
313 flecs_poly_claim(world_);
315 }
316 }
317 world_ = nullptr;
318 }
319 }
320
323 release();
324 }
325
327 operator world_t*() const { return world_; }
328
336 void make_owner() {
337 flecs_poly_release(world_);
338 }
339
341 void reset() {
342 /* Make sure there's only one reference to the world. */
343 ecs_assert(flecs_poly_refcount(world_) == 1, ECS_INVALID_OPERATION,
344 "reset would invalidate other handles");
346 world_ = ecs_init();
348 }
349
352 world_t* c_ptr() const {
353 return world_;
354 }
355
359 void quit() const {
361 }
362
365 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
366 ecs_atfini(world_, action, ctx);
367 }
368
371 bool should_quit() const {
372 return ecs_should_quit(world_);
373 }
374
398 }
399
409 void frame_end() const {
411 }
412
423 bool readonly_begin(bool multi_threaded = false) const {
424 return ecs_readonly_begin(world_, multi_threaded);
425 }
426
433 void readonly_end() const {
435 }
436
453 bool defer_begin() const {
454 return ecs_defer_begin(world_);
455 }
456
472 bool defer_end() const {
473 return ecs_defer_end(world_);
474 }
475
488 bool is_deferred() const {
489 return ecs_is_deferred(world_);
490 }
491
504 bool is_defer_suspended() const {
506 }
507
523 void set_stage_count(int32_t stages) const {
525 }
526
535 int32_t get_stage_count() const {
537 }
538
545 int32_t get_stage_id() const {
546 return ecs_stage_get_id(world_);
547 }
548
555 bool is_stage() const {
560 "flecs::world instance contains invalid reference to world or stage");
562 }
563
574 void merge() const {
576 }
577
592 flecs::world get_stage(int32_t stage_id) const {
593 return flecs::world(ecs_get_stage(world_, stage_id));
594 }
595
613 flecs_poly_release(as); // World object will claim.
614 return flecs::world(as);
615 }
616
624 /* Safe cast, mutability is checked. */
625 return flecs::world(
626 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
627 }
628
639 bool is_readonly() const {
641 }
642
653 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
654 ecs_set_ctx(world_, ctx, ctx_free);
655 }
656
666 void* get_ctx() const {
667 return ecs_get_ctx(world_);
668 }
669
681 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
682 ecs_set_binding_ctx(world_, ctx, ctx_free);
683 }
684
694 void* get_binding_ctx() const {
696 }
697
705 void dim(int32_t entity_count) const {
706 ecs_dim(world_, entity_count);
707 }
708
717 void set_entity_range(entity_t min, entity_t max) const {
718 ecs_set_entity_range(world_, min, max);
719 }
720
731 void enable_range_check(bool enabled = true) const {
733 }
734
744
752 flecs::entity get_scope() const;
753
759 template <typename T>
760 flecs::entity set_scope() const;
761
768 return ecs_set_lookup_path(world_, search_path);
769 }
770
779 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
780
783 template <typename T, if_t< !is_callable<T>::value > = 0>
784 void set(const T& value) const {
785 flecs::set<T>(world_, _::type<T>::id(world_), value);
786 }
787
790 template <typename T, if_t< !is_callable<T>::value > = 0>
791 void set(T&& value) const {
792 flecs::set<T>(world_, _::type<T>::id(world_),
793 FLECS_FWD(value));
794 }
795
798 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
799 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
800 void set(const A& value) const {
801 flecs::set<P>(world_, _::type<First>::id(world_), value);
802 }
803
806 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
807 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
808 void set(A&& value) const {
809 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
810 }
811
814 template <typename First, typename Second>
815 void set(Second second, const First& value) const;
816
819 template <typename First, typename Second>
820 void set(Second second, First&& value) const;
821
824 template <typename Func, if_t< is_callable<Func>::value > = 0 >
825 void set(const Func& func) const;
826
827 template <typename T, typename ... Args>
828 void emplace(Args&&... args) const {
829 flecs::id_t component_id = _::type<T>::id(world_);
830 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
831 }
832
835 #ifndef ensure
836 template <typename T>
837 T& ensure() const;
838 #endif
839
842 template <typename T>
843 void modified() const;
844
847 template <typename T>
848 ref<T> get_ref() const;
849
850
851 /* try_get */
852
855 const void* try_get(flecs::id_t id) const;
856
859 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
860
863 template <typename T>
864 const T* try_get() const;
865
868 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
869 typename A = actual_type_t<P>>
870 const A* try_get() const;
871
874 template <typename First, typename Second>
875 const First* try_get(Second second) const;
876
877
878 /* get */
879
882 const void* get(flecs::id_t id) const;
883
886 const void* get(flecs::entity_t r, flecs::entity_t t) const;
887
888 template <typename T>
889 const T& get() const;
890
893 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
894 typename A = actual_type_t<P>>
895 const A& get() const;
896
899 template <typename First, typename Second>
900 const First& get(Second second) const;
901
904 template <typename Func, if_t< is_callable<Func>::value > = 0 >
905 void get(const Func& func) const;
906
907
908 /* try_get_mut */
909
912 void* try_get_mut(flecs::id_t id) const;
913
917
918 template <typename T>
919 T* try_get_mut() const;
920
923 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
924 typename A = actual_type_t<P>>
925 A* try_get_mut() const;
926
929 template <typename First, typename Second>
930 First* try_get_mut(Second second) const;
931
932
933 /* get_mut */
934
937 void* get_mut(flecs::id_t id) const;
938
941 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
942
943 template <typename T>
944 T& get_mut() const;
945
948 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
949 typename A = actual_type_t<P>>
950 A& get_mut() const;
951
954 template <typename First, typename Second>
955 First& get_mut(Second second) const;
956
957
963 template <typename T>
964 bool has() const;
965
972 template <typename First, typename Second>
973 bool has() const;
974
981 template <typename First>
982 bool has(flecs::id_t second) const;
983
990 bool has(flecs::id_t first, flecs::id_t second) const;
991
998 template <typename E, if_t< is_enum<E>::value > = 0>
999 bool has(E value) const;
1000
1003 template <typename T>
1004 void add() const;
1005
1011 template <typename First, typename Second>
1012 void add() const;
1013
1019 template <typename First>
1020 void add(flecs::entity_t second) const;
1021
1027 void add(flecs::entity_t first, flecs::entity_t second) const;
1028
1034 template <typename E, if_t< is_enum<E>::value > = 0>
1035 void add(E value) const;
1036
1039 template <typename T>
1040 void remove() const;
1041
1047 template <typename First, typename Second>
1048 void remove() const;
1049
1055 template <typename First>
1056 void remove(flecs::entity_t second) const;
1057
1063 void remove(flecs::entity_t first, flecs::entity_t second) const;
1064
1072 template <typename Func>
1073 void children(Func&& f) const;
1074
1077 template <typename T>
1078 flecs::entity singleton() const;
1079
1089 template<typename First>
1090 flecs::entity target(int32_t index = 0) const;
1091
1102 template<typename T>
1103 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1104
1114 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1115
1122 template <typename T>
1123 flecs::entity use(const char *alias = nullptr) const;
1124
1130 flecs::entity use(const char *name, const char *alias = nullptr) const;
1131
1137 void use(flecs::entity entity, const char *alias = nullptr) const;
1138
1144 int count(flecs::id_t component_id) const {
1145 return ecs_count_id(world_, component_id);
1146 }
1147
1154 int count(flecs::entity_t first, flecs::entity_t second) const {
1155 return ecs_count_id(world_, ecs_pair(first, second));
1156 }
1157
1163 template <typename T>
1164 int count() const {
1165 return count(_::type<T>::id(world_));
1166 }
1167
1174 template <typename First>
1175 int count(flecs::entity_t second) const {
1176 return count(_::type<First>::id(world_), second);
1177 }
1178
1185 template <typename First, typename Second>
1186 int count() const {
1187 return count(
1190 }
1191
1194 template <typename Func>
1195 void with(id_t with_id, const Func& func) const {
1196 ecs_id_t prev = ecs_set_with(world_, with_id);
1197 func();
1198 ecs_set_with(world_, prev);
1199 }
1200
1203 template <typename T, typename Func>
1204 void with(const Func& func) const {
1205 with(this->id<T>(), func);
1206 }
1207
1210 template <typename First, typename Second, typename Func>
1211 void with(const Func& func) const {
1212 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
1213 }
1214
1217 template <typename First, typename Func>
1218 void with(id_t second, const Func& func) const {
1219 with(ecs_pair(this->id<First>(), second), func);
1220 }
1221
1224 template <typename Func>
1225 void with(id_t first, id_t second, const Func& func) const {
1226 with(ecs_pair(first, second), func);
1227 }
1228
1232 template <typename Func>
1233 void scope(id_t parent, const Func& func) const {
1234 ecs_entity_t prev = ecs_set_scope(world_, parent);
1235 func();
1236 ecs_set_scope(world_, prev);
1237 }
1238
1241 template <typename T, typename Func>
1242 void scope(const Func& func) const {
1244 scope(parent, func);
1245 }
1246
1250 flecs::scoped_world scope(id_t parent) const;
1251
1252 template <typename T>
1253 flecs::scoped_world scope() const;
1254
1255 flecs::scoped_world scope(const char* name) const;
1256
1258 void delete_with(id_t the_id) const {
1259 ecs_delete_with(world_, the_id);
1260 }
1261
1263 void delete_with(entity_t first, entity_t second) const {
1264 delete_with(ecs_pair(first, second));
1265 }
1266
1268 template <typename T>
1269 void delete_with() const {
1271 }
1272
1274 template <typename First, typename Second>
1278
1280 template <typename First>
1281 void delete_with(entity_t second) const {
1283 }
1284
1286 void remove_all(id_t the_id) const {
1287 ecs_remove_all(world_, the_id);
1288 }
1289
1291 void remove_all(entity_t first, entity_t second) const {
1292 remove_all(ecs_pair(first, second));
1293 }
1294
1296 template <typename T>
1297 void remove_all() const {
1299 }
1300
1302 template <typename First, typename Second>
1306
1308 template <typename First>
1309 void remove_all(entity_t second) const {
1311 }
1312
1321 template <typename Func>
1322 void defer(const Func& func) const {
1324 func();
1326 }
1327
1337 void defer_suspend() const {
1339 }
1340
1350 void defer_resume() const {
1352 }
1353
1360 bool exists(flecs::entity_t e) const {
1361 return ecs_exists(world_, e);
1362 }
1363
1371 return ecs_is_alive(world_, e);
1372 }
1373
1382 return ecs_is_valid(world_, e);
1383 }
1384
1391
1396
1403 }
1404
1409 uint32_t get_version(flecs::entity_t e) const {
1410 return ecs_get_version(e);
1411 }
1412
1414 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1415 ecs_run_post_frame(world_, action, ctx);
1416 }
1417
1423 return ecs_get_world_info(world_);
1424 }
1425
1428 return get_info()->delta_time;
1429 }
1430
1435 void shrink() const {
1437 }
1438
1444 void exclusive_access_begin(const char *thread_name = nullptr) {
1445 ecs_exclusive_access_begin(world_, thread_name);
1446 }
1447
1453 void exclusive_access_end(bool lock_world = false) {
1454 ecs_exclusive_access_end(world_, lock_world);
1455 }
1456
1463 template <typename T>
1466 return _::type<T>::id(world_);
1467 }
1468 else {
1469 return 0;
1470 }
1471 }
1472
1477
1480 return ecs_get_type_info(world_, ecs_pair(r, t));
1481 }
1482
1484 template <typename T>
1488
1490 template <typename R>
1494
1496 template <typename R, typename T>
1498 return type_info<R>(_::type<T>::id(world_));
1499 }
1500
1501# include "mixins/id/mixin.inl"
1503# include "mixins/entity/mixin.inl"
1504# include "mixins/event/mixin.inl"
1505# include "mixins/term/mixin.inl"
1506# include "mixins/observer/mixin.inl"
1507# include "mixins/query/mixin.inl"
1508# include "mixins/enum/mixin.inl"
1509
1510# ifdef FLECS_MODULE
1511# include "mixins/module/mixin.inl"
1512# endif
1513# ifdef FLECS_PIPELINE
1514# include "mixins/pipeline/mixin.inl"
1515# endif
1516# ifdef FLECS_SYSTEM
1517# include "mixins/system/mixin.inl"
1518# endif
1519# ifdef FLECS_TIMER
1520# include "mixins/timer/mixin.inl"
1521# endif
1522# ifdef FLECS_SCRIPT
1523# include "mixins/script/mixin.inl"
1524# endif
1525# ifdef FLECS_META
1526# include "mixins/meta/world.inl"
1527# endif
1528# ifdef FLECS_JSON
1529# include "mixins/json/world.inl"
1530# endif
1531# ifdef FLECS_APP
1532# include "mixins/app/mixin.inl"
1533# endif
1534# ifdef FLECS_METRICS
1535# include "mixins/metrics/mixin.inl"
1536# endif
1537# ifdef FLECS_ALERTS
1538# include "mixins/alerts/mixin.inl"
1539# endif
1540
1541public:
1544
1546};
1547
1558 flecs::world_t *w,
1559 flecs::entity_t s) : world(w)
1560 {
1561 prev_scope_ = ecs_set_scope(w, s);
1562 }
1563
1568
1570 scoped_world(const scoped_world& obj) : world(nullptr) {
1572 world_ = obj.world_;
1573 flecs_poly_claim(world_);
1574 }
1575
1577};
1578
1581} // namespace flecs
Alert world mixin.
App world addon mixin.
Component mixin.
Entity world mixin.
Enum world mixin.
Event world mixin.
void ecs_remove_all(ecs_world_t *world, ecs_id_t component)
Remove all instances of the specified component.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t component)
Create new entities with a specified component.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
#define ECS_INVALID_OPERATION
Invalid operation error code.
Definition log.h:659
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:661
ecs_world_t * ecs_stage_new(ecs_world_t *world)
Create an unmanaged stage.
bool ecs_defer_end(ecs_world_t *world)
End a block of operations to defer.
bool ecs_readonly_begin(ecs_world_t *world, bool multi_threaded)
Begin readonly mode.
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until the end of the frame.
void ecs_defer_suspend(ecs_world_t *world)
Suspend deferring but do not flush queue.
bool ecs_is_deferred(const ecs_world_t *world)
Test if deferring is enabled for the current stage.
void ecs_stage_free(ecs_world_t *stage)
Free an unmanaged stage.
void ecs_merge(ecs_world_t *stage)
Merge a stage.
int32_t ecs_stage_get_id(const ecs_world_t *world)
Get the stage ID.
bool ecs_stage_is_readonly(const ecs_world_t *world)
Test whether the current world is readonly.
int32_t ecs_get_stage_count(const ecs_world_t *world)
Get the number of configured stages.
ecs_world_t * ecs_get_stage(const ecs_world_t *world, int32_t stage_id)
Get stage-specific world pointer.
void ecs_set_stage_count(ecs_world_t *world, int32_t stages)
Configure the world to have N stages.
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
bool ecs_is_defer_suspended(const ecs_world_t *world)
Test if deferring is suspended for the current stage.
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t component)
Get the type info for a component.
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition flecs.h:428
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:381
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:425
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:374
flecs::entity entity(Args &&... args) const
Create an entity.
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_world_t world_t
World type.
Definition c_types.hpp:18
void ecs_delete_with(ecs_world_t *world, ecs_id_t component)
Delete all entities with the specified component.
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified ID.
void(* ecs_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
Definition flecs.h:641
void(* ecs_ctx_free_t)(void *ctx)
Function to clean up context data.
Definition flecs.h:646
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.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Signal that a component has been modified.
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove the generation from an entity ID.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
uint32_t ecs_get_version(ecs_entity_t entity)
Get the generation of an entity.
bool ecs_exists(const ecs_world_t *world, ecs_entity_t entity)
Test whether an entity exists.
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
void ecs_set_version(ecs_world_t *world, ecs_entity_t entity)
Override the generation of an entity.
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
ecs_entity_t * ecs_set_lookup_path(ecs_world_t *world, const ecs_entity_t *lookup_path)
Set the search path for lookup operations.
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
void ecs_atfini(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register an action to be executed when the world is destroyed.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init(void)
Create a new world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
float ecs_frame_begin(ecs_world_t *world, float delta_time)
Begin frame.
void ecs_run_post_frame(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register an action to be executed once after the frame.
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been requested.
void ecs_quit(ecs_world_t *world)
Signal exit.
void ecs_frame_end(ecs_world_t *world)
End frame.
void * ecs_get_binding_ctx(const ecs_world_t *world)
Get the world binding context.
void ecs_shrink(ecs_world_t *world)
Free unused memory.
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
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.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get the world info.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get the world from a poly.
void ecs_set_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world context.
void ecs_exclusive_access_begin(ecs_world_t *world, const char *thread_name)
Begin exclusive thread access.
void ecs_set_binding_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world binding context.
#define flecs_poly_is(object, type)
Test if a pointer is of the specified type.
Definition flecs.h:2814
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable or disable range limits.
void ecs_exclusive_access_end(ecs_world_t *world, bool lock_world)
End exclusive thread access.
void * ecs_get_ctx(const ecs_world_t *world)
Get the world context.
ID world mixin.
JSON world mixin.
Meta world mixin.
Metrics world mixin.
Module world mixin.
Observer world mixin.
Pipeline world mixin.
Query world mixin.
Script world mixin.
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1019
Type that contains information about the world.
Definition flecs.h:1478
float delta_time
Time passed to or computed by ecs_progress().
Definition flecs.h:1484
Component class.
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1551
~scoped_world()
Destructor.
Definition world.hpp:1565
scoped_world(flecs::world_t *w, flecs::entity_t s)
Create a scoped world.
Definition world.hpp:1557
flecs::entity_t prev_scope_
The previous scope entity.
Definition world.hpp:1576
scoped_world(const scoped_world &obj)
Copy constructor.
Definition world.hpp:1570
The world.
Definition world.hpp:246
bool is_stage() const
Test if this is a stage.
Definition world.hpp:555
void shrink() const
Free unused memory.
Definition world.hpp:1435
uint32_t get_version(flecs::entity_t e) const
Get the version of the provided entity.
Definition world.hpp:1409
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1269
const T & get() const
Get a singleton component.
Definition world.hpp:191
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:1286
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1281
void merge() const
Merge world or stage.
Definition world.hpp:574
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1545
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1258
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1422
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:91
T & get_mut() const
Get a mutable singleton component.
Definition world.hpp:257
void remove() const
Remove singleton component.
Definition world.hpp:346
flecs::entity lookup(const char *name, const char *sep="::", const char *root_sep="::", bool recursive=true) const
Lookup entity by name.
Definition world.hpp:102
void set(A &&value) const
Set singleton pair.
Definition world.hpp:808
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1427
void quit() const
Signal application should quit.
Definition world.hpp:359
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for ID.
Definition world.hpp:427
const flecs::type_info_t * type_info()
Return the type info.
Definition world.hpp:1485
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:717
void readonly_end() const
End readonly mode.
Definition world.hpp:433
void with(const Func &func) const
All entities created in the function are created with the pair.
Definition world.hpp:1211
flecs::entity make_alive(flecs::entity_t e) const
Ensure an entity ID is alive.
Definition world.hpp:433
int count() const
Count entities matching a component.
Definition world.hpp:1164
void exclusive_access_begin(const char *thread_name=nullptr)
Begin exclusive access.
Definition world.hpp:1444
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:385
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:1322
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:371
bool is_alive(flecs::entity_t e) const
Check if entity is alive.
Definition world.hpp:1370
world_t * c_ptr() const
Obtain a pointer to the C world object.
Definition world.hpp:352
const T * try_get() const
Get singleton component.
Definition world.hpp:158
~world()
Destructor.
Definition world.hpp:322
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:453
void reset()
Delete and recreate the world.
Definition world.hpp:341
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:767
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1337
void set(const A &value) const
Set singleton pair.
Definition world.hpp:800
void make_owner()
Make the current world object the owner of the world.
Definition world.hpp:336
bool is_valid(flecs::entity_t e) const
Check if entity ID is valid.
Definition world.hpp:1381
flecs::world async_stage() const
Create an asynchronous stage.
Definition world.hpp:611
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:488
void release()
Release the underlying world object.
Definition world.hpp:304
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:694
int32_t get_stage_id() const
Get current stage ID.
Definition world.hpp:545
void init_builtin_components()
Initialize built-in components.
Definition world.hpp:12
world(const world &obj)
Copy constructor.
Definition world.hpp:274
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:1242
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1350
void dim(int32_t entity_count) const
Preallocate memory for a number of entities.
Definition world.hpp:705
void set_version(flecs::entity_t e) const
Set the version of an entity to the provided value.
Definition world.hpp:1401
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:523
void with(id_t with_id, const Func &func) const
All entities created in the function are created with the ID.
Definition world.hpp:1195
void * get_ctx() const
Get world context.
Definition world.hpp:666
const flecs::type_info_t * type_info(flecs::entity_t r, flecs::entity_t t)
Return the type info.
Definition world.hpp:1479
int count() const
Count entities matching a pair.
Definition world.hpp:1186
flecs::scoped_world scope() const
Use the provided scope (by type) for operations run on the returned world.
Definition world.hpp:484
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1303
bool defer_end() const
End block of operations to defer.
Definition world.hpp:472
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1154
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1309
world(world_t *w)
Create a world from a C world.
Definition world.hpp:265
void children(Func &&f) const
Iterate entities in root of world.
Definition world.hpp:373
flecs::world get_world() const
Get actual world.
Definition world.hpp:623
T * try_get_mut() const
Try to get a mutable singleton component (returns nullptr if not found).
Definition world.hpp:224
void scope(id_t parent, const Func &func) const
All entities created in the function are created in the scope.
Definition world.hpp:1233
void with(const Func &func) const
All entities created in the function are created with the type.
Definition world.hpp:1204
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1291
void modified() const
Mark singleton component as modified.
Definition world.hpp:118
world(world &&obj) noexcept
Move constructor.
Definition world.hpp:288
void enable_range_check(bool enabled=true) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:731
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1175
world & operator=(const world &obj) noexcept
Copy assignment operator.
Definition world.hpp:280
flecs::entity set_scope(const flecs::entity_t scope) const
Set current scope.
Definition world.hpp:86
flecs::id_t id_if_registered()
Return the component ID if it has been registered.
Definition world.hpp:1464
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:396
flecs::entity use(const char *alias=nullptr) const
Create an alias for a component.
Definition world.hpp:54
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:639
void add() const
Add singleton component.
Definition world.hpp:312
T & ensure() const
Ensure singleton component.
Definition world.hpp:110
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:423
void set(const T &value) const
Set singleton component.
Definition world.hpp:784
void with(id_t first, id_t second, const Func &func) const
All entities created in the function are created with the pair.
Definition world.hpp:1225
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:592
void set(T &&value) const
Set singleton component.
Definition world.hpp:791
bool has() const
Test if world has singleton component.
Definition world.hpp:278
bool exists(flecs::entity_t e) const
Check if entity ID exists in the world.
Definition world.hpp:1360
world()
Create a world.
Definition world.hpp:249
void frame_end() const
End frame.
Definition world.hpp:409
void run_post_frame(ecs_fini_action_t action, void *ctx) const
Run callback after completing the frame.
Definition world.hpp:1414
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:681
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:365
const flecs::type_info_t * type_info(flecs::id_t component)
Return the type info.
Definition world.hpp:1474
int32_t get_stage_count() const
Get the number of configured stages.
Definition world.hpp:535
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1263
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1275
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:379
void exclusive_access_end(bool lock_world=false)
End exclusive access.
Definition world.hpp:1453
void with(id_t second, const Func &func) const
All entities created in the function are created with the pair.
Definition world.hpp:1218
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:653
bool is_defer_suspended() const
Test whether deferring is suspended.
Definition world.hpp:504
world(int argc, char *argv[])
Create a world with command-line arguments.
Definition world.hpp:258
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:1144
const flecs::type_info_t * type_info()
Return the type info.
Definition world.hpp:1497
const flecs::type_info_t * type_info(flecs::entity_t t)
Return the type info.
Definition world.hpp:1491
world & operator=(world &&obj) noexcept
Move assignment operator.
Definition world.hpp:294
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1297
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:139
System module world mixin.
Term world mixin.
Timer module mixin.
flecs::id_t strip_generation(flecs::entity_t e)
Return the ID without generation.
Definition world.hpp:219
uint32_t get_generation(flecs::entity_t e)
Return the entity generation.
Definition world.hpp:228
void assign(world_t *world, flecs::entity_t entity, T &&value, flecs::id_t id)
Assign a component value using move semantics.
Definition world.hpp:109
void set(world_t *world, flecs::entity_t entity, T &&value, flecs::id_t id)
Static helper functions to assign a component value.
Definition world.hpp:22
void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args &&... args)
Emplace a component value, constructing it in place.
Definition world.hpp:202