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
244struct world {
247 explicit world()
248 : world_( ecs_init() ) {
250 }
251
256 explicit world(int argc, char *argv[])
257 : world_( ecs_init_w_args(argc, argv) ) {
259 }
260
263 explicit world(world_t *w)
264 : world_( w ) {
265 if (w) {
266 flecs_poly_claim(w);
267 }
268 }
269
272 world(const world& obj) {
273 this->world_ = obj.world_;
274 flecs_poly_claim(this->world_);
275 }
276
278 world& operator=(const world& obj) noexcept {
279 release();
280 this->world_ = obj.world_;
281 flecs_poly_claim(this->world_);
282 return *this;
283 }
284
286 world(world&& obj) noexcept {
287 world_ = obj.world_;
288 obj.world_ = nullptr;
289 }
290
292 world& operator=(world&& obj) noexcept {
293 release();
294 world_ = obj.world_;
295 obj.world_ = nullptr;
296 return *this;
297 }
298
302 void release() {
303 if (world_) {
304 if (!flecs_poly_release(world_)) {
305 if (ecs_stage_get_id(world_) == -1) {
307 } else {
308 // Before we call ecs_fini(), we increment the reference count back to 1.
309 // Otherwise, copies of this object created during ecs_fini() (e.g., a component on_remove hook)
310 // would again call this destructor and ecs_fini().
311 flecs_poly_claim(world_);
313 }
314 }
315 world_ = nullptr;
316 }
317 }
318
321 release();
322 }
323
325 operator world_t*() const { return world_; }
326
334 void make_owner() {
335 flecs_poly_release(world_);
336 }
337
339 void reset() {
340 /* Make sure there's only one reference to the world. */
341 ecs_assert(flecs_poly_refcount(world_) == 1, ECS_INVALID_OPERATION,
342 "reset would invalidate other handles");
344 world_ = ecs_init();
346 }
347
350 world_t* c_ptr() const {
351 return world_;
352 }
353
357 void quit() const {
359 }
360
363 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
364 ecs_atfini(world_, action, ctx);
365 }
366
369 bool should_quit() const {
370 return ecs_should_quit(world_);
371 }
372
396 }
397
407 void frame_end() const {
409 }
410
421 bool readonly_begin(bool multi_threaded = false) const {
422 return ecs_readonly_begin(world_, multi_threaded);
423 }
424
431 void readonly_end() const {
433 }
434
451 bool defer_begin() const {
452 return ecs_defer_begin(world_);
453 }
454
470 bool defer_end() const {
471 return ecs_defer_end(world_);
472 }
473
486 bool is_deferred() const {
487 return ecs_is_deferred(world_);
488 }
489
502 bool is_defer_suspended() const {
504 }
505
521 void set_stage_count(int32_t stages) const {
523 }
524
533 int32_t get_stage_count() const {
535 }
536
543 int32_t get_stage_id() const {
544 return ecs_stage_get_id(world_);
545 }
546
553 bool is_stage() const {
558 "flecs::world instance contains invalid reference to world or stage");
560 }
561
572 void merge() const {
574 }
575
590 flecs::world get_stage(int32_t stage_id) const {
591 return flecs::world(ecs_get_stage(world_, stage_id));
592 }
593
611 flecs_poly_release(as); // World object will claim.
612 return flecs::world(as);
613 }
614
622 /* Safe cast, mutability is checked. */
623 return flecs::world(
624 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
625 }
626
637 bool is_readonly() const {
639 }
640
651 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
652 ecs_set_ctx(world_, ctx, ctx_free);
653 }
654
664 void* get_ctx() const {
665 return ecs_get_ctx(world_);
666 }
667
679 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
680 ecs_set_binding_ctx(world_, ctx, ctx_free);
681 }
682
692 void* get_binding_ctx() const {
694 }
695
703 void dim(int32_t entity_count) const {
704 ecs_dim(world_, entity_count);
705 }
706
710 const ecs_entity_range_t* range_new(uint32_t min, uint32_t max) const {
711 return ecs_entity_range_new(world_, min, max);
712 }
713
717 void range_set(const ecs_entity_range_t *range) const {
719 }
720
726 }
727
737
745 flecs::entity get_scope() const;
746
752 template <typename T>
753 flecs::entity set_scope() const;
754
761 return ecs_set_lookup_path(world_, search_path);
762 }
763
772 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
773
776 template <typename T, if_t< !is_callable<T>::value > = 0>
777 void set(const T& value) const {
778 flecs::set<T>(world_, _::type<T>::id(world_), value);
779 }
780
783 template <typename T, if_t< !is_callable<T>::value > = 0>
784 void set(T&& value) const {
785 flecs::set<T>(world_, _::type<T>::id(world_),
786 FLECS_FWD(value));
787 }
788
791 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
792 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
793 void set(const A& value) const {
794 flecs::set<P>(world_, _::type<First>::id(world_), value);
795 }
796
799 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
800 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
801 void set(A&& value) const {
802 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
803 }
804
807 template <typename First, typename Second>
808 void set(Second second, const First& value) const;
809
812 template <typename First, typename Second>
813 void set(Second second, First&& value) const;
814
817 template <typename Func, if_t< is_callable<Func>::value > = 0 >
818 void set(const Func& func) const;
819
820 template <typename T, typename ... Args>
821 void emplace(Args&&... args) const {
822 flecs::id_t component_id = _::type<T>::id(world_);
823 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
824 }
825
828 #ifndef ensure
829 template <typename T>
830 T& ensure() const;
831 #endif
832
835 template <typename T>
836 void modified() const;
837
840 template <typename T>
841 ref<T> get_ref() const;
842
843
844 /* try_get */
845
848 const void* try_get(flecs::id_t id) const;
849
852 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
853
856 template <typename T>
857 const T* try_get() const;
858
861 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
862 typename A = actual_type_t<P>>
863 const A* try_get() const;
864
867 template <typename First, typename Second>
868 const First* try_get(Second second) const;
869
870
871 /* get */
872
875 const void* get(flecs::id_t id) const;
876
879 const void* get(flecs::entity_t r, flecs::entity_t t) const;
880
881 template <typename T>
882 const T& get() const;
883
886 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
887 typename A = actual_type_t<P>>
888 const A& get() const;
889
892 template <typename First, typename Second>
893 const First& get(Second second) const;
894
897 template <typename Func, if_t< is_callable<Func>::value > = 0 >
898 void get(const Func& func) const;
899
900
901 /* try_get_mut */
902
905 void* try_get_mut(flecs::id_t id) const;
906
910
911 template <typename T>
912 T* try_get_mut() const;
913
916 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
917 typename A = actual_type_t<P>>
918 A* try_get_mut() const;
919
922 template <typename First, typename Second>
923 First* try_get_mut(Second second) const;
924
925
926 /* get_mut */
927
930 void* get_mut(flecs::id_t id) const;
931
934 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
935
936 template <typename T>
937 T& get_mut() const;
938
941 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
942 typename A = actual_type_t<P>>
943 A& get_mut() const;
944
947 template <typename First, typename Second>
948 First& get_mut(Second second) const;
949
950
956 template <typename T>
957 bool has() const;
958
965 template <typename First, typename Second>
966 bool has() const;
967
974 template <typename First>
975 bool has(flecs::id_t second) const;
976
983 bool has(flecs::id_t first, flecs::id_t second) const;
984
991 template <typename E, if_t< is_enum<E>::value > = 0>
992 bool has(E value) const;
993
996 template <typename T>
997 void add() const;
998
1004 template <typename First, typename Second>
1005 void add() const;
1006
1012 template <typename First>
1013 void add(flecs::entity_t second) const;
1014
1020 void add(flecs::entity_t first, flecs::entity_t second) const;
1021
1027 template <typename E, if_t< is_enum<E>::value > = 0>
1028 void add(E value) const;
1029
1032 template <typename T>
1033 void remove() const;
1034
1040 template <typename First, typename Second>
1041 void remove() const;
1042
1048 template <typename First>
1049 void remove(flecs::entity_t second) const;
1050
1056 void remove(flecs::entity_t first, flecs::entity_t second) const;
1057
1065 template <typename Func>
1066 void children(Func&& f) const;
1067
1070 template <typename T>
1071 flecs::entity singleton() const;
1072
1082 template<typename First>
1083 flecs::entity target(int32_t index = 0) const;
1084
1095 template<typename T>
1096 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1097
1107 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1108
1115 template <typename T>
1116 flecs::entity use(const char *alias = nullptr) const;
1117
1123 flecs::entity use(const char *name, const char *alias = nullptr) const;
1124
1130 void use(flecs::entity entity, const char *alias = nullptr) const;
1131
1137 int count(flecs::id_t component_id) const {
1138 return ecs_count_id(world_, component_id);
1139 }
1140
1147 int count(flecs::entity_t first, flecs::entity_t second) const {
1148 return ecs_count_id(world_, ecs_pair(first, second));
1149 }
1150
1156 template <typename T>
1157 int count() const {
1158 return count(_::type<T>::id(world_));
1159 }
1160
1167 template <typename First>
1168 int count(flecs::entity_t second) const {
1169 return count(_::type<First>::id(world_), second);
1170 }
1171
1178 template <typename First, typename Second>
1179 int count() const {
1180 return count(
1183 }
1184
1187 template <typename Func>
1188 void with(id_t with_id, const Func& func) const {
1189 ecs_id_t prev = ecs_set_with(world_, with_id);
1190 func();
1191 ecs_set_with(world_, prev);
1192 }
1193
1196 template <typename T, typename Func>
1197 void with(const Func& func) const {
1198 with(this->id<T>(), func);
1199 }
1200
1203 template <typename First, typename Second, typename Func>
1204 void with(const Func& func) const {
1205 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
1206 }
1207
1210 template <typename First, typename Func>
1211 void with(id_t second, const Func& func) const {
1212 with(ecs_pair(this->id<First>(), second), func);
1213 }
1214
1217 template <typename Func>
1218 void with(id_t first, id_t second, const Func& func) const {
1219 with(ecs_pair(first, second), func);
1220 }
1221
1225 template <typename Func>
1226 void scope(id_t parent, const Func& func) const {
1227 ecs_entity_t prev = ecs_set_scope(world_, parent);
1228 func();
1229 ecs_set_scope(world_, prev);
1230 }
1231
1234 template <typename T, typename Func>
1235 void scope(const Func& func) const {
1237 scope(parent, func);
1238 }
1239
1241 void delete_with(id_t the_id) const {
1242 ecs_delete_with(world_, the_id);
1243 }
1244
1246 void delete_with(entity_t first, entity_t second) const {
1247 delete_with(ecs_pair(first, second));
1248 }
1249
1251 template <typename T>
1252 void delete_with() const {
1254 }
1255
1257 template <typename First, typename Second>
1261
1263 template <typename First>
1264 void delete_with(entity_t second) const {
1266 }
1267
1269 void remove_all(id_t the_id) const {
1270 ecs_remove_all(world_, the_id);
1271 }
1272
1274 void remove_all(entity_t first, entity_t second) const {
1275 remove_all(ecs_pair(first, second));
1276 }
1277
1279 template <typename T>
1280 void remove_all() const {
1282 }
1283
1285 template <typename First, typename Second>
1289
1291 template <typename First>
1292 void remove_all(entity_t second) const {
1294 }
1295
1304 template <typename Func>
1305 void defer(const Func& func) const {
1307 func();
1309 }
1310
1320 void defer_suspend() const {
1322 }
1323
1333 void defer_resume() const {
1335 }
1336
1343 bool exists(flecs::entity_t e) const {
1344 return ecs_exists(world_, e);
1345 }
1346
1354 return ecs_is_alive(world_, e);
1355 }
1356
1365 return ecs_is_valid(world_, e);
1366 }
1367
1374
1379
1386 }
1387
1392 uint32_t get_version(flecs::entity_t e) const {
1393 return ecs_get_version(e);
1394 }
1395
1397 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1398 ecs_run_post_frame(world_, action, ctx);
1399 }
1400
1406 return ecs_get_world_info(world_);
1407 }
1408
1411 return get_info()->delta_time;
1412 }
1413
1418 void shrink() const {
1420 }
1421
1427 void exclusive_access_begin(const char *thread_name = nullptr) {
1428 ecs_exclusive_access_begin(world_, thread_name);
1429 }
1430
1436 void exclusive_access_end(bool lock_world = false) {
1437 ecs_exclusive_access_end(world_, lock_world);
1438 }
1439
1446 template <typename T>
1449 return _::type<T>::id(world_);
1450 }
1451 else {
1452 return 0;
1453 }
1454 }
1455
1460
1463 return ecs_get_type_info(world_, ecs_pair(r, t));
1464 }
1465
1467 template <typename T>
1471
1473 template <typename R>
1477
1479 template <typename R, typename T>
1481 return type_info<R>(_::type<T>::id(world_));
1482 }
1483
1484# include "mixins/id/mixin.inl"
1486# include "mixins/entity/mixin.inl"
1487# include "mixins/event/mixin.inl"
1488# include "mixins/term/mixin.inl"
1489# include "mixins/observer/mixin.inl"
1490# include "mixins/query/mixin.inl"
1491# include "mixins/enum/mixin.inl"
1492
1493# ifdef FLECS_MODULE
1494# include "mixins/module/mixin.inl"
1495# endif
1496# ifdef FLECS_PIPELINE
1497# include "mixins/pipeline/mixin.inl"
1498# endif
1499# ifdef FLECS_SYSTEM
1500# include "mixins/system/mixin.inl"
1501# endif
1502# ifdef FLECS_TIMER
1503# include "mixins/timer/mixin.inl"
1504# endif
1505# ifdef FLECS_SCRIPT
1506# include "mixins/script/mixin.inl"
1507# endif
1508# ifdef FLECS_META
1509# include "mixins/meta/world.inl"
1510# endif
1511# ifdef FLECS_JSON
1512# include "mixins/json/world.inl"
1513# endif
1514# ifdef FLECS_APP
1515# include "mixins/app/mixin.inl"
1516# endif
1517# ifdef FLECS_METRICS
1518# include "mixins/metrics/mixin.inl"
1519# endif
1520# ifdef FLECS_ALERTS
1521# include "mixins/alerts/mixin.inl"
1522# endif
1523
1524public:
1527
1529};
1530
1533} // 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:433
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:386
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:430
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:379
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:646
void(* ecs_ctx_free_t)(void *ctx)
Function to clean up context data.
Definition flecs.h:651
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:2892
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:1594
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1037
Type that contains information about the world.
Definition flecs.h:1524
float delta_time
Time passed to or computed by ecs_progress().
Definition flecs.h:1528
Component class.
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
The world.
Definition world.hpp:244
bool is_stage() const
Test if this is a stage.
Definition world.hpp:553
void shrink() const
Free unused memory.
Definition world.hpp:1418
uint32_t get_version(flecs::entity_t e) const
Get the version of the provided entity.
Definition world.hpp:1392
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1252
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:1269
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1264
void merge() const
Merge world or stage.
Definition world.hpp:572
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1528
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1241
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1405
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:801
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1410
void quit() const
Signal application should quit.
Definition world.hpp:357
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:1468
void readonly_end() const
End readonly mode.
Definition world.hpp:431
void with(const Func &func) const
All entities created in the function are created with the pair.
Definition world.hpp:1204
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:1157
void exclusive_access_begin(const char *thread_name=nullptr)
Begin exclusive access.
Definition world.hpp:1427
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:1305
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:369
bool is_alive(flecs::entity_t e) const
Check if entity is alive.
Definition world.hpp:1353
world_t * c_ptr() const
Obtain a pointer to the C world object.
Definition world.hpp:350
const T * try_get() const
Get singleton component.
Definition world.hpp:158
~world()
Destructor.
Definition world.hpp:320
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:451
void reset()
Delete and recreate the world.
Definition world.hpp:339
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:760
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1320
void set(const A &value) const
Set singleton pair.
Definition world.hpp:793
void make_owner()
Make the current world object the owner of the world.
Definition world.hpp:334
bool is_valid(flecs::entity_t e) const
Check if entity ID is valid.
Definition world.hpp:1364
flecs::world async_stage() const
Create an asynchronous stage.
Definition world.hpp:609
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:486
void release()
Release the underlying world object.
Definition world.hpp:302
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:692
int32_t get_stage_id() const
Get current stage ID.
Definition world.hpp:543
void init_builtin_components()
Initialize built-in components.
Definition world.hpp:12
world(const world &obj)
Copy constructor.
Definition world.hpp:272
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:1235
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1333
void range_set(const ecs_entity_range_t *range) const
Set the active entity id range.
Definition world.hpp:717
void dim(int32_t entity_count) const
Preallocate memory for a number of entities.
Definition world.hpp:703
void set_version(flecs::entity_t e) const
Set the version of an entity to the provided value.
Definition world.hpp:1384
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:521
void with(id_t with_id, const Func &func) const
All entities created in the function are created with the ID.
Definition world.hpp:1188
void * get_ctx() const
Get world context.
Definition world.hpp:664
const flecs::type_info_t * type_info(flecs::entity_t r, flecs::entity_t t)
Return the type info.
Definition world.hpp:1462
int count() const
Count entities matching a pair.
Definition world.hpp:1179
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1286
const ecs_entity_range_t * range_get() const
Get the currently active entity id range.
Definition world.hpp:724
bool defer_end() const
End block of operations to defer.
Definition world.hpp:470
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1147
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1292
world(world_t *w)
Create a world from a C world.
Definition world.hpp:263
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:621
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:1226
void with(const Func &func) const
All entities created in the function are created with the type.
Definition world.hpp:1197
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1274
void modified() const
Mark singleton component as modified.
Definition world.hpp:118
world(world &&obj) noexcept
Move constructor.
Definition world.hpp:286
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1168
world & operator=(const world &obj) noexcept
Copy assignment operator.
Definition world.hpp:278
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:1447
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:394
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:637
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:421
void set(const T &value) const
Set singleton component.
Definition world.hpp:777
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:1218
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:590
void set(T &&value) const
Set singleton component.
Definition world.hpp:784
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:1343
world()
Create a world.
Definition world.hpp:247
void frame_end() const
End frame.
Definition world.hpp:407
void run_post_frame(ecs_fini_action_t action, void *ctx) const
Run callback after completing the frame.
Definition world.hpp:1397
const ecs_entity_range_t * range_new(uint32_t min, uint32_t max) const
Create a new entity id range.
Definition world.hpp:710
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:679
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:363
const flecs::type_info_t * type_info(flecs::id_t component)
Return the type info.
Definition world.hpp:1457
int32_t get_stage_count() const
Get the number of configured stages.
Definition world.hpp:533
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1246
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1258
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:1436
void with(id_t second, const Func &func) const
All entities created in the function are created with the pair.
Definition world.hpp:1211
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:651
bool is_defer_suspended() const
Test whether deferring is suspended.
Definition world.hpp:502
world(int argc, char *argv[])
Create a world with command-line arguments.
Definition world.hpp:256
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:1137
const flecs::type_info_t * type_info()
Return the type info.
Definition world.hpp:1480
const flecs::type_info_t * type_info(flecs::entity_t t)
Return the type info.
Definition world.hpp:1474
world & operator=(world &&obj) noexcept
Move assignment operator.
Definition world.hpp:292
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1280
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