Flecs: include/flecs/addons/cpp/world.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
world.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs
9{
10
11/* Static helper functions to assign a component value */
12
13// set(T&&), T = constructible
14template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
15 inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
16 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
17 "operation invalid for empty type");
18
19 if (!ecs_is_deferred(world)) {
20 T& dst = *static_cast<T*>(ecs_ensure_id(world, entity, id));
21 dst = FLECS_MOV(value);
22
23 ecs_modified_id(world, entity, id);
24 } else {
25 T& dst = *static_cast<T*>(ecs_ensure_modified_id(world, entity, id));
26 dst = FLECS_MOV(value);
27 }
28}
29
30// set(const T&), T = constructible
31template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
32 inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
33 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
34 "operation invalid for empty type");
35
36 if (!ecs_is_deferred(world)) {
37 T& dst = *static_cast<T*>(ecs_ensure_id(world, entity, id));
38 dst = FLECS_MOV(value);
39
40 ecs_modified_id(world, entity, id);
41 } else {
42 T& dst = *static_cast<T*>(ecs_ensure_modified_id(world, entity, id));
43 dst = FLECS_MOV(value);
44 }
45}
46
47// set(T&&), T = not constructible
48template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
49inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
50 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
51 "operation invalid for empty type");
52
53 if (!ecs_is_deferred(world)) {
54 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
55 dst = FLECS_MOV(value);
56
57 ecs_modified_id(world, entity, id);
58 } else {
59 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
60 dst = FLECS_MOV(value);
61 }
62}
63
64// set(const T&), T = not constructible
65template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
66inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
67 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
68 "operation invalid for empty type");
69
70 if (!ecs_is_deferred(world)) {
71 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
72 dst = FLECS_MOV(value);
73
74 ecs_modified_id(world, entity, id);
75 } else {
76 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
77 dst = FLECS_MOV(value);
78 }
79}
80
81// emplace for T(Args...)
82template <typename T, typename ... Args, if_t<
83 std::is_constructible<actual_type_t<T>, Args...>::value ||
84 std::is_default_constructible<actual_type_t<T>>::value > = 0>
85inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
86 ecs_assert(_::type<T>::size() != 0, ECS_INVALID_PARAMETER,
87 "operation invalid for empty type");
88 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id, nullptr));
89
90 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
91
92 ecs_modified_id(world, entity, id);
93}
94
95// set(T&&)
96template <typename T, typename A>
97inline void set(world_t *world, entity_t entity, A&& value) {
98 id_t id = _::type<T>::id(world);
99 flecs::set(world, entity, FLECS_FWD(value), id);
100}
101
102// set(const T&)
103template <typename T, typename A>
104inline void set(world_t *world, entity_t entity, const A& value) {
105 id_t id = _::type<T>::id(world);
106 flecs::set(world, entity, value, id);
107}
108
113 inline flecs::id_t strip_generation(flecs::entity_t e) {
114 return ecs_strip_generation(e);
115}
116
119 inline uint32_t get_generation(flecs::entity_t e) {
120 return ECS_GENERATION(e);
121}
122
123struct scoped_world;
124
137 struct world {
140 explicit world()
141 : world_( ecs_init() ) {
142 init_builtin_components();
143 }
144
149 explicit world(int argc, char *argv[])
150 : world_( ecs_init_w_args(argc, argv) ) {
151 init_builtin_components();
152 }
153
156 explicit world(world_t *w)
157 : world_( w ) {
158 if (w) {
159 flecs_poly_claim(w);
160 }
161 }
162
165 world(const world& obj) {
166 this->world_ = obj.world_;
167 flecs_poly_claim(this->world_);
168 }
169
170 world& operator=(const world& obj) noexcept {
171 release();
172 this->world_ = obj.world_;
173 flecs_poly_claim(this->world_);
174 return *this;
175 }
176
177 world(world&& obj) noexcept {
178 world_ = obj.world_;
179 obj.world_ = nullptr;
180 }
181
182 world& operator=(world&& obj) noexcept {
183 release();
184 world_ = obj.world_;
185 obj.world_ = nullptr;
186 return *this;
187 }
188
189 /* Releases the underlying world object. If this is the last handle, the world
190 will be finalized. */
191 void release() {
192 if (world_) {
193 if (!flecs_poly_release(world_)) {
194 if (ecs_stage_get_id(world_) == -1) {
195 ecs_stage_free(world_);
196 } else {
197 // before we call ecs_fini(), we increment the reference count back to 1
198 // otherwise, copies of this object created during ecs_fini (e.g. a component on_remove hook)
199 // would call again this destructor and ecs_fini().
200 flecs_poly_claim(world_);
201 ecs_fini(world_);
202 }
203 }
204 world_ = nullptr;
205 }
206 }
207
208 ~world() {
209 release();
210 }
211
212 /* Implicit conversion to world_t* */
213 operator world_t*() const { return world_; }
214
222 void make_owner() {
223 flecs_poly_release(world_);
224 }
225
227 void reset() {
228 /* Make sure there's only one reference to the world */
229 ecs_assert(flecs_poly_refcount(world_) == 1, ECS_INVALID_OPERATION,
230 "reset would invalidate other handles");
231 ecs_fini(world_);
232 world_ = ecs_init();
233 }
234
237 world_t* c_ptr() const {
238 return world_;
239 }
240
244 void quit() const {
245 ecs_quit(world_);
246 }
247
250 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
251 ecs_atfini(world_, action, ctx);
252 }
253
256 bool should_quit() const {
257 return ecs_should_quit(world_);
258 }
259
281 ecs_ftime_t frame_begin(float delta_time = 0) const {
282 return ecs_frame_begin(world_, delta_time);
283 }
284
294 void frame_end() const {
295 ecs_frame_end(world_);
296 }
297
308 bool readonly_begin(bool multi_threaded = false) const {
309 return ecs_readonly_begin(world_, multi_threaded);
310 }
311
318 void readonly_end() const {
319 ecs_readonly_end(world_);
320 }
321
337 bool defer_begin() const {
338 return ecs_defer_begin(world_);
339 }
340
355 bool defer_end() const {
356 return ecs_defer_end(world_);
357 }
358
370 bool is_deferred() const {
371 return ecs_is_deferred(world_);
372 }
373
389 void set_stage_count(int32_t stages) const {
390 ecs_set_stage_count(world_, stages);
391 }
392
401 int32_t get_stage_count() const {
402 return ecs_get_stage_count(world_);
403 }
404
411 int32_t get_stage_id() const {
412 return ecs_stage_get_id(world_);
413 }
414
421 bool is_stage() const {
422 ecs_assert(
423 flecs_poly_is(world_, ecs_world_t) ||
424 flecs_poly_is(world_, ecs_stage_t),
425 ECS_INVALID_PARAMETER,
426 "flecs::world instance contains invalid reference to world or stage");
427 return flecs_poly_is(world_, ecs_stage_t);
428 }
429
440 void merge() const {
441 ecs_merge(world_);
442 }
443
458 flecs::world get_stage(int32_t stage_id) const {
459 return flecs::world(ecs_get_stage(world_, stage_id));
460 }
461
477 flecs::world async_stage() const {
478 ecs_world_t *as = ecs_stage_new(world_);
479 flecs_poly_release(as); // world object will claim
480 return flecs::world(as);
481 }
482
489 flecs::world get_world() const {
490 /* Safe cast, mutability is checked */
491 return flecs::world(
492 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
493 }
494
505 bool is_readonly() const {
506 return ecs_stage_is_readonly(world_);
507 }
508
520 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
521 ecs_set_ctx(world_, ctx, ctx_free);
522 }
523
533 void* get_ctx() const {
534 return ecs_get_ctx(world_);
535 }
536
548 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
549 ecs_set_binding_ctx(world_, ctx, ctx_free);
550 }
551
561 void* get_binding_ctx() const {
562 return ecs_get_binding_ctx(world_);
563 }
564
572 void dim(int32_t entity_count) const {
573 ecs_dim(world_, entity_count);
574 }
575
584 void set_entity_range(entity_t min, entity_t max) const {
585 ecs_set_entity_range(world_, min, max);
586 }
587
598 void enable_range_check(bool enabled = true) const {
599 ecs_enable_range_check(world_, enabled);
600 }
601
610 flecs::entity set_scope(const flecs::entity_t scope) const;
611
619 flecs::entity get_scope() const;
620
626 template <typename T>
627 flecs::entity set_scope() const;
628
634 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
635 return ecs_set_lookup_path(world_, search_path);
636 }
637
644 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
645
648 template <typename T, if_t< !is_callable<T>::value > = 0>
649 void set(const T& value) const {
650 flecs::set<T>(world_, _::type<T>::id(world_), value);
651 }
652
655 template <typename T, if_t< !is_callable<T>::value > = 0>
656 void set(T&& value) const {
657 flecs::set<T>(world_, _::type<T>::id(world_),
658 FLECS_FWD(value));
659 }
660
663 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
664 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
665 void set(const A& value) const {
666 flecs::set<P>(world_, _::type<First>::id(world_), value);
667 }
668
671 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
672 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
673 void set(A&& value) const {
674 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
675 }
676
679 template <typename First, typename Second>
680 void set(Second second, const First& value) const;
681
684 template <typename First, typename Second>
685 void set(Second second, First&& value) const;
686
689 template <typename Func, if_t< is_callable<Func>::value > = 0 >
690 void set(const Func& func) const;
691
692 template <typename T, typename ... Args>
693 void emplace(Args&&... args) const {
694 flecs::id_t component_id = _::type<T>::id(world_);
695 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
696 }
697
700 #ifndef ensure
701 template <typename T>
702 T& ensure() const;
703 #endif
704
707 template <typename T>
708 void modified() const;
709
712 template <typename T>
713 ref<T> get_ref() const;
714
717 template <typename T>
718 const T* get() const;
719
722 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
723 typename A = actual_type_t<P>>
724 const A* get() const;
725
728 template <typename First, typename Second>
729 const First* get(Second second) const;
730
733 template <typename Func, if_t< is_callable<Func>::value > = 0 >
734 void get(const Func& func) const;
735
738 template <typename T>
739 T* get_mut() const;
740
743 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
744 typename A = actual_type_t<P>>
745 A* get_mut() const;
746
749 template <typename First, typename Second>
750 First* get_mut(Second second) const;
751
754 template <typename T>
755 bool has() const;
756
762 template <typename First, typename Second>
763 bool has() const;
764
770 template <typename First>
771 bool has(flecs::id_t second) const;
772
778 bool has(flecs::id_t first, flecs::id_t second) const;
779
782 template <typename T>
783 void add() const;
784
790 template <typename First, typename Second>
791 void add() const;
792
798 template <typename First>
799 void add(flecs::entity_t second) const;
800
806 void add(flecs::entity_t first, flecs::entity_t second) const;
807
810 template <typename T>
811 void remove() const;
812
818 template <typename First, typename Second>
819 void remove() const;
820
826 template <typename First>
827 void remove(flecs::entity_t second) const;
828
834 void remove(flecs::entity_t first, flecs::entity_t second) const;
835
843 template <typename Func>
844 void children(Func&& f) const;
845
848 template <typename T>
849 flecs::entity singleton() const;
850
859 template<typename First>
860 flecs::entity target(int32_t index = 0) const;
861
870 template<typename T>
871 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
872
881 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
882
889 template <typename T>
890 flecs::entity use(const char *alias = nullptr) const;
891
897 flecs::entity use(const char *name, const char *alias = nullptr) const;
898
904 void use(flecs::entity entity, const char *alias = nullptr) const;
905
910 int count(flecs::id_t component_id) const {
911 return ecs_count_id(world_, component_id);
912 }
913
919 int count(flecs::entity_t first, flecs::entity_t second) const {
920 return ecs_count_id(world_, ecs_pair(first, second));
921 }
922
927 template <typename T>
928 int count() const {
929 return count(_::type<T>::id(world_));
930 }
931
937 template <typename First>
938 int count(flecs::entity_t second) const {
939 return count(_::type<First>::id(world_), second);
940 }
941
947 template <typename First, typename Second>
948 int count() const {
949 return count(
950 _::type<First>::id(world_),
951 _::type<Second>::id(world_));
952 }
953
956 template <typename Func>
957 void with(id_t with_id, const Func& func) const {
958 ecs_id_t prev = ecs_set_with(world_, with_id);
959 func();
960 ecs_set_with(world_, prev);
961 }
962
965 template <typename T, typename Func>
966 void with(const Func& func) const {
967 with(this->id<T>(), func);
968 }
969
972 template <typename First, typename Second, typename Func>
973 void with(const Func& func) const {
974 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
975 }
976
979 template <typename First, typename Func>
980 void with(id_t second, const Func& func) const {
981 with(ecs_pair(this->id<First>(), second), func);
982 }
983
986 template <typename Func>
987 void with(id_t first, id_t second, const Func& func) const {
988 with(ecs_pair(first, second), func);
989 }
990
994 template <typename Func>
995 void scope(id_t parent, const Func& func) const {
996 ecs_entity_t prev = ecs_set_scope(world_, parent);
997 func();
998 ecs_set_scope(world_, prev);
999 }
1000
1003 template <typename T, typename Func>
1004 void scope(const Func& func) const {
1005 flecs::id_t parent = _::type<T>::id(world_);
1006 scope(parent, func);
1007 }
1008
1012 flecs::scoped_world scope(id_t parent) const;
1013
1014 template <typename T>
1015 flecs::scoped_world scope() const;
1016
1017 flecs::scoped_world scope(const char* name) const;
1018
1020 void delete_with(id_t the_id) const {
1021 ecs_delete_with(world_, the_id);
1022 }
1023
1025 void delete_with(entity_t first, entity_t second) const {
1026 delete_with(ecs_pair(first, second));
1027 }
1028
1030 template <typename T>
1031 void delete_with() const {
1032 delete_with(_::type<T>::id(world_));
1033 }
1034
1036 template <typename First, typename Second>
1037 void delete_with() const {
1038 delete_with(_::type<First>::id(world_), _::type<Second>::id(world_));
1039 }
1040
1042 template <typename First>
1043 void delete_with(entity_t second) const {
1044 delete_with(_::type<First>::id(world_), second);
1045 }
1046
1048 void remove_all(id_t the_id) const {
1049 ecs_remove_all(world_, the_id);
1050 }
1051
1053 void remove_all(entity_t first, entity_t second) const {
1054 remove_all(ecs_pair(first, second));
1055 }
1056
1058 template <typename T>
1059 void remove_all() const {
1060 remove_all(_::type<T>::id(world_));
1061 }
1062
1064 template <typename First, typename Second>
1065 void remove_all() const {
1066 remove_all(_::type<First>::id(world_), _::type<Second>::id(world_));
1067 }
1068
1070 template <typename First>
1071 void remove_all(entity_t second) const {
1072 remove_all(_::type<First>::id(world_), second);
1073 }
1074
1083 template <typename Func>
1084 void defer(const Func& func) const {
1085 ecs_defer_begin(world_);
1086 func();
1087 ecs_defer_end(world_);
1088 }
1089
1099 void defer_suspend() const {
1100 ecs_defer_suspend(world_);
1101 }
1102
1112 void defer_resume() const {
1113 ecs_defer_resume(world_);
1114 }
1115
1122 bool exists(flecs::entity_t e) const {
1123 return ecs_exists(world_, e);
1124 }
1125
1132 bool is_alive(flecs::entity_t e) const {
1133 return ecs_is_alive(world_, e);
1134 }
1135
1143 bool is_valid(flecs::entity_t e) const {
1144 return ecs_is_valid(world_, e);
1145 }
1146
1152 flecs::entity get_alive(flecs::entity_t e) const;
1153
1157 flecs::entity make_alive(flecs::entity_t e) const;
1158
1159 /* Run callback after completing frame */
1160 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1161 ecs_run_post_frame(world_, action, ctx);
1162 }
1163
1168 const flecs::world_info_t* get_info() const{
1169 return ecs_get_world_info(world_);
1170 }
1171
1173 ecs_ftime_t delta_time() const {
1174 return get_info()->delta_time;
1175 }
1176
1177# include "mixins/id/mixin.inl"
1178# include "mixins/component/mixin.inl"
1179# include "mixins/entity/mixin.inl"
1180# include "mixins/event/mixin.inl"
1181# include "mixins/term/mixin.inl"
1182# include "mixins/observer/mixin.inl"
1183# include "mixins/query/mixin.inl"
1184# include "mixins/enum/mixin.inl"
1185
1186# ifdef FLECS_MODULE
1187# include "mixins/module/mixin.inl"
1188# endif
1189# ifdef FLECS_PIPELINE
1190# include "mixins/pipeline/mixin.inl"
1191# endif
1192# ifdef FLECS_SYSTEM
1193# include "mixins/system/mixin.inl"
1194# endif
1195# ifdef FLECS_TIMER
1196# include "mixins/timer/mixin.inl"
1197# endif
1198# ifdef FLECS_SCRIPT
1199# include "mixins/script/mixin.inl"
1200# endif
1201# ifdef FLECS_META
1202# include "mixins/meta/world.inl"
1203# endif
1204# ifdef FLECS_JSON
1205# include "mixins/json/world.inl"
1206# endif
1207# ifdef FLECS_APP
1208# include "mixins/app/mixin.inl"
1209# endif
1210# ifdef FLECS_METRICS
1211# include "mixins/metrics/mixin.inl"
1212# endif
1213# ifdef FLECS_ALERTS
1214# include "mixins/alerts/mixin.inl"
1215# endif
1216
1217public:
1218 void init_builtin_components();
1219
1220 world_t *world_;
1221};
1222
1226 struct scoped_world : world {
1227 scoped_world(
1228 flecs::world_t *w,
1229 flecs::entity_t s) : world(w)
1230 {
1231 prev_scope_ = ecs_set_scope(w, s);
1232 }
1233
1234 ~scoped_world() {
1235 ecs_set_scope(world_, prev_scope_);
1236 }
1237
1238 scoped_world(const scoped_world& obj) : world(nullptr) {
1239 prev_scope_ = obj.prev_scope_;
1240 world_ = obj.world_;
1241 flecs_poly_claim(world_);
1242 }
1243
1244 flecs::entity_t prev_scope_;
1245};
1246
1249} // namespace flecs
mixin.inl
App world addon mixin.
mixin.inl
Component mixin.
mixin.inl
Entity world mixin.
mixin.inl
Enum world mixin.
mixin.inl
Event world mixin.
ecs_set_with
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
ecs_remove_all
void ecs_remove_all(ecs_world_t *world, ecs_id_t id)
Remove all instances of the specified (component) id.
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
ecs_stage_new
ecs_world_t * ecs_stage_new(ecs_world_t *world)
Create unmanaged stage.
ecs_defer_end
bool ecs_defer_end(ecs_world_t *world)
End block of operations to defer.
ecs_readonly_begin
bool ecs_readonly_begin(ecs_world_t *world, bool multi_threaded)
Begin readonly mode.
ecs_defer_resume
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
ecs_defer_begin
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until end of frame.
ecs_defer_suspend
void ecs_defer_suspend(ecs_world_t *world)
Suspend deferring but do not flush queue.
ecs_is_deferred
bool ecs_is_deferred(const ecs_world_t *world)
Test if deferring is enabled for current stage.
ecs_stage_free
void ecs_stage_free(ecs_world_t *stage)
Free unmanaged stage.
ecs_merge
void ecs_merge(ecs_world_t *world)
Merge world or stage.
ecs_stage_get_id
int32_t ecs_stage_get_id(const ecs_world_t *world)
Get stage id.
ecs_stage_is_readonly
bool ecs_stage_is_readonly(const ecs_world_t *world)
Test whether the current world is readonly.
ecs_get_stage_count
int32_t ecs_get_stage_count(const ecs_world_t *world)
Get number of configured stages.
ecs_get_stage
ecs_world_t * ecs_get_stage(const ecs_world_t *world, int32_t stage_id)
Get stage-specific world pointer.
ecs_set_stage_count
void ecs_set_stage_count(ecs_world_t *world, int32_t stages)
Configure world to have N stages.
ecs_readonly_end
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
ecs_stage_t
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition flecs.h:394
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:347
ecs_world_t
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:391
ecs_id_t
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:340
flecs::world::entity
flecs::entity entity(Args &&... args) const
Create an entity.
Definition impl.hpp:195
ecs_delete_with
void ecs_delete_with(ecs_world_t *world, ecs_id_t id)
Delete all entities with the specified id.
ecs_count_id
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified id.
ecs_fini_action_t
void(* ecs_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
Definition flecs.h:611
ecs_ctx_free_t
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:616
ecs_emplace_id
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, bool *is_new)
Emplace a component.
ecs_ensure_id
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
ecs_ensure_modified_id
void * ecs_ensure_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Combines ensure + modified in single operation.
ecs_modified_id
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
ecs_strip_generation
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove generation from entity id.
ecs_is_valid
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
ecs_exists
bool ecs_exists(const ecs_world_t *world, ecs_entity_t entity)
Test whether an entity exists.
ecs_is_alive
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
ecs_ftime_t
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
ecs_set_lookup_path
ecs_entity_t * ecs_set_lookup_path(ecs_world_t *world, const ecs_entity_t *lookup_path)
Set search path for lookup operations.
ecs_set_scope
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
ecs_atfini
void ecs_atfini(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed when world is destroyed.
ecs_fini
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_init
ecs_world_t * ecs_init(void)
Create a new world.
ecs_init_w_args
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
ecs_frame_begin
float ecs_frame_begin(ecs_world_t *world, float delta_time)
Begin frame.
ecs_run_post_frame
void ecs_run_post_frame(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed once after frame.
ecs_should_quit
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been requested.
ecs_quit
void ecs_quit(ecs_world_t *world)
Signal exit This operation signals that the application should quit.
ecs_frame_end
void ecs_frame_end(ecs_world_t *world)
End frame.
ecs_get_binding_ctx
void * ecs_get_binding_ctx(const ecs_world_t *world)
Get the world binding context.
ecs_dim
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
ecs_set_entity_range
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issuing new entity ids.
ecs_get_world_info
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
ecs_get_world
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
ecs_set_ctx
void ecs_set_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world context.
ecs_set_binding_ctx
void ecs_set_binding_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world binding context.
flecs_poly_is
#define flecs_poly_is(object, type)
Test if pointer is of specified type.
Definition flecs.h:2615
ecs_enable_range_check
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
ecs_get_ctx
void * ecs_get_ctx(const ecs_world_t *world)
Get the world context.
mixin.inl
Id world mixin.
world.inl
JSON world mixin.
world.inl
Meta world mixin.
mixin.inl
Module world mixin.
mixin.inl
Observer world mixin.
mixin.inl
Pipeline world mixin.
mixin.inl
Query world mixin.
mixin.inl
Script world mixin.
ecs_world_info_t
Type that contains information about the world.
Definition flecs.h:1365
ecs_world_info_t::delta_time
float delta_time
Time passed to or computed by ecs_progress()
Definition flecs.h:1371
flecs::_::type
Definition flecs.hpp:38
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
flecs::scoped_world
Scoped world.
Definition world.hpp:1226
flecs::world
The world.
Definition world.hpp:137
flecs::world::is_stage
bool is_stage() const
Test if is a stage.
Definition world.hpp:421
flecs::world::delete_with
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1031
flecs::world::remove_all
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:1048
flecs::world::delete_with
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1043
flecs::world::merge
void merge() const
Merge world or stage.
Definition world.hpp:440
flecs::world::delete_with
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1020
flecs::world::get_info
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1168
flecs::world::get_scope
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:67
flecs::world::get_mut
T * get_mut() const
Get mutable singleton component.
Definition world.hpp:132
flecs::world::remove
void remove() const
Remove singleton component.
Definition world.hpp:196
flecs::world::lookup
flecs::entity lookup(const char *name, const char *sep="::", const char *root_sep="::", bool recursive=true) const
Lookup entity by name.
Definition world.hpp:76
flecs::world::set
void set(A &&value) const
Set singleton pair.
Definition world.hpp:673
flecs::world::delta_time
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1173
flecs::world::quit
void quit() const
Signal application should quit.
Definition world.hpp:244
flecs::world::get_alive
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition world.hpp:266
flecs::world::set_entity_range
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:584
flecs::world::readonly_end
void readonly_end() const
End readonly mode.
Definition world.hpp:318
flecs::world::with
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:973
flecs::world::make_alive
flecs::entity make_alive(flecs::entity_t e) const
Definition world.hpp:271
flecs::world::count
int count() const
Count entities matching a component.
Definition world.hpp:928
flecs::world::target
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:229
flecs::world::get
const T * get() const
Get singleton component.
Definition world.hpp:114
flecs::world::defer
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:1084
flecs::world::should_quit
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:256
flecs::world::is_alive
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1132
flecs::world::c_ptr
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:237
flecs::world::defer_begin
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:337
flecs::world::reset
void reset()
Deletes and recreates the world.
Definition world.hpp:227
flecs::world::set_lookup_path
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:634
flecs::world::defer_suspend
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1099
flecs::world::set
void set(const A &value) const
Set singleton pair.
Definition world.hpp:665
flecs::world::make_owner
void make_owner()
Make current world object owner of the world.
Definition world.hpp:222
flecs::world::is_valid
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1143
flecs::world::async_stage
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:477
flecs::world::is_deferred
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:370
flecs::world::get_binding_ctx
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:561
flecs::world::get_stage_id
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:411
flecs::world::world
world(const world &obj)
Not allowed to copy a world.
Definition world.hpp:165
flecs::world::scope
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:1004
flecs::world::defer_resume
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1112
flecs::world::set_scope
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:72
flecs::world::dim
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition world.hpp:572
flecs::world::set_stage_count
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:389
flecs::world::with
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:957
flecs::world::get_ctx
void * get_ctx() const
Get world context.
Definition world.hpp:533
flecs::world::count
int count() const
Count entities matching a pair.
Definition world.hpp:948
flecs::world::remove_all
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1065
flecs::world::defer_end
bool defer_end() const
End block of operations to defer.
Definition world.hpp:355
flecs::world::count
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:919
flecs::world::remove_all
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1071
flecs::world::world
world(world_t *w)
Create world from C world.
Definition world.hpp:156
flecs::world::children
void children(Func &&f) const
Iterate entities in root of world Accepts a callback with the following signature:
Definition world.hpp:219
flecs::world::get_world
flecs::world get_world() const
Get actual world.
Definition world.hpp:489
flecs::world::scope
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:995
flecs::world::with
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:966
flecs::world::remove_all
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1053
flecs::world::modified
void modified() const
Mark singleton component as modified.
Definition world.hpp:90
flecs::world::enable_range_check
void enable_range_check(bool enabled=true) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:598
flecs::world::count
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:938
flecs::world::frame_begin
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:281
flecs::world::use
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition world.hpp:34
flecs::world::is_readonly
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:505
flecs::world::add
void add() const
Add singleton component.
Definition world.hpp:173
flecs::world::ensure
T & ensure() const
Ensure singleton component.
Definition world.hpp:83
flecs::world::readonly_begin
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:308
flecs::world::set
void set(const T &value) const
Set singleton component.
Definition world.hpp:649
flecs::world::with
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:987
flecs::world::get_stage
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:458
flecs::world::set
void set(T &&value) const
Set singleton component.
Definition world.hpp:656
flecs::world::has
bool has() const
Test if world has singleton component.
Definition world.hpp:150
flecs::world::exists
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1122
flecs::world::world
world()
Create world.
Definition world.hpp:140
flecs::world::frame_end
void frame_end() const
End frame.
Definition world.hpp:294
flecs::world::set_binding_ctx
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:548
flecs::world::atfini
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:250
flecs::world::get_stage_count
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:401
flecs::world::delete_with
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1025
flecs::world::delete_with
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1037
flecs::world::singleton
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:224
flecs::world::with
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:980
flecs::world::set_ctx
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:520
flecs::world::world
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:149
flecs::world::count
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:910
flecs::world::remove_all
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1059
flecs::world::get_ref
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:108
mixin.inl
System module world mixin.
mixin.inl
Term world mixin.
mixin.inl
Timer module mixin.
flecs::strip_generation
flecs::id_t strip_generation(flecs::entity_t e)
Return id without generation.
Definition world.hpp:113
flecs::get_generation
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:119