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
712 const ecs_entity_range_t* range_new(uint32_t min, uint32_t max) const {
713 return ecs_entity_range_new(world_, min, max);
714 }
715
719 void range_set(const ecs_entity_range_t *range) const {
721 }
722
728 }
729
739
747 flecs::entity get_scope() const;
748
754 template <typename T>
755 flecs::entity set_scope() const;
756
763 return ecs_set_lookup_path(world_, search_path);
764 }
765
774 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
775
778 template <typename T, if_t< !is_callable<T>::value > = 0>
779 void set(const T& value) const {
780 flecs::set<T>(world_, _::type<T>::id(world_), value);
781 }
782
785 template <typename T, if_t< !is_callable<T>::value > = 0>
786 void set(T&& value) const {
787 flecs::set<T>(world_, _::type<T>::id(world_),
788 FLECS_FWD(value));
789 }
790
793 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
794 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
795 void set(const A& value) const {
796 flecs::set<P>(world_, _::type<First>::id(world_), value);
797 }
798
801 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
802 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
803 void set(A&& value) const {
804 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
805 }
806
809 template <typename First, typename Second>
810 void set(Second second, const First& value) const;
811
814 template <typename First, typename Second>
815 void set(Second second, First&& value) const;
816
819 template <typename Func, if_t< is_callable<Func>::value > = 0 >
820 void set(const Func& func) const;
821
822 template <typename T, typename ... Args>
823 void emplace(Args&&... args) const {
824 flecs::id_t component_id = _::type<T>::id(world_);
825 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
826 }
827
830 #ifndef ensure
831 template <typename T>
832 T& ensure() const;
833 #endif
834
837 template <typename T>
838 void modified() const;
839
842 template <typename T>
843 ref<T> get_ref() const;
844
845
846 /* try_get */
847
850 const void* try_get(flecs::id_t id) const;
851
854 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
855
858 template <typename T>
859 const T* try_get() const;
860
863 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
864 typename A = actual_type_t<P>>
865 const A* try_get() const;
866
869 template <typename First, typename Second>
870 const First* try_get(Second second) const;
871
872
873 /* get */
874
877 const void* get(flecs::id_t id) const;
878
881 const void* get(flecs::entity_t r, flecs::entity_t t) const;
882
883 template <typename T>
884 const T& get() const;
885
888 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
889 typename A = actual_type_t<P>>
890 const A& get() const;
891
894 template <typename First, typename Second>
895 const First& get(Second second) const;
896
899 template <typename Func, if_t< is_callable<Func>::value > = 0 >
900 void get(const Func& func) const;
901
902
903 /* try_get_mut */
904
907 void* try_get_mut(flecs::id_t id) const;
908
912
913 template <typename T>
914 T* try_get_mut() const;
915
918 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
919 typename A = actual_type_t<P>>
920 A* try_get_mut() const;
921
924 template <typename First, typename Second>
925 First* try_get_mut(Second second) const;
926
927
928 /* get_mut */
929
932 void* get_mut(flecs::id_t id) const;
933
936 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
937
938 template <typename T>
939 T& get_mut() const;
940
943 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
944 typename A = actual_type_t<P>>
945 A& get_mut() const;
946
949 template <typename First, typename Second>
950 First& get_mut(Second second) const;
951
952
958 template <typename T>
959 bool has() const;
960
967 template <typename First, typename Second>
968 bool has() const;
969
976 template <typename First>
977 bool has(flecs::id_t second) const;
978
985 bool has(flecs::id_t first, flecs::id_t second) const;
986
993 template <typename E, if_t< is_enum<E>::value > = 0>
994 bool has(E value) const;
995
998 template <typename T>
999 void add() const;
1000
1006 template <typename First, typename Second>
1007 void add() const;
1008
1014 template <typename First>
1015 void add(flecs::entity_t second) const;
1016
1022 void add(flecs::entity_t first, flecs::entity_t second) const;
1023
1029 template <typename E, if_t< is_enum<E>::value > = 0>
1030 void add(E value) const;
1031
1034 template <typename T>
1035 void remove() const;
1036
1042 template <typename First, typename Second>
1043 void remove() const;
1044
1050 template <typename First>
1051 void remove(flecs::entity_t second) const;
1052
1058 void remove(flecs::entity_t first, flecs::entity_t second) const;
1059
1067 template <typename Func>
1068 void children(Func&& f) const;
1069
1072 template <typename T>
1073 flecs::entity singleton() const;
1074
1084 template<typename First>
1085 flecs::entity target(int32_t index = 0) const;
1086
1097 template<typename T>
1098 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1099
1109 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1110
1117 template <typename T>
1118 flecs::entity use(const char *alias = nullptr) const;
1119
1125 flecs::entity use(const char *name, const char *alias = nullptr) const;
1126
1132 void use(flecs::entity entity, const char *alias = nullptr) const;
1133
1139 int count(flecs::id_t component_id) const {
1140 return ecs_count_id(world_, component_id);
1141 }
1142
1149 int count(flecs::entity_t first, flecs::entity_t second) const {
1150 return ecs_count_id(world_, ecs_pair(first, second));
1151 }
1152
1158 template <typename T>
1159 int count() const {
1160 return count(_::type<T>::id(world_));
1161 }
1162
1169 template <typename First>
1170 int count(flecs::entity_t second) const {
1171 return count(_::type<First>::id(world_), second);
1172 }
1173
1180 template <typename First, typename Second>
1181 int count() const {
1182 return count(
1185 }
1186
1189 template <typename Func>
1190 void with(id_t with_id, const Func& func) const {
1191 ecs_id_t prev = ecs_set_with(world_, with_id);
1192 func();
1193 ecs_set_with(world_, prev);
1194 }
1195
1198 template <typename T, typename Func>
1199 void with(const Func& func) const {
1200 with(this->id<T>(), func);
1201 }
1202
1205 template <typename First, typename Second, typename Func>
1206 void with(const Func& func) const {
1207 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
1208 }
1209
1212 template <typename First, typename Func>
1213 void with(id_t second, const Func& func) const {
1214 with(ecs_pair(this->id<First>(), second), func);
1215 }
1216
1219 template <typename Func>
1220 void with(id_t first, id_t second, const Func& func) const {
1221 with(ecs_pair(first, second), func);
1222 }
1223
1227 template <typename Func>
1228 void scope(id_t parent, const Func& func) const {
1229 ecs_entity_t prev = ecs_set_scope(world_, parent);
1230 func();
1231 ecs_set_scope(world_, prev);
1232 }
1233
1236 template <typename T, typename Func>
1237 void scope(const Func& func) const {
1239 scope(parent, func);
1240 }
1241
1245 flecs::scoped_world scope(id_t parent) const;
1246
1247 template <typename T>
1248 flecs::scoped_world scope() const;
1249
1250 flecs::scoped_world scope(const char* name) const;
1251
1253 void delete_with(id_t the_id) const {
1254 ecs_delete_with(world_, the_id);
1255 }
1256
1258 void delete_with(entity_t first, entity_t second) const {
1259 delete_with(ecs_pair(first, second));
1260 }
1261
1263 template <typename T>
1264 void delete_with() const {
1266 }
1267
1269 template <typename First, typename Second>
1273
1275 template <typename First>
1276 void delete_with(entity_t second) const {
1278 }
1279
1281 void remove_all(id_t the_id) const {
1282 ecs_remove_all(world_, the_id);
1283 }
1284
1286 void remove_all(entity_t first, entity_t second) const {
1287 remove_all(ecs_pair(first, second));
1288 }
1289
1291 template <typename T>
1292 void remove_all() const {
1294 }
1295
1297 template <typename First, typename Second>
1301
1303 template <typename First>
1304 void remove_all(entity_t second) const {
1306 }
1307
1316 template <typename Func>
1317 void defer(const Func& func) const {
1319 func();
1321 }
1322
1332 void defer_suspend() const {
1334 }
1335
1345 void defer_resume() const {
1347 }
1348
1355 bool exists(flecs::entity_t e) const {
1356 return ecs_exists(world_, e);
1357 }
1358
1366 return ecs_is_alive(world_, e);
1367 }
1368
1377 return ecs_is_valid(world_, e);
1378 }
1379
1386
1391
1398 }
1399
1404 uint32_t get_version(flecs::entity_t e) const {
1405 return ecs_get_version(e);
1406 }
1407
1409 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1410 ecs_run_post_frame(world_, action, ctx);
1411 }
1412
1418 return ecs_get_world_info(world_);
1419 }
1420
1423 return get_info()->delta_time;
1424 }
1425
1430 void shrink() const {
1432 }
1433
1439 void exclusive_access_begin(const char *thread_name = nullptr) {
1440 ecs_exclusive_access_begin(world_, thread_name);
1441 }
1442
1448 void exclusive_access_end(bool lock_world = false) {
1449 ecs_exclusive_access_end(world_, lock_world);
1450 }
1451
1458 template <typename T>
1461 return _::type<T>::id(world_);
1462 }
1463 else {
1464 return 0;
1465 }
1466 }
1467
1472
1475 return ecs_get_type_info(world_, ecs_pair(r, t));
1476 }
1477
1479 template <typename T>
1483
1485 template <typename R>
1489
1491 template <typename R, typename T>
1493 return type_info<R>(_::type<T>::id(world_));
1494 }
1495
1496# include "mixins/id/mixin.inl"
1498# include "mixins/entity/mixin.inl"
1499# include "mixins/event/mixin.inl"
1500# include "mixins/term/mixin.inl"
1501# include "mixins/observer/mixin.inl"
1502# include "mixins/query/mixin.inl"
1503# include "mixins/enum/mixin.inl"
1504
1505# ifdef FLECS_MODULE
1506# include "mixins/module/mixin.inl"
1507# endif
1508# ifdef FLECS_PIPELINE
1509# include "mixins/pipeline/mixin.inl"
1510# endif
1511# ifdef FLECS_SYSTEM
1512# include "mixins/system/mixin.inl"
1513# endif
1514# ifdef FLECS_TIMER
1515# include "mixins/timer/mixin.inl"
1516# endif
1517# ifdef FLECS_SCRIPT
1518# include "mixins/script/mixin.inl"
1519# endif
1520# ifdef FLECS_META
1521# include "mixins/meta/world.inl"
1522# endif
1523# ifdef FLECS_JSON
1524# include "mixins/json/world.inl"
1525# endif
1526# ifdef FLECS_APP
1527# include "mixins/app/mixin.inl"
1528# endif
1529# ifdef FLECS_METRICS
1530# include "mixins/metrics/mixin.inl"
1531# endif
1532# ifdef FLECS_ALERTS
1533# include "mixins/alerts/mixin.inl"
1534# endif
1535
1536public:
1539
1541};
1542
1553 flecs::world_t *w,
1554 flecs::entity_t s) : world(w)
1555 {
1556 prev_scope_ = ecs_set_scope(w, s);
1557 }
1558
1563
1565 scoped_world(const scoped_world& obj) : world(nullptr) {
1567 world_ = obj.world_;
1568 flecs_poly_claim(world_);
1569 }
1570
1572};
1573
1576} // 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:669
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:671
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:432
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:385
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:429
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:378
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:645
void(* ecs_ctx_free_t)(void *ctx)
Function to clean up context data.
Definition flecs.h:650
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_entity_range_set(ecs_world_t *world, const ecs_entity_range_t *range)
Set the active entity range.
const ecs_entity_range_t * ecs_entity_range_new(ecs_world_t *world, uint32_t min, uint32_t max)
Create a new entity range.
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.
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.
const ecs_entity_range_t * ecs_entity_range_get(const ecs_world_t *world)
Get the currently active entity id range.
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:2850
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 stores an entity id range.
Definition flecs.h:1552
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1023
Type that contains information about the world.
Definition flecs.h:1482
float delta_time
Time passed to or computed by ecs_progress().
Definition flecs.h:1486
Component class.
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1546
~scoped_world()
Destructor.
Definition world.hpp:1560
scoped_world(flecs::world_t *w, flecs::entity_t s)
Create a scoped world.
Definition world.hpp:1552
flecs::entity_t prev_scope_
The previous scope entity.
Definition world.hpp:1571
scoped_world(const scoped_world &obj)
Copy constructor.
Definition world.hpp:1565
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:1430
uint32_t get_version(flecs::entity_t e) const
Get the version of the provided entity.
Definition world.hpp:1404
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1264
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:1281
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1276
void merge() const
Merge world or stage.
Definition world.hpp:574
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1540
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1253
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1417
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:803
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1422
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:1480
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:1206
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:1159
void exclusive_access_begin(const char *thread_name=nullptr)
Begin exclusive access.
Definition world.hpp:1439
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:1317
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:1365
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:762
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1332
void set(const A &value) const
Set singleton pair.
Definition world.hpp:795
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:1376
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:1237
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1345
void range_set(const ecs_entity_range_t *range) const
Set the active entity id range.
Definition world.hpp:719
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:1396
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:1190
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:1474
int count() const
Count entities matching a pair.
Definition world.hpp:1181
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:1298
const ecs_entity_range_t * range_get() const
Get the currently active entity id range.
Definition world.hpp:726
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:1149
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1304
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:1228
void with(const Func &func) const
All entities created in the function are created with the type.
Definition world.hpp:1199
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1286
void modified() const
Mark singleton component as modified.
Definition world.hpp:118
world(world &&obj) noexcept
Move constructor.
Definition world.hpp:288
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1170
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:1459
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:779
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:1220
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:786
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:1355
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:1409
const ecs_entity_range_t * range_new(uint32_t min, uint32_t max) const
Create a new entity id range.
Definition world.hpp:712
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:1469
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:1258
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1270
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:1448
void with(id_t second, const Func &func) const
All entities created in the function are created with the pair.
Definition world.hpp:1213
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:1139
const flecs::type_info_t * type_info()
Return the type info.
Definition world.hpp:1492
const flecs::type_info_t * type_info(flecs::entity_t t)
Return the type info.
Definition world.hpp:1486
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:1292
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