Flecs v3.2
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(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
17
18 if (!ecs_is_deferred(world)) {
19 T& dst = *static_cast<T*>(ecs_ensure_id(world, entity, id));
20 dst = FLECS_MOV(value);
21
22 ecs_modified_id(world, entity, id);
23 } else {
24 T& dst = *static_cast<T*>(ecs_ensure_modified_id(world, entity, id));
25 dst = FLECS_MOV(value);
26 }
27}
28
29// set(const T&), T = constructible
30template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
31inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
32 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
33
34 if (!ecs_is_deferred(world)) {
35 T& dst = *static_cast<T*>(ecs_ensure_id(world, entity, id));
36 dst = FLECS_MOV(value);
37
38 ecs_modified_id(world, entity, id);
39 } else {
40 T& dst = *static_cast<T*>(ecs_ensure_modified_id(world, entity, id));
41 dst = FLECS_MOV(value);
42 }
43}
44
45// set(T&&), T = not constructible
46template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
47inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
48 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
49
50 if (!ecs_is_deferred(world)) {
51 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
52 dst = FLECS_MOV(value);
53
54 ecs_modified_id(world, entity, id);
55 } else {
56 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
57 dst = FLECS_MOV(value);
58 }
59}
60
61// set(const T&), T = not constructible
62template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
63inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
64 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
65
66 if (!ecs_is_deferred(world)) {
67 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
68 dst = FLECS_MOV(value);
69
70 ecs_modified_id(world, entity, id);
71 } else {
72 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
73 dst = FLECS_MOV(value);
74 }
75}
76
77// emplace for T(Args...)
78template <typename T, typename ... Args, if_t<
79 std::is_constructible<actual_type_t<T>, Args...>::value ||
80 std::is_default_constructible<actual_type_t<T>>::value > = 0>
81inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
82 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
83 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id));
84
85 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
86
87 ecs_modified_id(world, entity, id);
88}
89
90// set(T&&)
91template <typename T, typename A>
92inline void set(world_t *world, entity_t entity, A&& value) {
93 id_t id = _::cpp_type<T>::id(world);
94 flecs::set(world, entity, FLECS_FWD(value), id);
95}
96
97// set(const T&)
98template <typename T, typename A>
99inline void set(world_t *world, entity_t entity, const A& value) {
100 id_t id = _::cpp_type<T>::id(world);
101 flecs::set(world, entity, value, id);
102}
103
108inline flecs::id_t strip_generation(flecs::entity_t e) {
109 return ecs_strip_generation(e);
110}
111
114inline uint32_t get_generation(flecs::entity_t e) {
115 return ECS_GENERATION(e);
116}
117
118struct scoped_world;
119
132struct world {
135 explicit world()
136 : m_world( ecs_init() )
137 , m_owned( true ) { init_builtin_components(); }
138
143 explicit world(int argc, char *argv[])
144 : m_world( ecs_init_w_args(argc, argv) )
145 , m_owned( true ) { init_builtin_components(); }
146
149 explicit world(world_t *w)
150 : m_world( w )
151 , m_owned( false ) { }
152
155 world(const world& obj) = delete;
156
157 world(world&& obj) noexcept {
158 m_world = obj.m_world;
159 m_owned = obj.m_owned;
160 obj.m_world = nullptr;
161 obj.m_owned = false;
162 }
163
164 /* Implicit conversion to world_t* */
165 operator world_t*() const { return m_world; }
166
169 world& operator=(const world& obj) = delete;
170
171 world& operator=(world&& obj) noexcept {
172 this->~world();
173
174 m_world = obj.m_world;
175 m_owned = obj.m_owned;
176 obj.m_world = nullptr;
177 obj.m_owned = false;
178 return *this;
179 }
180
181 ~world() {
182 if (m_owned && ecs_stage_is_async(m_world)) {
183 ecs_async_stage_free(m_world);
184 } else
185 if (m_owned && m_world) {
186 ecs_fini(m_world);
187 }
188 }
189
191 void reset() {
192 // Can only reset the world if we own the world object.
193 ecs_assert(this->m_owned, ECS_INVALID_OPERATION, NULL);
194 ecs_fini(m_world);
195 m_world = ecs_init();
196 }
197
200 world_t* c_ptr() const {
201 return m_world;
202 }
203
207 void quit() const {
208 ecs_quit(m_world);
209 }
210
213 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
214 ecs_atfini(m_world, action, ctx);
215 }
216
219 bool should_quit() const {
220 return ecs_should_quit(m_world);
221 }
222
242 return ecs_frame_begin(m_world, delta_time);
243 }
244
251 void frame_end() const {
252 ecs_frame_end(m_world);
253 }
254
261 bool readonly_begin(bool multi_threaded = false) const {
262 return ecs_readonly_begin(m_world, multi_threaded);
263 }
264
269 void readonly_end() const {
270 ecs_readonly_end(m_world);
271 }
272
279 bool defer_begin() const {
280 return ecs_defer_begin(m_world);
281 }
282
288 bool defer_end() const {
289 return ecs_defer_end(m_world);
290 }
291
294 bool is_deferred() const {
295 return ecs_is_deferred(m_world);
296 }
297
310 void set_stage_count(int32_t stages) const {
311 ecs_set_stage_count(m_world, stages);
312 }
313
319 int32_t get_stage_count() const {
320 return ecs_get_stage_count(m_world);
321 }
322
329 int32_t get_stage_id() const {
330 return ecs_get_stage_id(m_world);
331 }
332
339 bool is_stage() const {
341 ecs_poly_is(m_world, ecs_world_t) ||
342 ecs_poly_is(m_world, ecs_stage_t),
343 ECS_INVALID_PARAMETER, NULL);
344 return ecs_poly_is(m_world, ecs_stage_t);
345 }
346
363 void set_automerge(bool automerge) const {
364 ecs_set_automerge(m_world, automerge);
365 }
366
375 void merge() const {
376 ecs_merge(m_world);
377 }
378
393 flecs::world get_stage(int32_t stage_id) const {
394 return flecs::world(ecs_get_stage(m_world, stage_id));
395 }
396
415 auto result = flecs::world(ecs_async_stage_new(m_world));
416 result.m_owned = true;
417 return result;
418 }
419
427 /* Safe cast, mutability is checked */
428 return flecs::world(
429 m_world ? const_cast<flecs::world_t*>(ecs_get_world(m_world)) : nullptr);
430 }
431
438 bool is_readonly() const {
439 return ecs_stage_is_readonly(m_world);
440 }
441
448 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
449 ecs_set_ctx(m_world, ctx, ctx_free);
450 }
451
456 void* get_ctx() const {
457 return ecs_get_ctx(m_world);
458 }
459
466 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
467 ecs_set_binding_ctx(m_world, ctx, ctx_free);
468 }
469
474 void* get_binding_ctx() const {
475 return ecs_get_binding_ctx(m_world);
476 }
477
483 void dim(int32_t entity_count) const {
484 ecs_dim(m_world, entity_count);
485 }
486
493 void set_entity_range(entity_t min, entity_t max) const {
494 ecs_set_entity_range(m_world, min, max);
495 }
496
505 void enable_range_check(bool enabled) const {
506 ecs_enable_range_check(m_world, enabled);
507 }
508
515 flecs::entity set_scope(const flecs::entity_t scope) const;
516
522 flecs::entity get_scope() const;
523
527 template <typename T>
528 flecs::entity set_scope() const;
529
533 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
534 return ecs_set_lookup_path(m_world, search_path);
535 }
536
543 flecs::entity lookup(const char *name, bool search_path = true) const;
544
547 template <typename T, if_t< !is_callable<T>::value > = 0>
548 void set(const T& value) const {
549 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world), value);
550 }
551
554 template <typename T, if_t< !is_callable<T>::value > = 0>
555 void set(T&& value) const {
556 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world),
557 FLECS_FWD(value));
558 }
559
562 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
563 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
564 void set(const A& value) const {
565 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), value);
566 }
567
570 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
571 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
572 void set(A&& value) const {
573 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), FLECS_FWD(value));
574 }
575
578 template <typename First, typename Second>
579 void set(Second second, const First& value) const;
580
583 template <typename First, typename Second>
584 void set(Second second, First&& value) const;
585
588 template <typename Func, if_t< is_callable<Func>::value > = 0 >
589 void set(const Func& func) const;
590
591 template <typename T, typename ... Args>
592 void emplace(Args&&... args) const {
593 flecs::id_t component_id = _::cpp_type<T>::id(m_world);
594 flecs::emplace<T>(m_world, component_id, component_id,
595 FLECS_FWD(args)...);
596 }
597
600 #ifndef ensure
601 template <typename T>
602 T& ensure() const;
603 #endif
604
607 template <typename T>
608 void modified() const;
609
612 template <typename T>
613 ref<T> get_ref() const;
614
617 template <typename T>
618 const T* get() const;
619
622 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
623 typename A = actual_type_t<P>>
624 const A* get() const;
625
628 template <typename First, typename Second>
629 const First* get(Second second) const;
630
633 template <typename Func, if_t< is_callable<Func>::value > = 0 >
634 void get(const Func& func) const;
635
638 template <typename T>
639 bool has() const;
640
646 template <typename First, typename Second>
647 bool has() const;
648
654 template <typename First>
655 bool has(flecs::id_t second) const;
656
662 bool has(flecs::id_t first, flecs::id_t second) const;
663
666 template <typename T>
667 void add() const;
668
674 template <typename First, typename Second>
675 void add() const;
676
682 template <typename First>
683 void add(flecs::entity_t second) const;
684
690 void add(flecs::entity_t first, flecs::entity_t second) const;
691
694 template <typename T>
695 void remove() const;
696
702 template <typename First, typename Second>
703 void remove() const;
704
710 template <typename First>
711 void remove(flecs::entity_t second) const;
712
718 void remove(flecs::entity_t first, flecs::entity_t second) const;
719
727 template <typename Func>
728 void children(Func&& f) const;
729
732 template <typename T>
733 flecs::entity singleton() const;
734
743 template<typename First>
744 flecs::entity target(int32_t index = 0) const;
745
754 template<typename T>
755 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
756
765 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
766
773 template <typename T>
774 flecs::entity use(const char *alias = nullptr) const;
775
781 flecs::entity use(const char *name, const char *alias = nullptr) const;
782
788 void use(flecs::entity entity, const char *alias = nullptr) const;
789
794 int count(flecs::id_t component_id) const {
795 return ecs_count_id(m_world, component_id);
796 }
797
803 int count(flecs::entity_t first, flecs::entity_t second) const {
804 return ecs_count_id(m_world, ecs_pair(first, second));
805 }
806
811 template <typename T>
812 int count() const {
813 return count(_::cpp_type<T>::id(m_world));
814 }
815
821 template <typename First>
822 int count(flecs::entity_t second) const {
823 return count(_::cpp_type<First>::id(m_world), second);
824 }
825
831 template <typename First, typename Second>
832 int count() const {
833 return count(
834 _::cpp_type<First>::id(m_world),
835 _::cpp_type<Second>::id(m_world));
836 }
837
840 template <typename Func>
841 void with(id_t with_id, const Func& func) const {
842 ecs_id_t prev = ecs_set_with(m_world, with_id);
843 func();
844 ecs_set_with(m_world, prev);
845 }
846
849 template <typename T, typename Func>
850 void with(const Func& func) const {
851 with(this->id<T>(), func);
852 }
853
856 template <typename First, typename Second, typename Func>
857 void with(const Func& func) const {
858 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
859 }
860
863 template <typename First, typename Func>
864 void with(id_t second, const Func& func) const {
865 with(ecs_pair(this->id<First>(), second), func);
866 }
867
870 template <typename Func>
871 void with(id_t first, id_t second, const Func& func) const {
872 with(ecs_pair(first, second), func);
873 }
874
878 template <typename Func>
879 void scope(id_t parent, const Func& func) const {
880 ecs_entity_t prev = ecs_set_scope(m_world, parent);
881 func();
882 ecs_set_scope(m_world, prev);
883 }
884
887 template <typename T, typename Func>
888 void scope(const Func& func) const {
889 flecs::id_t parent = _::cpp_type<T>::id(m_world);
890 scope(parent, func);
891 }
892
896 flecs::scoped_world scope(id_t parent) const;
897
898 template <typename T>
899 flecs::scoped_world scope() const;
900
901 flecs::scoped_world scope(const char* name) const;
902
904 void delete_with(id_t the_id) const {
905 ecs_delete_with(m_world, the_id);
906 }
907
909 void delete_with(entity_t first, entity_t second) const {
910 delete_with(ecs_pair(first, second));
911 }
912
914 template <typename T>
915 void delete_with() const {
917 }
918
920 template <typename First, typename Second>
921 void delete_with() const {
923 }
924
926 template <typename First>
927 void delete_with(entity_t second) const {
928 delete_with(_::cpp_type<First>::id(m_world), second);
929 }
930
932 void remove_all(id_t the_id) const {
933 ecs_remove_all(m_world, the_id);
934 }
935
937 void remove_all(entity_t first, entity_t second) const {
938 remove_all(ecs_pair(first, second));
939 }
940
942 template <typename T>
943 void remove_all() const {
945 }
946
948 template <typename First, typename Second>
949 void remove_all() const {
951 }
952
954 template <typename First>
955 void remove_all(entity_t second) const {
956 remove_all(_::cpp_type<First>::id(m_world), second);
957 }
958
962 template <typename Func>
963 void defer(const Func& func) const {
964 ecs_defer_begin(m_world);
965 func();
966 ecs_defer_end(m_world);
967 }
968
973 void defer_suspend() const {
974 ecs_defer_suspend(m_world);
975 }
976
981 void defer_resume() const {
982 ecs_defer_resume(m_world);
983 }
984
989 bool exists(flecs::entity_t e) const {
990 return ecs_exists(m_world, e);
991 }
992
997 bool is_alive(flecs::entity_t e) const {
998 return ecs_is_alive(m_world, e);
999 }
1000
1006 bool is_valid(flecs::entity_t e) const {
1007 return ecs_is_valid(m_world, e);
1008 }
1009
1015 flecs::entity get_alive(flecs::entity_t e) const;
1016
1017 flecs::entity make_alive(flecs::entity_t e) const;
1018
1019 /* Run callback after completing frame */
1020 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1021 ecs_run_post_frame(m_world, action, ctx);
1022 }
1023
1028 return ecs_get_world_info(m_world);
1029 }
1030
1033 return get_info()->delta_time;
1034 }
1035
1036# include "mixins/id/mixin.inl"
1038# include "mixins/entity/mixin.inl"
1039# include "mixins/event/mixin.inl"
1040# include "mixins/term/mixin.inl"
1041# include "mixins/filter/mixin.inl"
1042# include "mixins/observer/mixin.inl"
1043# include "mixins/query/mixin.inl"
1044# include "mixins/enum/mixin.inl"
1045
1046# ifdef FLECS_MODULE
1047# include "mixins/module/mixin.inl"
1048# endif
1049# ifdef FLECS_PIPELINE
1050# include "mixins/pipeline/mixin.inl"
1051# endif
1052# ifdef FLECS_SNAPSHOT
1053# include "mixins/snapshot/mixin.inl"
1054# endif
1055# ifdef FLECS_SYSTEM
1056# include "mixins/system/mixin.inl"
1057# endif
1058# ifdef FLECS_TIMER
1059# include "mixins/timer/mixin.inl"
1060# endif
1061# ifdef FLECS_RULES
1062# include "mixins/rule/mixin.inl"
1063# endif
1064# ifdef FLECS_PLECS
1065# include "mixins/plecs/mixin.inl"
1066# endif
1067# ifdef FLECS_META
1068# include "mixins/meta/world.inl"
1069# endif
1070# ifdef FLECS_JSON
1071# include "mixins/json/world.inl"
1072# endif
1073# ifdef FLECS_APP
1074# include "mixins/app/mixin.inl"
1075# endif
1076# ifdef FLECS_METRICS
1077# include "mixins/metrics/mixin.inl"
1078# endif
1079# ifdef FLECS_ALERTS
1080# include "mixins/alerts/mixin.inl"
1081# endif
1082
1083public:
1084 void init_builtin_components();
1085
1086 world_t *m_world;
1087 bool m_owned;
1088};
1089
1095 flecs::world_t *w,
1096 flecs::entity_t s) : world(nullptr)
1097 {
1098 m_prev_scope = ecs_set_scope(w, s);
1099 m_world = w;
1100 m_owned = false;
1101 }
1102
1103 ~scoped_world() {
1104 ecs_set_scope(m_world, m_prev_scope);
1105 }
1106
1107 scoped_world(const scoped_world& obj) : world(nullptr) {
1108 m_prev_scope = obj.m_prev_scope;
1109 m_world = obj.m_world;
1110 m_owned = obj.m_owned;
1111 }
1112
1113 flecs::entity_t m_prev_scope;
1114};
1115
1118} // namespace flecs
App world addon mixin.
Component mixin.
Entity world mixin.
Enum world mixin.
Event world mixin.
Filter 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:351
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.
bool ecs_stage_is_async(ecs_world_t *stage)
Test whether provided stage is asynchronous.
void ecs_merge(ecs_world_t *world)
Merge world or stage.
void ecs_async_stage_free(ecs_world_t *stage)
Free asynchronous stage.
void ecs_set_automerge(ecs_world_t *world, bool automerge)
Enable/disable auto-merging for world or stage.
ecs_world_t * ecs_async_stage_new(ecs_world_t *world)
Create asynchronous stage.
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.
int32_t ecs_get_stage_id(const ecs_world_t *world)
Get current stage id.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:318
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:362
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:311
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:621
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:626
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
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:57
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 signaled.
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.
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.
Plecs world mixin.
Query world mixin.
Rule world mixin.
Snapshot world mixin.
Type that contains information about the world.
Definition flecs.h:1232
float delta_time
Time passed to or computed by ecs_progress.
Definition flecs.h:1238
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1093
The world.
Definition world.hpp:132
bool is_stage() const
Test if is a stage.
Definition world.hpp:339
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:915
void set_automerge(bool automerge) const
Enable/disable auto-merging for world or stage.
Definition world.hpp:363
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:932
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:927
void merge() const
Merge world or stage.
Definition world.hpp:375
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:904
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1027
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:69
void remove() const
Remove singleton component.
Definition world.hpp:180
void set(A &&value) const
Set singleton pair.
Definition world.hpp:572
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1032
void quit() const
Signal application should quit.
Definition world.hpp:207
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition world.hpp:250
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:493
void readonly_end() const
End readonly mode.
Definition world.hpp:269
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:857
int count() const
Count entities matching a component.
Definition world.hpp:812
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:213
const T * get() const
Get singleton component.
Definition world.hpp:116
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:963
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:219
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:997
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:200
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:279
void reset()
Deletes and recreates the world.
Definition world.hpp:191
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:533
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:973
void set(const A &value) const
Set singleton pair.
Definition world.hpp:564
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1006
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:414
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:294
world & operator=(const world &obj)=delete
Not allowed to copy a world.
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:474
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:329
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:888
void defer_resume() const
Resume deferring operations.
Definition world.hpp:981
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:74
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition world.hpp:483
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:310
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:841
void * get_ctx() const
Get world context.
Definition world.hpp:456
world(const world &obj)=delete
Not allowed to copy a world.
int count() const
Count entities matching a pair.
Definition world.hpp:832
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:949
bool defer_end() const
End block of operations to defer.
Definition world.hpp:288
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:803
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:955
world(world_t *w)
Create world from C world.
Definition world.hpp:149
void children(Func &&f) const
Iterate entities in root of world Accepts a callback with the following signature:
Definition world.hpp:203
flecs::world get_world() const
Get actual world.
Definition world.hpp:426
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:879
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:850
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:937
flecs::entity lookup(const char *name, bool search_path=true) const
Lookup entity by name.
Definition world.hpp:78
void modified() const
Mark singleton component as modified.
Definition world.hpp:92
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:822
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:241
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition world.hpp:36
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:438
void add() const
Add singleton component.
Definition world.hpp:157
T & ensure() const
Ensure singleton component.
Definition world.hpp:85
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:261
void set(const T &value) const
Set singleton component.
Definition world.hpp:548
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:871
void enable_range_check(bool enabled) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:505
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:393
void set(T &&value) const
Set singleton component.
Definition world.hpp:555
bool has() const
Test if world has singleton component.
Definition world.hpp:134
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:989
world()
Create world.
Definition world.hpp:135
void frame_end() const
End frame.
Definition world.hpp:251
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:466
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:213
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:319
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:909
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:921
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:208
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:864
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:448
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:143
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:794
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:943
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:110
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:108
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:114