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) {
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) {
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) const {
214 ecs_atfini(m_world, action, ctx);
215 }
216
219 bool should_quit() const {
220 return ecs_should_quit(m_world);
221 }
222
241 ecs_ftime_t frame_begin(float delta_time = 0) const {
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
547 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
548 return ecs_set_lookup_path(m_world, search_path);
549 }
550
555 flecs::entity lookup(const char *name) const;
556
559 template <typename T, if_t< !is_callable<T>::value > = 0>
560 void set(const T& value) const {
561 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world), value);
562 }
563
566 template <typename T, if_t< !is_callable<T>::value > = 0>
567 void set(T&& value) const {
568 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world),
569 FLECS_FWD(value));
570 }
571
574 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
575 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
576 void set(const A& value) const {
577 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), value);
578 }
579
582 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
583 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
584 void set(A&& value) const {
585 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), FLECS_FWD(value));
586 }
587
590 template <typename First, typename Second>
591 void set(Second second, const First& value) const;
592
595 template <typename First, typename Second>
596 void set(Second second, First&& value) const;
597
600 template <typename Func, if_t< is_callable<Func>::value > = 0 >
601 void set(const Func& func) const;
602
603 template <typename T, typename ... Args>
604 void emplace(Args&&... args) const {
605 flecs::id_t component_id = _::cpp_type<T>::id(m_world);
606 flecs::emplace<T>(m_world, component_id, component_id,
607 FLECS_FWD(args)...);
608 }
609
612 template <typename T>
613 T* get_mut() const;
614
617 template <typename T>
618 void modified() const;
619
622 template <typename T>
623 ref<T> get_ref() const;
624
627 template <typename T>
628 const T* get() const;
629
632 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
633 typename A = actual_type_t<P>>
634 const A* get() const;
635
638 template <typename First, typename Second>
639 const First* get(Second second) const;
640
643 template <typename Func, if_t< is_callable<Func>::value > = 0 >
644 void get(const Func& func) const;
645
648 template <typename T>
649 bool has() const;
650
656 template <typename First, typename Second>
657 bool has() const;
658
664 template <typename First>
665 bool has(flecs::id_t second) const;
666
672 bool has(flecs::id_t first, flecs::id_t second) const;
673
676 template <typename T>
677 void add() const;
678
684 template <typename First, typename Second>
685 void add() const;
686
692 template <typename First>
693 void add(flecs::entity_t second) const;
694
700 void add(flecs::entity_t first, flecs::entity_t second) const;
701
704 template <typename T>
705 void remove() const;
706
712 template <typename First, typename Second>
713 void remove() const;
714
720 template <typename First>
721 void remove(flecs::entity_t second) const;
722
728 void remove(flecs::entity_t first, flecs::entity_t second) const;
729
734 template <typename Func>
735 void children(Func&& f) const;
736
739 template <typename T>
740 flecs::entity singleton() const;
741
750 template<typename First>
751 flecs::entity target(int32_t index = 0) const;
752
761 template<typename T>
762 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
763
772 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
773
780 template <typename T>
781 flecs::entity use(const char *alias = nullptr) const;
782
788 flecs::entity use(const char *name, const char *alias = nullptr) const;
789
795 void use(flecs::entity entity, const char *alias = nullptr) const;
796
801 int count(flecs::id_t component_id) const {
802 return ecs_count_id(m_world, component_id);
803 }
804
810 int count(flecs::entity_t first, flecs::entity_t second) const {
811 return ecs_count_id(m_world, ecs_pair(first, second));
812 }
813
818 template <typename T>
819 int count() const {
820 return count(_::cpp_type<T>::id(m_world));
821 }
822
828 template <typename First>
829 int count(flecs::entity_t second) const {
830 return count(_::cpp_type<First>::id(m_world), second);
831 }
832
838 template <typename First, typename Second>
839 int count() const {
840 return count(
841 _::cpp_type<First>::id(m_world),
842 _::cpp_type<Second>::id(m_world));
843 }
844
847 template <typename Func>
848 void with(id_t with_id, const Func& func) const {
849 ecs_id_t prev = ecs_set_with(m_world, with_id);
850 func();
851 ecs_set_with(m_world, prev);
852 }
853
856 template <typename T, typename Func>
857 void with(const Func& func) const {
858 with(this->id<T>(), func);
859 }
860
863 template <typename First, typename Second, typename Func>
864 void with(const Func& func) const {
865 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
866 }
867
870 template <typename First, typename Func>
871 void with(id_t second, const Func& func) const {
872 with(ecs_pair(this->id<First>(), second), func);
873 }
874
877 template <typename Func>
878 void with(id_t first, id_t second, const Func& func) const {
879 with(ecs_pair(first, second), func);
880 }
881
885 template <typename Func>
886 void scope(id_t parent, const Func& func) const {
887 ecs_entity_t prev = ecs_set_scope(m_world, parent);
888 func();
889 ecs_set_scope(m_world, prev);
890 }
891
894 template <typename T, typename Func>
895 void scope(const Func& func) const {
896 flecs::id_t parent = _::cpp_type<T>::id(m_world);
897 scope(parent, func);
898 }
899
903 flecs::scoped_world scope(id_t parent) const;
904
905 template <typename T>
906 flecs::scoped_world scope() const;
907
908 flecs::scoped_world scope(const char* name) const;
909
911 void delete_with(id_t the_id) const {
912 ecs_delete_with(m_world, the_id);
913 }
914
916 void delete_with(entity_t first, entity_t second) const {
917 delete_with(ecs_pair(first, second));
918 }
919
921 template <typename T>
922 void delete_with() const {
924 }
925
927 template <typename First, typename Second>
928 void delete_with() const {
930 }
931
933 void remove_all(id_t the_id) const {
934 ecs_remove_all(m_world, the_id);
935 }
936
938 void remove_all(entity_t first, entity_t second) const {
939 remove_all(ecs_pair(first, second));
940 }
941
943 template <typename T>
944 void remove_all() const {
946 }
947
949 template <typename First, typename Second>
950 void remove_all() const {
952 }
953
957 template <typename Func>
958 void defer(const Func& func) const {
959 ecs_defer_begin(m_world);
960 func();
961 ecs_defer_end(m_world);
962 }
963
968 void defer_suspend() const {
969 ecs_defer_suspend(m_world);
970 }
971
976 void defer_resume() const {
977 ecs_defer_resume(m_world);
978 }
979
984 bool exists(flecs::entity_t e) const {
985 return ecs_exists(m_world, e);
986 }
987
992 bool is_alive(flecs::entity_t e) const {
993 return ecs_is_alive(m_world, e);
994 }
995
1001 bool is_valid(flecs::entity_t e) const {
1002 return ecs_is_valid(m_world, e);
1003 }
1004
1010 flecs::entity get_alive(flecs::entity_t e) const;
1011
1012/* Prevent clashing with Unreal define. Unreal applications will have to use
1013 * ecs_ensure. */
1014#ifndef ensure
1021 flecs::entity ensure(flecs::entity_t e) const;
1022#endif
1023
1024 /* Run callback after completing frame */
1025 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1026 ecs_run_post_frame(m_world, action, ctx);
1027 }
1028
1033 return ecs_get_world_info(m_world);
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:352
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 automerging 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:286
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:330
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:279
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:585
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:590
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 + modifed 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:42
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 issueing 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:1173
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:354
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:922
void set_automerge(bool automerge) const
Enable/disable automerging 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:933
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:911
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1032
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:63
T * get_mut() const
Get mut singleton component.
Definition world.hpp:78
void remove() const
Remove singleton component.
Definition world.hpp:172
void set(A &&value) const
Set singleton pair.
Definition world.hpp:584
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:242
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:864
int count() const
Count entities matching a component.
Definition world.hpp:819
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:205
const T * get() const
Get singleton component.
Definition world.hpp:108
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:958
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:992
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 lookup(const char *name) const
Lookup entity by name.
Definition world.hpp:72
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:547
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:968
void set(const A &value) const
Set singleton pair.
Definition world.hpp:576
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1001
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:895
bool readonly_begin() const
Begin staging.
Definition world.hpp:273
void defer_resume() const
Resume deferring operations.
Definition world.hpp:976
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:68
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:848
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:839
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:950
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:810
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: void(*)(flecs::ent...
Definition world.hpp:195
flecs::world get_world() const
Get actual world.
Definition world.hpp:441
void atfini(ecs_fini_action_t action, void *ctx) const
Register action to be executed when world is destroyed.
Definition world.hpp:213
flecs::entity ensure(flecs::entity_t e) const
Ensures that entity with provided generation is alive.
Definition world.hpp:249
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:886
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:857
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:938
void modified() const
Mark singleton component as modified.
Definition world.hpp:84
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:829
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:30
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:149
void set(const T &value) const
Set singleton component.
Definition world.hpp:560
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:878
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:567
bool has() const
Test if world has singleton component.
Definition world.hpp:126
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:984
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
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:916
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:928
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:200
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:871
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:801
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:944
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:102
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