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_get_mut_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_get_mut_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_get_mut_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_get_mut_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_get_mut_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_get_mut_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_get_mut_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_get_mut_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
273 bool readonly_begin() const {
274 return ecs_readonly_begin(m_world);
275 }
276
284 void readonly_end() const {
285 ecs_readonly_end(m_world);
286 }
287
294 bool defer_begin() const {
295 return ecs_defer_begin(m_world);
296 }
297
303 bool defer_end() const {
304 return ecs_defer_end(m_world);
305 }
306
309 bool is_deferred() const {
310 return ecs_is_deferred(m_world);
311 }
312
325 void set_stage_count(int32_t stages) const {
326 ecs_set_stage_count(m_world, stages);
327 }
328
334 int32_t get_stage_count() const {
335 return ecs_get_stage_count(m_world);
336 }
337
344 int32_t get_stage_id() const {
345 return ecs_get_stage_id(m_world);
346 }
347
354 bool is_stage() const {
356 ecs_poly_is(m_world, ecs_world_t) ||
357 ecs_poly_is(m_world, ecs_stage_t),
358 ECS_INVALID_PARAMETER, NULL);
359 return ecs_poly_is(m_world, ecs_stage_t);
360 }
361
378 void set_automerge(bool automerge) const {
379 ecs_set_automerge(m_world, automerge);
380 }
381
390 void merge() const {
391 ecs_merge(m_world);
392 }
393
408 flecs::world get_stage(int32_t stage_id) const {
409 return flecs::world(ecs_get_stage(m_world, stage_id));
410 }
411
430 auto result = flecs::world(ecs_async_stage_new(m_world));
431 result.m_owned = true;
432 return result;
433 }
434
442 /* Safe cast, mutability is checked */
443 return flecs::world(
444 m_world ? const_cast<flecs::world_t*>(ecs_get_world(m_world)) : nullptr);
445 }
446
453 bool is_readonly() const {
454 return ecs_stage_is_readonly(m_world);
455 }
456
463 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
464 ecs_set_ctx(m_world, ctx, ctx_free);
465 }
466
471 void* get_ctx() const {
472 return ecs_get_ctx(m_world);
473 }
474
481 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
482 ecs_set_binding_ctx(m_world, ctx, ctx_free);
483 }
484
489 void* get_binding_ctx() const {
490 return ecs_get_binding_ctx(m_world);
491 }
492
498 void dim(int32_t entity_count) const {
499 ecs_dim(m_world, entity_count);
500 }
501
508 void set_entity_range(entity_t min, entity_t max) const {
509 ecs_set_entity_range(m_world, min, max);
510 }
511
520 void enable_range_check(bool enabled) const {
521 ecs_enable_range_check(m_world, enabled);
522 }
523
530 flecs::entity set_scope(const flecs::entity_t scope) const;
531
537 flecs::entity get_scope() const;
538
542 template <typename T>
543 flecs::entity set_scope() const;
544
548 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
549 return ecs_set_lookup_path(m_world, search_path);
550 }
551
558 flecs::entity lookup(const char *name, bool search_path = true) const;
559
562 template <typename T, if_t< !is_callable<T>::value > = 0>
563 void set(const T& value) const {
564 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world), value);
565 }
566
569 template <typename T, if_t< !is_callable<T>::value > = 0>
570 void set(T&& value) const {
571 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world),
572 FLECS_FWD(value));
573 }
574
577 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
578 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
579 void set(const A& value) const {
580 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), value);
581 }
582
585 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
586 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
587 void set(A&& value) const {
588 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), FLECS_FWD(value));
589 }
590
593 template <typename First, typename Second>
594 void set(Second second, const First& value) const;
595
598 template <typename First, typename Second>
599 void set(Second second, First&& value) const;
600
603 template <typename Func, if_t< is_callable<Func>::value > = 0 >
604 void set(const Func& func) const;
605
606 template <typename T, typename ... Args>
607 void emplace(Args&&... args) const {
608 flecs::id_t component_id = _::cpp_type<T>::id(m_world);
609 flecs::emplace<T>(m_world, component_id, component_id,
610 FLECS_FWD(args)...);
611 }
612
615 template <typename T>
616 T* get_mut() const;
617
620 template <typename T>
621 void modified() const;
622
625 template <typename T>
626 ref<T> get_ref() const;
627
630 template <typename T>
631 const T* get() const;
632
635 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
636 typename A = actual_type_t<P>>
637 const A* get() const;
638
641 template <typename First, typename Second>
642 const First* get(Second second) const;
643
646 template <typename Func, if_t< is_callable<Func>::value > = 0 >
647 void get(const Func& func) const;
648
651 template <typename T>
652 bool has() const;
653
659 template <typename First, typename Second>
660 bool has() const;
661
667 template <typename First>
668 bool has(flecs::id_t second) const;
669
675 bool has(flecs::id_t first, flecs::id_t second) const;
676
679 template <typename T>
680 void add() const;
681
687 template <typename First, typename Second>
688 void add() const;
689
695 template <typename First>
696 void add(flecs::entity_t second) const;
697
703 void add(flecs::entity_t first, flecs::entity_t second) const;
704
707 template <typename T>
708 void remove() const;
709
715 template <typename First, typename Second>
716 void remove() const;
717
723 template <typename First>
724 void remove(flecs::entity_t second) const;
725
731 void remove(flecs::entity_t first, flecs::entity_t second) const;
732
740 template <typename Func>
741 void children(Func&& f) const;
742
745 template <typename T>
746 flecs::entity singleton() const;
747
756 template<typename First>
757 flecs::entity target(int32_t index = 0) const;
758
767 template<typename T>
768 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
769
778 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
779
786 template <typename T>
787 flecs::entity use(const char *alias = nullptr) const;
788
794 flecs::entity use(const char *name, const char *alias = nullptr) const;
795
801 void use(flecs::entity entity, const char *alias = nullptr) const;
802
807 int count(flecs::id_t component_id) const {
808 return ecs_count_id(m_world, component_id);
809 }
810
816 int count(flecs::entity_t first, flecs::entity_t second) const {
817 return ecs_count_id(m_world, ecs_pair(first, second));
818 }
819
824 template <typename T>
825 int count() const {
826 return count(_::cpp_type<T>::id(m_world));
827 }
828
834 template <typename First>
835 int count(flecs::entity_t second) const {
836 return count(_::cpp_type<First>::id(m_world), second);
837 }
838
844 template <typename First, typename Second>
845 int count() const {
846 return count(
847 _::cpp_type<First>::id(m_world),
848 _::cpp_type<Second>::id(m_world));
849 }
850
853 template <typename Func>
854 void with(id_t with_id, const Func& func) const {
855 ecs_id_t prev = ecs_set_with(m_world, with_id);
856 func();
857 ecs_set_with(m_world, prev);
858 }
859
862 template <typename T, typename Func>
863 void with(const Func& func) const {
864 with(this->id<T>(), func);
865 }
866
869 template <typename First, typename Second, typename Func>
870 void with(const Func& func) const {
871 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
872 }
873
876 template <typename First, typename Func>
877 void with(id_t second, const Func& func) const {
878 with(ecs_pair(this->id<First>(), second), func);
879 }
880
883 template <typename Func>
884 void with(id_t first, id_t second, const Func& func) const {
885 with(ecs_pair(first, second), func);
886 }
887
891 template <typename Func>
892 void scope(id_t parent, const Func& func) const {
893 ecs_entity_t prev = ecs_set_scope(m_world, parent);
894 func();
895 ecs_set_scope(m_world, prev);
896 }
897
900 template <typename T, typename Func>
901 void scope(const Func& func) const {
902 flecs::id_t parent = _::cpp_type<T>::id(m_world);
903 scope(parent, func);
904 }
905
909 flecs::scoped_world scope(id_t parent) const;
910
911 template <typename T>
912 flecs::scoped_world scope() const;
913
914 flecs::scoped_world scope(const char* name) const;
915
917 void delete_with(id_t the_id) const {
918 ecs_delete_with(m_world, the_id);
919 }
920
922 void delete_with(entity_t first, entity_t second) const {
923 delete_with(ecs_pair(first, second));
924 }
925
927 template <typename T>
928 void delete_with() const {
930 }
931
933 template <typename First, typename Second>
934 void delete_with() const {
936 }
937
939 template <typename First>
940 void delete_with(entity_t second) const {
941 delete_with(_::cpp_type<First>::id(m_world), second);
942 }
943
945 void remove_all(id_t the_id) const {
946 ecs_remove_all(m_world, the_id);
947 }
948
950 void remove_all(entity_t first, entity_t second) const {
951 remove_all(ecs_pair(first, second));
952 }
953
955 template <typename T>
956 void remove_all() const {
958 }
959
961 template <typename First, typename Second>
962 void remove_all() const {
964 }
965
967 template <typename First>
968 void remove_all(entity_t second) const {
969 remove_all(_::cpp_type<First>::id(m_world), second);
970 }
971
975 template <typename Func>
976 void defer(const Func& func) const {
977 ecs_defer_begin(m_world);
978 func();
979 ecs_defer_end(m_world);
980 }
981
986 void defer_suspend() const {
987 ecs_defer_suspend(m_world);
988 }
989
994 void defer_resume() const {
995 ecs_defer_resume(m_world);
996 }
997
1002 bool exists(flecs::entity_t e) const {
1003 return ecs_exists(m_world, e);
1004 }
1005
1010 bool is_alive(flecs::entity_t e) const {
1011 return ecs_is_alive(m_world, e);
1012 }
1013
1019 bool is_valid(flecs::entity_t e) const {
1020 return ecs_is_valid(m_world, e);
1021 }
1022
1028 flecs::entity get_alive(flecs::entity_t e) const;
1029
1030/* Prevent clashing with Unreal define. Unreal applications will have to use
1031 * ecs_ensure. */
1032#ifndef ensure
1039 flecs::entity ensure(flecs::entity_t e) const;
1040#endif
1041
1042 /* Run callback after completing frame */
1043 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1044 ecs_run_post_frame(m_world, action, ctx);
1045 }
1046
1051 return ecs_get_world_info(m_world);
1052 }
1053
1056 return get_info()->delta_time;
1057 }
1058
1059# include "mixins/id/mixin.inl"
1061# include "mixins/entity/mixin.inl"
1062# include "mixins/event/mixin.inl"
1063# include "mixins/term/mixin.inl"
1064# include "mixins/filter/mixin.inl"
1065# include "mixins/observer/mixin.inl"
1066# include "mixins/query/mixin.inl"
1067# include "mixins/enum/mixin.inl"
1068
1069# ifdef FLECS_MODULE
1070# include "mixins/module/mixin.inl"
1071# endif
1072# ifdef FLECS_PIPELINE
1073# include "mixins/pipeline/mixin.inl"
1074# endif
1075# ifdef FLECS_SNAPSHOT
1076# include "mixins/snapshot/mixin.inl"
1077# endif
1078# ifdef FLECS_SYSTEM
1079# include "mixins/system/mixin.inl"
1080# endif
1081# ifdef FLECS_TIMER
1082# include "mixins/timer/mixin.inl"
1083# endif
1084# ifdef FLECS_RULES
1085# include "mixins/rule/mixin.inl"
1086# endif
1087# ifdef FLECS_PLECS
1088# include "mixins/plecs/mixin.inl"
1089# endif
1090# ifdef FLECS_META
1091# include "mixins/meta/world.inl"
1092# endif
1093# ifdef FLECS_JSON
1094# include "mixins/json/world.inl"
1095# endif
1096# ifdef FLECS_APP
1097# include "mixins/app/mixin.inl"
1098# endif
1099# ifdef FLECS_METRICS
1100# include "mixins/metrics/mixin.inl"
1101# endif
1102# ifdef FLECS_ALERTS
1103# include "mixins/alerts/mixin.inl"
1104# endif
1105
1106public:
1107 void init_builtin_components();
1108
1109 world_t *m_world;
1110 bool m_owned;
1111};
1112
1118 flecs::world_t *w,
1119 flecs::entity_t s) : world(nullptr)
1120 {
1121 m_prev_scope = ecs_set_scope(w, s);
1122 m_world = w;
1123 m_owned = false;
1124 }
1125
1126 ~scoped_world() {
1127 ecs_set_scope(m_world, m_prev_scope);
1128 }
1129
1130 scoped_world(const scoped_world& obj) : world(nullptr) {
1131 m_prev_scope = obj.m_prev_scope;
1132 m_world = obj.m_world;
1133 m_owned = obj.m_owned;
1134 }
1135
1136 flecs::entity_t m_prev_scope;
1137};
1138
1141} // 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.
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.
bool ecs_readonly_begin(ecs_world_t *world)
Begin readonly mode.
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:305
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:349
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:298
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:608
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:613
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Emplace a component.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
void * ecs_get_mut_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Combines get_mut + modified in single operation.
void * ecs_get_mut_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
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:43
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:1204
float delta_time
Time passed to or computed by ecs_progress.
Definition flecs.h:1210
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1116
The world.
Definition world.hpp:132
bool is_stage() const
Test if is a stage.
Definition world.hpp:354
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:928
void set_automerge(bool automerge) const
Enable/disable auto-merging for world or stage.
Definition world.hpp:378
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:945
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:940
void merge() const
Merge world or stage.
Definition world.hpp:390
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:917
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1050
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:69
T * get_mut() const
Get mut singleton component.
Definition world.hpp:84
void remove() const
Remove singleton component.
Definition world.hpp:178
void set(A &&value) const
Set singleton pair.
Definition world.hpp:587
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1055
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:248
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:508
void readonly_end() const
End staging.
Definition world.hpp:284
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:870
int count() const
Count entities matching a component.
Definition world.hpp:825
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:211
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:976
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:1010
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:294
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:548
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:986
void set(const A &value) const
Set singleton pair.
Definition world.hpp:579
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1019
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:429
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:309
world & operator=(const world &obj)=delete
Not allowed to copy a world.
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:489
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:344
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:901
bool readonly_begin() const
Begin staging.
Definition world.hpp:273
void defer_resume() const
Resume deferring operations.
Definition world.hpp:994
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:498
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:325
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:854
void * get_ctx() const
Get world context.
Definition world.hpp:471
world(const world &obj)=delete
Not allowed to copy a world.
int count() const
Count entities matching a pair.
Definition world.hpp:845
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:962
bool defer_end() const
End block of operations to defer.
Definition world.hpp:303
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:816
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:968
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:201
flecs::world get_world() const
Get actual world.
Definition world.hpp:441
flecs::entity ensure(flecs::entity_t e) const
Ensures that entity with provided generation is alive.
Definition world.hpp:255
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:892
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:863
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:950
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:90
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:835
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:453
void add() const
Add singleton component.
Definition world.hpp:155
void set(const T &value) const
Set singleton component.
Definition world.hpp:563
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:884
void enable_range_check(bool enabled) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:520
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:408
void set(T &&value) const
Set singleton component.
Definition world.hpp:570
bool has() const
Test if world has singleton component.
Definition world.hpp:132
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1002
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:481
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:334
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:922
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:934
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:206
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:877
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:463
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:807
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:956
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:108
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:114