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>
15inline 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>
32inline 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
113inline flecs::id_t strip_generation(flecs::entity_t e) {
114 return ecs_strip_generation(e);
115}
116
119inline uint32_t get_generation(flecs::entity_t e) {
120 return ECS_GENERATION(e);
121}
122
123struct scoped_world;
124
137struct 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 this->world_ = obj.world_;
172 flecs_poly_claim(this->world_);
173 return *this;
174 }
175
176 world(world&& obj) noexcept {
177 world_ = obj.world_;
178 obj.world_ = nullptr;
179 }
180
181 world& operator=(world&& obj) noexcept {
182 world_ = obj.world_;
183 obj.world_ = nullptr;
184 return *this;
185 }
186
187 ~world() {
188 if (world_) {
189 if (!flecs_poly_release(world_)) {
190 if (ecs_stage_get_id(world_) == -1) {
191 ecs_stage_free(world_);
192 } else {
193 // before we call ecs_fini(), we increment the reference count back to 1
194 // otherwise, copies of this object created during ecs_fini (e.g. a component on_remove hook)
195 // would call again this destructor and ecs_fini().
196 flecs_poly_claim(world_);
197 ecs_fini(world_);
198 }
199 }
200 }
201 }
202
203 /* Implicit conversion to world_t* */
204 operator world_t*() const { return world_; }
205
213 void make_owner() {
214 flecs_poly_release(world_);
215 }
216
218 void reset() {
219 /* Make sure there's only one reference to the world */
220 ecs_assert(flecs_poly_refcount(world_) == 1, ECS_INVALID_OPERATION,
221 "reset would invalidate other handles");
222 ecs_fini(world_);
223 world_ = ecs_init();
224 }
225
228 world_t* c_ptr() const {
229 return world_;
230 }
231
235 void quit() const {
236 ecs_quit(world_);
237 }
238
241 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
242 ecs_atfini(world_, action, ctx);
243 }
244
247 bool should_quit() const {
248 return ecs_should_quit(world_);
249 }
250
273 return ecs_frame_begin(world_, delta_time);
274 }
275
285 void frame_end() const {
286 ecs_frame_end(world_);
287 }
288
299 bool readonly_begin(bool multi_threaded = false) const {
300 return ecs_readonly_begin(world_, multi_threaded);
301 }
302
309 void readonly_end() const {
310 ecs_readonly_end(world_);
311 }
312
328 bool defer_begin() const {
329 return ecs_defer_begin(world_);
330 }
331
346 bool defer_end() const {
347 return ecs_defer_end(world_);
348 }
349
361 bool is_deferred() const {
362 return ecs_is_deferred(world_);
363 }
364
380 void set_stage_count(int32_t stages) const {
381 ecs_set_stage_count(world_, stages);
382 }
383
392 int32_t get_stage_count() const {
393 return ecs_get_stage_count(world_);
394 }
395
402 int32_t get_stage_id() const {
403 return ecs_stage_get_id(world_);
404 }
405
412 bool is_stage() const {
414 flecs_poly_is(world_, ecs_world_t) ||
415 flecs_poly_is(world_, ecs_stage_t),
416 ECS_INVALID_PARAMETER,
417 "flecs::world instance contains invalid reference to world or stage");
418 return flecs_poly_is(world_, ecs_stage_t);
419 }
420
431 void merge() const {
432 ecs_merge(world_);
433 }
434
449 flecs::world get_stage(int32_t stage_id) const {
450 return flecs::world(ecs_get_stage(world_, stage_id));
451 }
452
469 ecs_world_t *as = ecs_stage_new(world_);
470 flecs_poly_release(as); // world object will claim
471 return flecs::world(as);
472 }
473
481 /* Safe cast, mutability is checked */
482 return flecs::world(
483 world_ ? const_cast<flecs::world_t*>(ecs_get_world(world_)) : nullptr);
484 }
485
496 bool is_readonly() const {
497 return ecs_stage_is_readonly(world_);
498 }
499
511 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
512 ecs_set_ctx(world_, ctx, ctx_free);
513 }
514
524 void* get_ctx() const {
525 return ecs_get_ctx(world_);
526 }
527
539 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
540 ecs_set_binding_ctx(world_, ctx, ctx_free);
541 }
542
552 void* get_binding_ctx() const {
553 return ecs_get_binding_ctx(world_);
554 }
555
563 void dim(int32_t entity_count) const {
564 ecs_dim(world_, entity_count);
565 }
566
575 void set_entity_range(entity_t min, entity_t max) const {
576 ecs_set_entity_range(world_, min, max);
577 }
578
589 void enable_range_check(bool enabled = true) const {
590 ecs_enable_range_check(world_, enabled);
591 }
592
601 flecs::entity set_scope(const flecs::entity_t scope) const;
602
610 flecs::entity get_scope() const;
611
617 template <typename T>
618 flecs::entity set_scope() const;
619
625 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
626 return ecs_set_lookup_path(world_, search_path);
627 }
628
635 flecs::entity lookup(const char *name, const char *sep = "::", const char *root_sep = "::", bool recursive = true) const;
636
639 template <typename T, if_t< !is_callable<T>::value > = 0>
640 void set(const T& value) const {
641 flecs::set<T>(world_, _::type<T>::id(world_), value);
642 }
643
646 template <typename T, if_t< !is_callable<T>::value > = 0>
647 void set(T&& value) const {
648 flecs::set<T>(world_, _::type<T>::id(world_),
649 FLECS_FWD(value));
650 }
651
654 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
655 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
656 void set(const A& value) const {
657 flecs::set<P>(world_, _::type<First>::id(world_), value);
658 }
659
662 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
663 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
664 void set(A&& value) const {
665 flecs::set<P>(world_, _::type<First>::id(world_), FLECS_FWD(value));
666 }
667
670 template <typename First, typename Second>
671 void set(Second second, const First& value) const;
672
675 template <typename First, typename Second>
676 void set(Second second, First&& value) const;
677
680 template <typename Func, if_t< is_callable<Func>::value > = 0 >
681 void set(const Func& func) const;
682
683 template <typename T, typename ... Args>
684 void emplace(Args&&... args) const {
685 flecs::id_t component_id = _::type<T>::id(world_);
686 flecs::emplace<T>(world_, component_id, component_id, FLECS_FWD(args)...);
687 }
688
691 #ifndef ensure
692 template <typename T>
693 T& ensure() const;
694 #endif
695
698 template <typename T>
699 void modified() const;
700
703 template <typename T>
704 ref<T> get_ref() const;
705
708 template <typename T>
709 const T* get() const;
710
713 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
714 typename A = actual_type_t<P>>
715 const A* get() const;
716
719 template <typename First, typename Second>
720 const First* get(Second second) const;
721
724 template <typename Func, if_t< is_callable<Func>::value > = 0 >
725 void get(const Func& func) const;
726
729 template <typename T>
730 T* get_mut() const;
731
734 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
735 typename A = actual_type_t<P>>
736 A* get_mut() const;
737
740 template <typename First, typename Second>
741 First* get_mut(Second second) const;
742
745 template <typename T>
746 bool has() const;
747
753 template <typename First, typename Second>
754 bool has() const;
755
761 template <typename First>
762 bool has(flecs::id_t second) const;
763
769 bool has(flecs::id_t first, flecs::id_t second) const;
770
773 template <typename T>
774 void add() const;
775
781 template <typename First, typename Second>
782 void add() const;
783
789 template <typename First>
790 void add(flecs::entity_t second) const;
791
797 void add(flecs::entity_t first, flecs::entity_t second) const;
798
801 template <typename T>
802 void remove() const;
803
809 template <typename First, typename Second>
810 void remove() const;
811
817 template <typename First>
818 void remove(flecs::entity_t second) const;
819
825 void remove(flecs::entity_t first, flecs::entity_t second) const;
826
834 template <typename Func>
835 void children(Func&& f) const;
836
839 template <typename T>
840 flecs::entity singleton() const;
841
850 template<typename First>
851 flecs::entity target(int32_t index = 0) const;
852
861 template<typename T>
862 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
863
872 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
873
880 template <typename T>
881 flecs::entity use(const char *alias = nullptr) const;
882
888 flecs::entity use(const char *name, const char *alias = nullptr) const;
889
895 void use(flecs::entity entity, const char *alias = nullptr) const;
896
901 int count(flecs::id_t component_id) const {
902 return ecs_count_id(world_, component_id);
903 }
904
910 int count(flecs::entity_t first, flecs::entity_t second) const {
911 return ecs_count_id(world_, ecs_pair(first, second));
912 }
913
918 template <typename T>
919 int count() const {
920 return count(_::type<T>::id(world_));
921 }
922
928 template <typename First>
929 int count(flecs::entity_t second) const {
930 return count(_::type<First>::id(world_), second);
931 }
932
938 template <typename First, typename Second>
939 int count() const {
940 return count(
941 _::type<First>::id(world_),
942 _::type<Second>::id(world_));
943 }
944
947 template <typename Func>
948 void with(id_t with_id, const Func& func) const {
949 ecs_id_t prev = ecs_set_with(world_, with_id);
950 func();
951 ecs_set_with(world_, prev);
952 }
953
956 template <typename T, typename Func>
957 void with(const Func& func) const {
958 with(this->id<T>(), func);
959 }
960
963 template <typename First, typename Second, typename Func>
964 void with(const Func& func) const {
965 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
966 }
967
970 template <typename First, typename Func>
971 void with(id_t second, const Func& func) const {
972 with(ecs_pair(this->id<First>(), second), func);
973 }
974
977 template <typename Func>
978 void with(id_t first, id_t second, const Func& func) const {
979 with(ecs_pair(first, second), func);
980 }
981
985 template <typename Func>
986 void scope(id_t parent, const Func& func) const {
987 ecs_entity_t prev = ecs_set_scope(world_, parent);
988 func();
989 ecs_set_scope(world_, prev);
990 }
991
994 template <typename T, typename Func>
995 void scope(const Func& func) const {
996 flecs::id_t parent = _::type<T>::id(world_);
997 scope(parent, func);
998 }
999
1003 flecs::scoped_world scope(id_t parent) const;
1004
1005 template <typename T>
1006 flecs::scoped_world scope() const;
1007
1008 flecs::scoped_world scope(const char* name) const;
1009
1011 void delete_with(id_t the_id) const {
1012 ecs_delete_with(world_, the_id);
1013 }
1014
1016 void delete_with(entity_t first, entity_t second) const {
1017 delete_with(ecs_pair(first, second));
1018 }
1019
1021 template <typename T>
1022 void delete_with() const {
1023 delete_with(_::type<T>::id(world_));
1024 }
1025
1027 template <typename First, typename Second>
1028 void delete_with() const {
1030 }
1031
1033 template <typename First>
1034 void delete_with(entity_t second) const {
1035 delete_with(_::type<First>::id(world_), second);
1036 }
1037
1039 void remove_all(id_t the_id) const {
1040 ecs_remove_all(world_, the_id);
1041 }
1042
1044 void remove_all(entity_t first, entity_t second) const {
1045 remove_all(ecs_pair(first, second));
1046 }
1047
1049 template <typename T>
1050 void remove_all() const {
1051 remove_all(_::type<T>::id(world_));
1052 }
1053
1055 template <typename First, typename Second>
1056 void remove_all() const {
1058 }
1059
1061 template <typename First>
1062 void remove_all(entity_t second) const {
1063 remove_all(_::type<First>::id(world_), second);
1064 }
1065
1074 template <typename Func>
1075 void defer(const Func& func) const {
1076 ecs_defer_begin(world_);
1077 func();
1078 ecs_defer_end(world_);
1079 }
1080
1090 void defer_suspend() const {
1091 ecs_defer_suspend(world_);
1092 }
1093
1103 void defer_resume() const {
1104 ecs_defer_resume(world_);
1105 }
1106
1113 bool exists(flecs::entity_t e) const {
1114 return ecs_exists(world_, e);
1115 }
1116
1123 bool is_alive(flecs::entity_t e) const {
1124 return ecs_is_alive(world_, e);
1125 }
1126
1134 bool is_valid(flecs::entity_t e) const {
1135 return ecs_is_valid(world_, e);
1136 }
1137
1143 flecs::entity get_alive(flecs::entity_t e) const;
1144
1148 flecs::entity make_alive(flecs::entity_t e) const;
1149
1150 /* Run callback after completing frame */
1151 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1152 ecs_run_post_frame(world_, action, ctx);
1153 }
1154
1160 return ecs_get_world_info(world_);
1161 }
1162
1165 return get_info()->delta_time;
1166 }
1167
1168# include "mixins/id/mixin.inl"
1170# include "mixins/entity/mixin.inl"
1171# include "mixins/event/mixin.inl"
1172# include "mixins/term/mixin.inl"
1173# include "mixins/observer/mixin.inl"
1174# include "mixins/query/mixin.inl"
1175# include "mixins/enum/mixin.inl"
1176
1177# ifdef FLECS_MODULE
1178# include "mixins/module/mixin.inl"
1179# endif
1180# ifdef FLECS_PIPELINE
1181# include "mixins/pipeline/mixin.inl"
1182# endif
1183# ifdef FLECS_SYSTEM
1184# include "mixins/system/mixin.inl"
1185# endif
1186# ifdef FLECS_TIMER
1187# include "mixins/timer/mixin.inl"
1188# endif
1189# ifdef FLECS_SCRIPT
1190# include "mixins/script/mixin.inl"
1191# endif
1192# ifdef FLECS_META
1193# include "mixins/meta/world.inl"
1194# endif
1195# ifdef FLECS_JSON
1196# include "mixins/json/world.inl"
1197# endif
1198# ifdef FLECS_APP
1199# include "mixins/app/mixin.inl"
1200# endif
1201# ifdef FLECS_METRICS
1202# include "mixins/metrics/mixin.inl"
1203# endif
1204# ifdef FLECS_ALERTS
1205# include "mixins/alerts/mixin.inl"
1206# endif
1207
1208public:
1209 void init_builtin_components();
1210
1211 world_t *world_;
1212};
1213
1219 flecs::world_t *w,
1220 flecs::entity_t s) : world(w)
1221 {
1222 prev_scope_ = ecs_set_scope(w, s);
1223 }
1224
1225 ~scoped_world() {
1226 ecs_set_scope(world_, prev_scope_);
1227 }
1228
1229 scoped_world(const scoped_world& obj) : world(nullptr) {
1230 prev_scope_ = obj.prev_scope_;
1231 world_ = obj.world_;
1232 flecs_poly_claim(world_);
1233 }
1234
1235 flecs::entity_t prev_scope_;
1236};
1237
1240} // namespace flecs
App world addon mixin.
Component mixin.
Entity world mixin.
Enum world mixin.
Event world mixin.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
void ecs_remove_all(ecs_world_t *world, ecs_id_t id)
Remove all instances of the specified (component) id.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
ecs_world_t * ecs_stage_new(ecs_world_t *world)
Create unmanaged stage.
bool ecs_defer_end(ecs_world_t *world)
End 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 end of 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 current stage.
void ecs_stage_free(ecs_world_t *stage)
Free unmanaged stage.
void ecs_merge(ecs_world_t *world)
Merge world or stage.
int32_t ecs_stage_get_id(const ecs_world_t *world)
Get 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 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 world to have N stages.
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition flecs.h:386
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:339
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:383
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:332
flecs::entity entity(Args &&... args) const
Create an entity.
void ecs_delete_with(ecs_world_t *world, ecs_id_t id)
Delete all entities with the specified id.
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:579
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:584
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, bool *is_new)
Emplace a component.
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
void * ecs_ensure_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Combines ensure + modified in single operation.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove generation from entity id.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
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.
#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 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 action to be executed when 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 action to be executed once after 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 This operation signals that the application should quit.
void ecs_frame_end(ecs_world_t *world)
End frame.
void * ecs_get_binding_ctx(const ecs_world_t *world)
Get the world binding context.
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issuing new entity ids.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
void ecs_set_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world context.
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 pointer is of specified type.
Definition flecs.h:2577
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
void * ecs_get_ctx(const ecs_world_t *world)
Get the world context.
Id world mixin.
JSON world mixin.
Meta world mixin.
Module world mixin.
Observer world mixin.
Pipeline world mixin.
Query world mixin.
Script world mixin.
Type that contains information about the world.
Definition flecs.h:1341
float delta_time
Time passed to or computed by ecs_progress()
Definition flecs.h:1347
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1217
The world.
Definition world.hpp:137
bool is_stage() const
Test if is a stage.
Definition world.hpp:412
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:1022
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:1039
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1034
void merge() const
Merge world or stage.
Definition world.hpp:431
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:1011
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1159
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:67
T * get_mut() const
Get mutable singleton component.
Definition world.hpp:132
void remove() const
Remove singleton component.
Definition world.hpp:196
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
void set(A &&value) const
Set singleton pair.
Definition world.hpp:664
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1164
void quit() const
Signal application should quit.
Definition world.hpp:235
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition world.hpp:266
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:575
void readonly_end() const
End readonly mode.
Definition world.hpp:309
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:964
flecs::entity make_alive(flecs::entity_t e) const
Definition world.hpp:271
int count() const
Count entities matching a component.
Definition world.hpp:919
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:229
const T * get() const
Get singleton component.
Definition world.hpp:114
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:1075
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:247
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1123
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:228
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:328
void reset()
Deletes and recreates the world.
Definition world.hpp:218
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:625
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:1090
void set(const A &value) const
Set singleton pair.
Definition world.hpp:656
void make_owner()
Make current world object owner of the world.
Definition world.hpp:213
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1134
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:468
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:361
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:552
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:402
world(const world &obj)
Not allowed to copy a world.
Definition world.hpp:165
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:995
void defer_resume() const
Resume deferring operations.
Definition world.hpp:1103
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:72
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition world.hpp:563
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:380
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:948
void * get_ctx() const
Get world context.
Definition world.hpp:524
int count() const
Count entities matching a pair.
Definition world.hpp:939
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:1056
bool defer_end() const
End block of operations to defer.
Definition world.hpp:346
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:910
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1062
world(world_t *w)
Create world from C world.
Definition world.hpp:156
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() const
Get actual world.
Definition world.hpp:480
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:986
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:957
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:1044
void modified() const
Mark singleton component as modified.
Definition world.hpp:90
void enable_range_check(bool enabled=true) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:589
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:929
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:272
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition world.hpp:34
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:496
void add() const
Add singleton component.
Definition world.hpp:173
T & ensure() const
Ensure singleton component.
Definition world.hpp:83
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:299
void set(const T &value) const
Set singleton component.
Definition world.hpp:640
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:978
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:449
void set(T &&value) const
Set singleton component.
Definition world.hpp:647
bool has() const
Test if world has singleton component.
Definition world.hpp:150
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1113
world()
Create world.
Definition world.hpp:140
void frame_end() const
End frame.
Definition world.hpp:285
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:539
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:241
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:392
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:1016
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:1028
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:224
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:971
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:511
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:149
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:901
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:1050
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:108
System module world mixin.
Term world mixin.
Timer module mixin.
flecs::id_t strip_generation(flecs::entity_t e)
Return id without generation.
Definition world.hpp:113
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:119