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
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
737 template <typename Func>
738 void children(Func&& f) const;
739
742 template <typename T>
743 flecs::entity singleton() const;
744
753 template<typename First>
754 flecs::entity target(int32_t index = 0) const;
755
764 template<typename T>
765 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
766
775 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
776
783 template <typename T>
784 flecs::entity use(const char *alias = nullptr) const;
785
791 flecs::entity use(const char *name, const char *alias = nullptr) const;
792
798 void use(flecs::entity entity, const char *alias = nullptr) const;
799
804 int count(flecs::id_t component_id) const {
805 return ecs_count_id(m_world, component_id);
806 }
807
813 int count(flecs::entity_t first, flecs::entity_t second) const {
814 return ecs_count_id(m_world, ecs_pair(first, second));
815 }
816
821 template <typename T>
822 int count() const {
823 return count(_::cpp_type<T>::id(m_world));
824 }
825
831 template <typename First>
832 int count(flecs::entity_t second) const {
833 return count(_::cpp_type<First>::id(m_world), second);
834 }
835
841 template <typename First, typename Second>
842 int count() const {
843 return count(
844 _::cpp_type<First>::id(m_world),
845 _::cpp_type<Second>::id(m_world));
846 }
847
850 template <typename Func>
851 void with(id_t with_id, const Func& func) const {
852 ecs_id_t prev = ecs_set_with(m_world, with_id);
853 func();
854 ecs_set_with(m_world, prev);
855 }
856
859 template <typename T, typename Func>
860 void with(const Func& func) const {
861 with(this->id<T>(), func);
862 }
863
866 template <typename First, typename Second, typename Func>
867 void with(const Func& func) const {
868 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
869 }
870
873 template <typename First, typename Func>
874 void with(id_t second, const Func& func) const {
875 with(ecs_pair(this->id<First>(), second), func);
876 }
877
880 template <typename Func>
881 void with(id_t first, id_t second, const Func& func) const {
882 with(ecs_pair(first, second), func);
883 }
884
888 template <typename Func>
889 void scope(id_t parent, const Func& func) const {
890 ecs_entity_t prev = ecs_set_scope(m_world, parent);
891 func();
892 ecs_set_scope(m_world, prev);
893 }
894
897 template <typename T, typename Func>
898 void scope(const Func& func) const {
899 flecs::id_t parent = _::cpp_type<T>::id(m_world);
900 scope(parent, func);
901 }
902
906 flecs::scoped_world scope(id_t parent) const;
907
908 template <typename T>
909 flecs::scoped_world scope() const;
910
911 flecs::scoped_world scope(const char* name) const;
912
914 void delete_with(id_t the_id) const {
915 ecs_delete_with(m_world, the_id);
916 }
917
919 void delete_with(entity_t first, entity_t second) const {
920 delete_with(ecs_pair(first, second));
921 }
922
924 template <typename T>
925 void delete_with() const {
927 }
928
930 template <typename First, typename Second>
931 void delete_with() const {
933 }
934
936 void remove_all(id_t the_id) const {
937 ecs_remove_all(m_world, the_id);
938 }
939
941 void remove_all(entity_t first, entity_t second) const {
942 remove_all(ecs_pair(first, second));
943 }
944
946 template <typename T>
947 void remove_all() const {
949 }
950
952 template <typename First, typename Second>
953 void remove_all() const {
955 }
956
960 template <typename Func>
961 void defer(const Func& func) const {
962 ecs_defer_begin(m_world);
963 func();
964 ecs_defer_end(m_world);
965 }
966
971 void defer_suspend() const {
972 ecs_defer_suspend(m_world);
973 }
974
979 void defer_resume() const {
980 ecs_defer_resume(m_world);
981 }
982
987 bool exists(flecs::entity_t e) const {
988 return ecs_exists(m_world, e);
989 }
990
995 bool is_alive(flecs::entity_t e) const {
996 return ecs_is_alive(m_world, e);
997 }
998
1004 bool is_valid(flecs::entity_t e) const {
1005 return ecs_is_valid(m_world, e);
1006 }
1007
1013 flecs::entity get_alive(flecs::entity_t e) const;
1014
1015/* Prevent clashing with Unreal define. Unreal applications will have to use
1016 * ecs_ensure. */
1017#ifndef ensure
1024 flecs::entity ensure(flecs::entity_t e) const;
1025#endif
1026
1027 /* Run callback after completing frame */
1028 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1029 ecs_run_post_frame(m_world, action, ctx);
1030 }
1031
1036 return ecs_get_world_info(m_world);
1037 }
1038
1039# include "mixins/id/mixin.inl"
1041# include "mixins/entity/mixin.inl"
1042# include "mixins/event/mixin.inl"
1043# include "mixins/term/mixin.inl"
1044# include "mixins/filter/mixin.inl"
1045# include "mixins/observer/mixin.inl"
1046# include "mixins/query/mixin.inl"
1047# include "mixins/enum/mixin.inl"
1048
1049# ifdef FLECS_MODULE
1050# include "mixins/module/mixin.inl"
1051# endif
1052# ifdef FLECS_PIPELINE
1053# include "mixins/pipeline/mixin.inl"
1054# endif
1055# ifdef FLECS_SNAPSHOT
1056# include "mixins/snapshot/mixin.inl"
1057# endif
1058# ifdef FLECS_SYSTEM
1059# include "mixins/system/mixin.inl"
1060# endif
1061# ifdef FLECS_TIMER
1062# include "mixins/timer/mixin.inl"
1063# endif
1064# ifdef FLECS_RULES
1065# include "mixins/rule/mixin.inl"
1066# endif
1067# ifdef FLECS_PLECS
1068# include "mixins/plecs/mixin.inl"
1069# endif
1070# ifdef FLECS_META
1071# include "mixins/meta/world.inl"
1072# endif
1073# ifdef FLECS_JSON
1074# include "mixins/json/world.inl"
1075# endif
1076# ifdef FLECS_APP
1077# include "mixins/app/mixin.inl"
1078# endif
1079# ifdef FLECS_METRICS
1080# include "mixins/metrics/mixin.inl"
1081# endif
1082# ifdef FLECS_ALERTS
1083# include "mixins/alerts/mixin.inl"
1084# endif
1085
1086public:
1087 void init_builtin_components();
1088
1089 world_t *m_world;
1090 bool m_owned;
1091};
1092
1098 flecs::world_t *w,
1099 flecs::entity_t s) : world(nullptr)
1100 {
1101 m_prev_scope = ecs_set_scope(w, s);
1102 m_world = w;
1103 m_owned = false;
1104 }
1105
1106 ~scoped_world() {
1107 ecs_set_scope(m_world, m_prev_scope);
1108 }
1109
1110 scoped_world(const scoped_world& obj) : world(nullptr) {
1111 m_prev_scope = obj.m_prev_scope;
1112 m_world = obj.m_world;
1113 m_owned = obj.m_owned;
1114 }
1115
1116 flecs::entity_t m_prev_scope;
1117};
1118
1121} // 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:1096
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:925
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:936
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:914
const flecs::world_info_t * get_info() const
Get the world info.
Definition: world.hpp:1035
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:587
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:867
int count() const
Count entities matching a component.
Definition: world.hpp:822
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:961
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:995
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:971
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:1004
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:898
bool readonly_begin() const
Begin staging.
Definition: world.hpp:273
void defer_resume() const
Resume deferring operations.
Definition: world.hpp:979
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:851
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:842
void remove_all() const
Remove all instances of specified pair.
Definition: world.hpp:953
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:813
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:889
void with(const Func &func) const
All entities created in function are created with type.
Definition: world.hpp:860
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition: world.hpp:941
flecs::entity lookup(const char *name, bool search_path=true) const
Lookup entity by name.
Definition: world.hpp:72
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:832
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: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:881
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:126
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition: world.hpp:987
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:919
void delete_with() const
Delete all entities with specified pair.
Definition: world.hpp:931
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:874
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:804
void remove_all() const
Remove all instances of specified component.
Definition: world.hpp:947
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