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
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
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
356 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
357 ecs_atfini(world_, action, ctx);
358 }
359
370 bool readonly_begin(bool multi_threaded = false) const {
371 return ecs_readonly_begin(world_, multi_threaded);
372 }
373
380 void readonly_end() const {
382 }
383
400 bool defer_begin() const {
401 return ecs_defer_begin(world_);
402 }
403
419 bool defer_end() const {
420 return ecs_defer_end(world_);
421 }
422
435 bool is_deferred() const {
436 return ecs_is_deferred(world_);
437 }
438
451 bool is_defer_suspended() const {
453 }
454
470 void set_stage_count(int32_t stages) const {
472 }
473
482 int32_t get_stage_count() const {
484 }
485
492 int32_t get_stage_id() const {
493 return ecs_stage_get_id(world_);
494 }
495
502 bool is_stage() const {
507 "flecs::world instance contains invalid reference to world or stage");
509 }
510
521 void merge() const {
523 }
524
539 flecs::world get_stage(int32_t stage_id) const {
540 return flecs::world(ecs_get_stage(world_, stage_id));
541 }
542
560 flecs_poly_release(as); // World object will claim.
561 return flecs::world(as);
562 }
563
571 /* Safe cast, mutability is checked. */
572 return flecs::world(
573 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
574 }
575
586 bool is_readonly() const {
588 }
589
600 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
601 ecs_set_ctx(world_, ctx, ctx_free);
602 }
603
613 void* get_ctx() const {
614 return ecs_get_ctx(world_);
615 }
616
628 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
629 ecs_set_binding_ctx(world_, ctx, ctx_free);
630 }
631
641 void* get_binding_ctx() const {
643 }
644
652 void dim(int32_t entity_count) const {
653 ecs_dim(world_, entity_count);
654 }
655
665
673 flecs::entity get_scope() const;
674
680 template <typename T>
681 flecs::entity set_scope() const;
682
689 return ecs_set_lookup_path(world_, search_path);
690 }
691
700 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
701
704 template <typename T, if_t< !is_callable<T>::value > = 0>
705 void set(const T& value) const {
706 flecs::set<T>(world_, _::type<T>::id(world_), value);
707 }
708
711 template <typename T, if_t< !is_callable<T>::value > = 0>
712 void set(T&& value) const {
713 flecs::set<T>(world_, _::type<T>::id(world_),
714 FLECS_FWD(value));
715 }
716
719 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
720 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
721 void set(const A& value) const {
722 flecs::set<P>(world_, _::type<First>::id(world_), value);
723 }
724
727 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
728 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
729 void set(A&& value) const {
730 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
731 }
732
735 template <typename First, typename Second>
736 void set(Second second, const First& value) const;
737
740 template <typename First, typename Second>
741 void set(Second second, First&& value) const;
742
745 template <typename Func, if_t< is_callable<Func>::value > = 0 >
746 void set(const Func& func) const;
747
748 template <typename T, typename ... Args>
749 void emplace(Args&&... args) const {
750 flecs::id_t component_id = _::type<T>::id(world_);
751 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
752 }
753
756 #ifndef ensure
757 template <typename T>
758 T& ensure() const;
759 #endif
760
763 template <typename T>
764 void modified() const;
765
768 template <typename T>
769 ref<T> get_ref() const;
770
771
772 /* try_get */
773
776 const void* try_get(flecs::id_t id) const;
777
780 const void* try_get(flecs::entity_t r, flecs::entity_t t) const;
781
784 template <typename T>
785 const T* try_get() const;
786
789 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
790 typename A = actual_type_t<P>>
791 const A* try_get() const;
792
795 template <typename First, typename Second>
796 const First* try_get(Second second) const;
797
798
799 /* get */
800
803 const void* get(flecs::id_t id) const;
804
807 const void* get(flecs::entity_t r, flecs::entity_t t) const;
808
809 template <typename T>
810 const T& get() const;
811
814 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
815 typename A = actual_type_t<P>>
816 const A& get() const;
817
820 template <typename First, typename Second>
821 const First& get(Second second) const;
822
825 template <typename Func, if_t< is_callable<Func>::value > = 0 >
826 void get(const Func& func) const;
827
828
829 /* try_get_mut */
830
833 void* try_get_mut(flecs::id_t id) const;
834
838
839 template <typename T>
840 T* try_get_mut() const;
841
844 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
845 typename A = actual_type_t<P>>
846 A* try_get_mut() const;
847
850 template <typename First, typename Second>
851 First* try_get_mut(Second second) const;
852
853
854 /* get_mut */
855
858 void* get_mut(flecs::id_t id) const;
859
862 void* get_mut(flecs::entity_t r, flecs::entity_t t) const;
863
864 template <typename T>
865 T& get_mut() const;
866
869 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
870 typename A = actual_type_t<P>>
871 A& get_mut() const;
872
875 template <typename First, typename Second>
876 First& get_mut(Second second) const;
877
878
884 template <typename T>
885 bool has() const;
886
893 template <typename First, typename Second>
894 bool has() const;
895
902 template <typename First>
903 bool has(flecs::id_t second) const;
904
911 bool has(flecs::id_t first, flecs::id_t second) const;
912
919 template <typename E, if_t< is_enum<E>::value > = 0>
920 bool has(E value) const;
921
924 template <typename T>
925 void add() const;
926
932 template <typename First, typename Second>
933 void add() const;
934
940 template <typename First>
941 void add(flecs::entity_t second) const;
942
948 void add(flecs::entity_t first, flecs::entity_t second) const;
949
955 template <typename E, if_t< is_enum<E>::value > = 0>
956 void add(E value) const;
957
960 template <typename T>
961 void remove() const;
962
968 template <typename First, typename Second>
969 void remove() const;
970
976 template <typename First>
977 void remove(flecs::entity_t second) const;
978
984 void remove(flecs::entity_t first, flecs::entity_t second) const;
985
993 template <typename Func>
994 void children(Func&& f) const;
995
998 template <typename T>
999 flecs::entity singleton() const;
1000
1010 template<typename First>
1011 flecs::entity target(int32_t index = 0) const;
1012
1023 template<typename T>
1024 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1025
1035 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
1036
1043 template <typename T>
1044 flecs::entity use(const char *alias = nullptr) const;
1045
1051 flecs::entity use(const char *name, const char *alias = nullptr) const;
1052
1058 void use(flecs::entity entity, const char *alias = nullptr) const;
1059
1065 int count(flecs::id_t component_id) const {
1066 return ecs_count_id(world_, component_id);
1067 }
1068
1075 int count(flecs::entity_t first, flecs::entity_t second) const {
1076 return ecs_count_id(world_, ecs_pair(first, second));
1077 }
1078
1084 template <typename T>
1085 int count() const {
1086 return count(_::type<T>::id(world_));
1087 }
1088
1095 template <typename First>
1096 int count(flecs::entity_t second) const {
1097 return count(_::type<First>::id(world_), second);
1098 }
1099
1106 template <typename First, typename Second>
1107 int count() const {
1108 return count(
1111 }
1112
1116 template <typename Func>
1117 void scope(id_t parent, const Func& func) const {
1118 ecs_entity_t prev = ecs_set_scope(world_, parent);
1119 func();
1120 ecs_set_scope(world_, prev);
1121 }
1122
1125 template <typename T, typename Func>
1126 void scope(const Func& func) const {
1128 scope(parent, func);
1129 }
1130
1132 void delete_with(id_t the_id) const {
1133 ecs_delete_with(world_, the_id);
1134 }
1135
1137 void delete_with(entity_t first, entity_t second) const {
1138 delete_with(ecs_pair(first, second));
1139 }
1140
1142 template <typename T>
1143 void delete_with() const {
1145 }
1146
1148 template <typename First, typename Second>
1152
1154 template <typename First>
1155 void delete_with(entity_t second) const {
1157 }
1158
1160 void remove_all(id_t the_id) const {
1161 ecs_remove_all(world_, the_id);
1162 }
1163
1165 void remove_all(entity_t first, entity_t second) const {
1166 remove_all(ecs_pair(first, second));
1167 }
1168
1170 template <typename T>
1171 void remove_all() const {
1173 }
1174
1176 template <typename First, typename Second>
1180
1182 template <typename First>
1183 void remove_all(entity_t second) const {
1185 }
1186
1195 template <typename Func>
1196 void defer(const Func& func) const {
1198 func();
1200 }
1201
1211 void defer_suspend() const {
1213 }
1214
1224 void defer_resume() const {
1226 }
1227
1234 bool exists(flecs::entity_t e) const {
1235 return ecs_exists(world_, e);
1236 }
1237
1245 return ecs_is_alive(world_, e);
1246 }
1247
1256 return ecs_is_valid(world_, e);
1257 }
1258
1265
1270
1277 }
1278
1283 uint32_t get_version(flecs::entity_t e) const {
1284 return ecs_get_version(e);
1285 }
1286
1292 return ecs_get_world_info(world_);
1293 }
1294
1297 return get_info()->delta_time;
1298 }
1299
1304 void shrink() const {
1306 }
1307
1313 void exclusive_access_begin(const char *thread_name = nullptr) {
1314 ecs_exclusive_access_begin(world_, thread_name);
1315 }
1316
1322 void exclusive_access_end(bool lock_world = false) {
1323 ecs_exclusive_access_end(world_, lock_world);
1324 }
1325
1332 template <typename T>
1335 return _::type<T>::id(world_);
1336 }
1337 else {
1338 return 0;
1339 }
1340 }
1341
1346
1349 return ecs_get_type_info(world_, ecs_pair(r, t));
1350 }
1351
1353 template <typename T>
1357
1359 template <typename R>
1363
1365 template <typename R, typename T>
1367 return type_info<R>(_::type<T>::id(world_));
1368 }
1369
1370# include "mixins/id/mixin.inl"
1372# include "mixins/entity/mixin.inl"
1373# include "mixins/event/mixin.inl"
1374# include "mixins/term/mixin.inl"
1375# include "mixins/observer/mixin.inl"
1376# include "mixins/query/mixin.inl"
1377# include "mixins/enum/mixin.inl"
1378
1379# ifdef FLECS_PREFAB
1380# include "mixins/prefab/mixin.inl"
1381# endif
1382# ifdef FLECS_ENTITY_RANGES
1384# endif
1385# ifdef FLECS_FRAME
1386# include "mixins/frame/mixin.inl"
1387# endif
1388# ifdef FLECS_MODULE
1389# include "mixins/module/mixin.inl"
1390# endif
1391# ifdef FLECS_PIPELINE
1392# include "mixins/pipeline/mixin.inl"
1393# endif
1394# ifdef FLECS_SYSTEM
1395# include "mixins/system/mixin.inl"
1396# endif
1397# ifdef FLECS_TIMER
1398# include "mixins/timer/mixin.inl"
1399# endif
1400# ifdef FLECS_SCRIPT
1401# include "mixins/script/mixin.inl"
1402# endif
1403# ifdef FLECS_META
1404# include "mixins/meta/world.inl"
1405# endif
1406# ifdef FLECS_JSON
1407# include "mixins/json/world.inl"
1408# endif
1409# ifdef FLECS_APP
1410# include "mixins/app/mixin.inl"
1411# endif
1412# ifdef FLECS_METRICS
1413# include "mixins/metrics/mixin.inl"
1414# endif
1415# ifdef FLECS_ALERTS
1416# include "mixins/alerts/mixin.inl"
1417# endif
1418
1419public:
1422
1424};
1425
1428} // namespace flecs
Alert world mixin.
App world addon mixin.
Component mixin.
Entity world mixin.
Entity ranges world mixin.
Enum world mixin.
Event world mixin.
FLECS_API FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_set(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, const void *new_ptr, size_t size)
Set a component value for a C++ entity.
FLECS_API FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_assign(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, const void *new_ptr, size_t size)
Assign a component value for a C++ entity.
Frame world mixin.
void ecs_remove_all(ecs_world_t *world, ecs_id_t component)
Remove all instances of the 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:440
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:393
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:437
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:653
void(* ecs_ctx_free_t)(void *ctx)
Function to clean up context data.
Definition flecs.h:658
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.
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.
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:2622
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.
Result type for C++ set/assign operations.
Definition flecs_cpp.h:166
bool call_modified
Whether modified should be called.
Definition flecs_cpp.h:170
ecs_stage_t * stage
The stage.
Definition flecs_cpp.h:168
ecs_world_t * world
The world.
Definition flecs_cpp.h:167
void * ptr
Pointer to the component data.
Definition flecs_cpp.h:169
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1050
Type that contains information about the world.
Definition flecs.h:1532
float delta_time
Time passed to or computed by ecs_progress().
Definition flecs.h:1536
Component class.
Entity.
Definition entity.hpp:30
The world.
Definition world.hpp:244
bool is_stage() const
Test if this is a stage.
Definition world.hpp:502
void shrink() const
Free unused memory.
Definition world.hpp:1304
uint32_t get_version(flecs::entity_t e) const
Get the version of the provided entity.
Definition world.hpp:1283
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1143
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:1160
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1155
void merge() const
Merge world or stage.
Definition world.hpp:521
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1423
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1132
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1291
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:729
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1296
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:1354
void readonly_end() const
End readonly mode.
Definition world.hpp:380
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:1085
void exclusive_access_begin(const char *thread_name=nullptr)
Begin exclusive access.
Definition world.hpp:1313
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:1196
bool is_alive(flecs::entity_t e) const
Check if entity is alive.
Definition world.hpp:1244
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:400
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:688
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1211
void set(const A &value) const
Set singleton pair.
Definition world.hpp:721
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:1255
flecs::world async_stage() const
Create an asynchronous stage.
Definition world.hpp:558
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:435
void release()
Release the underlying world object.
Definition world.hpp:302
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:641
int32_t get_stage_id() const
Get current stage ID.
Definition world.hpp:492
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:1126
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1224
void dim(int32_t entity_count) const
Preallocate memory for a number of entities.
Definition world.hpp:652
void set_version(flecs::entity_t e) const
Set the version of an entity to the provided value.
Definition world.hpp:1275
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:470
void * get_ctx() const
Get world context.
Definition world.hpp:613
const flecs::type_info_t * type_info(flecs::entity_t r, flecs::entity_t t)
Return the type info.
Definition world.hpp:1348
int count() const
Count entities matching a pair.
Definition world.hpp:1107
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1177
bool defer_end() const
End block of operations to defer.
Definition world.hpp:419
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:1075
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1183
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:570
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:1117
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1165
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:1096
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:1333
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:586
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:370
void set(const T &value) const
Set singleton component.
Definition world.hpp:705
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:539
void set(T &&value) const
Set singleton component.
Definition world.hpp:712
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:1234
world()
Create a world.
Definition world.hpp:247
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:628
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:356
const flecs::type_info_t * type_info(flecs::id_t component)
Return the type info.
Definition world.hpp:1343
int32_t get_stage_count() const
Get the number of configured stages.
Definition world.hpp:482
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1137
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1149
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:1322
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:600
bool is_defer_suspended() const
Test whether deferring is suspended.
Definition world.hpp:451
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:1065
const flecs::type_info_t * type_info()
Return the type info.
Definition world.hpp:1366
const flecs::type_info_t * type_info(flecs::entity_t t)
Return the type info.
Definition world.hpp:1360
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:1171
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