Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
world.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs
9{
10
11/* Static helper functions to assign a component value */
12
13// set(T&&), T = constructible
14template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
15inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
16 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
17
18 if (!ecs_is_deferred(world)) {
19 T& dst = *static_cast<T*>(ecs_ensure_id(world, entity, id));
20 dst = FLECS_MOV(value);
21
22 ecs_modified_id(world, entity, id);
23 } else {
24 T& dst = *static_cast<T*>(ecs_ensure_modified_id(world, entity, id));
25 dst = FLECS_MOV(value);
26 }
27}
28
29// set(const T&), T = constructible
30template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
31inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
32 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
33
34 if (!ecs_is_deferred(world)) {
35 T& dst = *static_cast<T*>(ecs_ensure_id(world, entity, id));
36 dst = FLECS_MOV(value);
37
38 ecs_modified_id(world, entity, id);
39 } else {
40 T& dst = *static_cast<T*>(ecs_ensure_modified_id(world, entity, id));
41 dst = FLECS_MOV(value);
42 }
43}
44
45// set(T&&), T = not constructible
46template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
47inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
48 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
49
50 if (!ecs_is_deferred(world)) {
51 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
52 dst = FLECS_MOV(value);
53
54 ecs_modified_id(world, entity, id);
55 } else {
56 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
57 dst = FLECS_MOV(value);
58 }
59}
60
61// set(const T&), T = not constructible
62template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
63inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
64 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
65
66 if (!ecs_is_deferred(world)) {
67 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_id(world, entity, id));
68 dst = FLECS_MOV(value);
69
70 ecs_modified_id(world, entity, id);
71 } else {
72 T& dst = *static_cast<remove_reference_t<T>*>(ecs_ensure_modified_id(world, entity, id));
73 dst = FLECS_MOV(value);
74 }
75}
76
77// emplace for T(Args...)
78template <typename T, typename ... Args, if_t<
79 std::is_constructible<actual_type_t<T>, Args...>::value ||
80 std::is_default_constructible<actual_type_t<T>>::value > = 0>
81inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
82 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
83 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id));
84
85 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
86
87 ecs_modified_id(world, entity, id);
88}
89
90// set(T&&)
91template <typename T, typename A>
92inline void set(world_t *world, entity_t entity, A&& value) {
93 id_t id = _::cpp_type<T>::id(world);
94 flecs::set(world, entity, FLECS_FWD(value), id);
95}
96
97// set(const T&)
98template <typename T, typename A>
99inline void set(world_t *world, entity_t entity, const A& value) {
100 id_t id = _::cpp_type<T>::id(world);
101 flecs::set(world, entity, value, id);
102}
103
108inline flecs::id_t strip_generation(flecs::entity_t e) {
109 return ecs_strip_generation(e);
110}
111
114inline uint32_t get_generation(flecs::entity_t e) {
115 return ECS_GENERATION(e);
116}
117
118struct scoped_world;
119
132struct world {
135 explicit world()
136 : m_world( ecs_init() )
137 , m_owned( true ) { init_builtin_components(); }
138
143 explicit world(int argc, char *argv[])
144 : m_world( ecs_init_w_args(argc, argv) )
145 , m_owned( true ) { init_builtin_components(); }
146
149 explicit world(world_t *w, bool owned = false)
150 : m_world( w )
151 , m_owned( owned ) { }
152
155 world(const world& obj) = delete;
156
157 world(world&& obj) noexcept {
158 m_world = obj.m_world;
159 m_owned = obj.m_owned;
160 obj.m_world = nullptr;
161 obj.m_owned = false;
162 }
163
164 /* Implicit conversion to world_t* */
165 operator world_t*() const { return m_world; }
166
169 world& operator=(const world& obj) = delete;
170
171 world& operator=(world&& obj) noexcept {
172 this->~world();
173
174 m_world = obj.m_world;
175 m_owned = obj.m_owned;
176 obj.m_world = nullptr;
177 obj.m_owned = false;
178 return *this;
179 }
180
181 ~world() {
182 if (m_owned && ecs_stage_is_async(m_world)) {
183 ecs_async_stage_free(m_world);
184 } else
185 if (m_owned && m_world) {
186 ecs_fini(m_world);
187 }
188 }
189
191 void reset() {
192 // Can only reset the world if we own the world object.
193 ecs_assert(this->m_owned, ECS_INVALID_OPERATION, NULL);
194 ecs_fini(m_world);
195 m_world = ecs_init();
196 }
197
200 world_t* c_ptr() const {
201 return m_world;
202 }
203
207 void quit() const {
208 ecs_quit(m_world);
209 }
210
213 void atfini(ecs_fini_action_t action, void *ctx = nullptr) const {
214 ecs_atfini(m_world, action, ctx);
215 }
216
219 bool should_quit() const {
220 return ecs_should_quit(m_world);
221 }
222
242 return ecs_frame_begin(m_world, delta_time);
243 }
244
251 void frame_end() const {
252 ecs_frame_end(m_world);
253 }
254
261 bool readonly_begin(bool multi_threaded = false) const {
262 return ecs_readonly_begin(m_world, multi_threaded);
263 }
264
269 void readonly_end() const {
270 ecs_readonly_end(m_world);
271 }
272
279 bool defer_begin() const {
280 return ecs_defer_begin(m_world);
281 }
282
288 bool defer_end() const {
289 return ecs_defer_end(m_world);
290 }
291
294 bool is_deferred() const {
295 return ecs_is_deferred(m_world);
296 }
297
310 void set_stage_count(int32_t stages) const {
311 ecs_set_stage_count(m_world, stages);
312 }
313
319 int32_t get_stage_count() const {
320 return ecs_get_stage_count(m_world);
321 }
322
329 int32_t get_stage_id() const {
330 return ecs_get_stage_id(m_world);
331 }
332
339 bool is_stage() const {
341 ecs_poly_is(m_world, ecs_world_t) ||
342 ecs_poly_is(m_world, ecs_stage_t),
343 ECS_INVALID_PARAMETER, NULL);
344 return ecs_poly_is(m_world, ecs_stage_t);
345 }
346
363 void set_automerge(bool automerge) const {
364 ecs_set_automerge(m_world, automerge);
365 }
366
375 void merge() const {
376 ecs_merge(m_world);
377 }
378
393 flecs::world get_stage(int32_t stage_id) const {
394 return flecs::world(ecs_get_stage(m_world, stage_id));
395 }
396
415 auto result = flecs::world(ecs_async_stage_new(m_world));
416 result.m_owned = true;
417 return result;
418 }
419
427 /* Safe cast, mutability is checked */
428 return flecs::world(
429 m_world ? const_cast<flecs::world_t*>(ecs_get_world(m_world)) : nullptr);
430 }
431
438 bool is_readonly() const {
439 return ecs_stage_is_readonly(m_world);
440 }
441
448 void set_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
449 ecs_set_ctx(m_world, ctx, ctx_free);
450 }
451
456 void* get_ctx() const {
457 return ecs_get_ctx(m_world);
458 }
459
466 void set_binding_ctx(void* ctx, ecs_ctx_free_t ctx_free = nullptr) const {
467 ecs_set_binding_ctx(m_world, ctx, ctx_free);
468 }
469
474 void* get_binding_ctx() const {
475 return ecs_get_binding_ctx(m_world);
476 }
477
483 void dim(int32_t entity_count) const {
484 ecs_dim(m_world, entity_count);
485 }
486
493 void set_entity_range(entity_t min, entity_t max) const {
494 ecs_set_entity_range(m_world, min, max);
495 }
496
505 void enable_range_check(bool enabled) const {
506 ecs_enable_range_check(m_world, enabled);
507 }
508
515 flecs::entity set_scope(const flecs::entity_t scope) const;
516
522 flecs::entity get_scope() const;
523
527 template <typename T>
528 flecs::entity set_scope() const;
529
533 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
534 return ecs_set_lookup_path(m_world, search_path);
535 }
536
543 flecs::entity lookup(const char *name, bool search_path = true) const;
544
547 template <typename T, if_t< !is_callable<T>::value > = 0>
548 void set(const T& value) const {
549 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world), value);
550 }
551
554 template <typename T, if_t< !is_callable<T>::value > = 0>
555 void set(T&& value) const {
556 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world),
557 FLECS_FWD(value));
558 }
559
562 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
563 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
564 void set(const A& value) const {
565 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), value);
566 }
567
570 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
571 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
572 void set(A&& value) const {
573 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), FLECS_FWD(value));
574 }
575
578 template <typename First, typename Second>
579 void set(Second second, const First& value) const;
580
583 template <typename First, typename Second>
584 void set(Second second, First&& value) const;
585
588 template <typename Func, if_t< is_callable<Func>::value > = 0 >
589 void set(const Func& func) const;
590
591 template <typename T, typename ... Args>
592 void emplace(Args&&... args) const {
593 flecs::id_t component_id = _::cpp_type<T>::id(m_world);
594 flecs::emplace<T>(m_world, component_id, component_id,
595 FLECS_FWD(args)...);
596 }
597
600 #ifndef ensure
601 template <typename T>
602 T& ensure() const;
603 #endif
604
607 template <typename T>
608 void modified() const;
609
612 template <typename T>
613 ref<T> get_ref() const;
614
617 template <typename T>
618 const T* get() const;
619
622 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
623 typename A = actual_type_t<P>>
624 const A* get() const;
625
628 template <typename First, typename Second>
629 const First* get(Second second) const;
630
633 template <typename Func, if_t< is_callable<Func>::value > = 0 >
634 void get(const Func& func) const;
635
638 template <typename T>
639 T* get_mut() const;
640
643 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
644 typename A = actual_type_t<P>>
645 A* get_mut() const;
646
649 template <typename First, typename Second>
650 First* get_mut(Second second) const;
651
654 template <typename T>
655 bool has() const;
656
662 template <typename First, typename Second>
663 bool has() const;
664
670 template <typename First>
671 bool has(flecs::id_t second) const;
672
678 bool has(flecs::id_t first, flecs::id_t second) const;
679
682 template <typename T>
683 void add() const;
684
690 template <typename First, typename Second>
691 void add() const;
692
698 template <typename First>
699 void add(flecs::entity_t second) const;
700
706 void add(flecs::entity_t first, flecs::entity_t second) const;
707
710 template <typename T>
711 void remove() const;
712
718 template <typename First, typename Second>
719 void remove() const;
720
726 template <typename First>
727 void remove(flecs::entity_t second) const;
728
734 void remove(flecs::entity_t first, flecs::entity_t second) const;
735
743 template <typename Func>
744 void children(Func&& f) const;
745
748 template <typename T>
749 flecs::entity singleton() const;
750
759 template<typename First>
760 flecs::entity target(int32_t index = 0) const;
761
770 template<typename T>
771 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
772
781 flecs::entity target(flecs::entity_t first, int32_t index = 0) const;
782
789 template <typename T>
790 flecs::entity use(const char *alias = nullptr) const;
791
797 flecs::entity use(const char *name, const char *alias = nullptr) const;
798
804 void use(flecs::entity entity, const char *alias = nullptr) const;
805
810 int count(flecs::id_t component_id) const {
811 return ecs_count_id(m_world, component_id);
812 }
813
819 int count(flecs::entity_t first, flecs::entity_t second) const {
820 return ecs_count_id(m_world, ecs_pair(first, second));
821 }
822
827 template <typename T>
828 int count() const {
829 return count(_::cpp_type<T>::id(m_world));
830 }
831
837 template <typename First>
838 int count(flecs::entity_t second) const {
839 return count(_::cpp_type<First>::id(m_world), second);
840 }
841
847 template <typename First, typename Second>
848 int count() const {
849 return count(
850 _::cpp_type<First>::id(m_world),
851 _::cpp_type<Second>::id(m_world));
852 }
853
856 template <typename Func>
857 void with(id_t with_id, const Func& func) const {
858 ecs_id_t prev = ecs_set_with(m_world, with_id);
859 func();
860 ecs_set_with(m_world, prev);
861 }
862
865 template <typename T, typename Func>
866 void with(const Func& func) const {
867 with(this->id<T>(), func);
868 }
869
872 template <typename First, typename Second, typename Func>
873 void with(const Func& func) const {
874 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
875 }
876
879 template <typename First, typename Func>
880 void with(id_t second, const Func& func) const {
881 with(ecs_pair(this->id<First>(), second), func);
882 }
883
886 template <typename Func>
887 void with(id_t first, id_t second, const Func& func) const {
888 with(ecs_pair(first, second), func);
889 }
890
894 template <typename Func>
895 void scope(id_t parent, const Func& func) const {
896 ecs_entity_t prev = ecs_set_scope(m_world, parent);
897 func();
898 ecs_set_scope(m_world, prev);
899 }
900
903 template <typename T, typename Func>
904 void scope(const Func& func) const {
905 flecs::id_t parent = _::cpp_type<T>::id(m_world);
906 scope(parent, func);
907 }
908
912 flecs::scoped_world scope(id_t parent) const;
913
914 template <typename T>
915 flecs::scoped_world scope() const;
916
917 flecs::scoped_world scope(const char* name) const;
918
920 void delete_with(id_t the_id) const {
921 ecs_delete_with(m_world, the_id);
922 }
923
925 void delete_with(entity_t first, entity_t second) const {
926 delete_with(ecs_pair(first, second));
927 }
928
930 template <typename T>
931 void delete_with() const {
933 }
934
936 template <typename First, typename Second>
937 void delete_with() const {
939 }
940
942 template <typename First>
943 void delete_with(entity_t second) const {
944 delete_with(_::cpp_type<First>::id(m_world), second);
945 }
946
948 void remove_all(id_t the_id) const {
949 ecs_remove_all(m_world, the_id);
950 }
951
953 void remove_all(entity_t first, entity_t second) const {
954 remove_all(ecs_pair(first, second));
955 }
956
958 template <typename T>
959 void remove_all() const {
961 }
962
964 template <typename First, typename Second>
965 void remove_all() const {
967 }
968
970 template <typename First>
971 void remove_all(entity_t second) const {
972 remove_all(_::cpp_type<First>::id(m_world), second);
973 }
974
978 template <typename Func>
979 void defer(const Func& func) const {
980 ecs_defer_begin(m_world);
981 func();
982 ecs_defer_end(m_world);
983 }
984
989 void defer_suspend() const {
990 ecs_defer_suspend(m_world);
991 }
992
997 void defer_resume() const {
998 ecs_defer_resume(m_world);
999 }
1000
1005 bool exists(flecs::entity_t e) const {
1006 return ecs_exists(m_world, e);
1007 }
1008
1013 bool is_alive(flecs::entity_t e) const {
1014 return ecs_is_alive(m_world, e);
1015 }
1016
1022 bool is_valid(flecs::entity_t e) const {
1023 return ecs_is_valid(m_world, e);
1024 }
1025
1031 flecs::entity get_alive(flecs::entity_t e) const;
1032
1033 flecs::entity make_alive(flecs::entity_t e) const;
1034
1035 /* Run callback after completing frame */
1036 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
1037 ecs_run_post_frame(m_world, action, ctx);
1038 }
1039
1044 return ecs_get_world_info(m_world);
1045 }
1046
1049 return get_info()->delta_time;
1050 }
1051
1052# include "mixins/id/mixin.inl"
1054# include "mixins/entity/mixin.inl"
1055# include "mixins/event/mixin.inl"
1056# include "mixins/term/mixin.inl"
1057# include "mixins/filter/mixin.inl"
1058# include "mixins/observer/mixin.inl"
1059# include "mixins/query/mixin.inl"
1060# include "mixins/enum/mixin.inl"
1061
1062# ifdef FLECS_MODULE
1063# include "mixins/module/mixin.inl"
1064# endif
1065# ifdef FLECS_PIPELINE
1066# include "mixins/pipeline/mixin.inl"
1067# endif
1068# ifdef FLECS_SNAPSHOT
1069# include "mixins/snapshot/mixin.inl"
1070# endif
1071# ifdef FLECS_SYSTEM
1072# include "mixins/system/mixin.inl"
1073# endif
1074# ifdef FLECS_TIMER
1075# include "mixins/timer/mixin.inl"
1076# endif
1077# ifdef FLECS_RULES
1078# include "mixins/rule/mixin.inl"
1079# endif
1080# ifdef FLECS_PLECS
1081# include "mixins/plecs/mixin.inl"
1082# endif
1083# ifdef FLECS_META
1084# include "mixins/meta/world.inl"
1085# endif
1086# ifdef FLECS_JSON
1087# include "mixins/json/world.inl"
1088# endif
1089# ifdef FLECS_APP
1090# include "mixins/app/mixin.inl"
1091# endif
1092# ifdef FLECS_METRICS
1093# include "mixins/metrics/mixin.inl"
1094# endif
1095# ifdef FLECS_ALERTS
1096# include "mixins/alerts/mixin.inl"
1097# endif
1098
1099public:
1100 void init_builtin_components();
1101
1102 world_t *m_world;
1103 bool m_owned;
1104};
1105
1111 flecs::world_t *w,
1112 flecs::entity_t s) : world(nullptr)
1113 {
1114 m_prev_scope = ecs_set_scope(w, s);
1115 m_world = w;
1116 m_owned = false;
1117 }
1118
1119 ~scoped_world() {
1120 ecs_set_scope(m_world, m_prev_scope);
1121 }
1122
1123 scoped_world(const scoped_world& obj) : world(nullptr) {
1124 m_prev_scope = obj.m_prev_scope;
1125 m_world = obj.m_world;
1126 m_owned = obj.m_owned;
1127 }
1128
1129 flecs::entity_t m_prev_scope;
1130};
1131
1134} // namespace flecs
App world addon mixin.
Component mixin.
Entity world mixin.
Enum world mixin.
Event world mixin.
Filter world mixin.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
void ecs_remove_all(ecs_world_t *world, ecs_id_t id)
Remove all instances of the specified (component) id.
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:351
bool ecs_defer_end(ecs_world_t *world)
End block of operations to defer.
bool ecs_readonly_begin(ecs_world_t *world, bool multi_threaded)
Begin readonly mode.
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until end of frame.
void ecs_defer_suspend(ecs_world_t *world)
Suspend deferring but do not flush queue.
bool ecs_is_deferred(const ecs_world_t *world)
Test if deferring is enabled for current stage.
bool ecs_stage_is_async(ecs_world_t *stage)
Test whether provided stage is asynchronous.
void ecs_merge(ecs_world_t *world)
Merge world or stage.
void ecs_async_stage_free(ecs_world_t *stage)
Free asynchronous stage.
void ecs_set_automerge(ecs_world_t *world, bool automerge)
Enable/disable auto-merging for world or stage.
ecs_world_t * ecs_async_stage_new(ecs_world_t *world)
Create asynchronous stage.
bool ecs_stage_is_readonly(const ecs_world_t *world)
Test whether the current world is readonly.
int32_t ecs_get_stage_count(const ecs_world_t *world)
Get number of configured stages.
ecs_world_t * ecs_get_stage(const ecs_world_t *world, int32_t stage_id)
Get stage-specific world pointer.
void ecs_set_stage_count(ecs_world_t *world, int32_t stages)
Configure world to have N stages.
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
int32_t ecs_get_stage_id(const ecs_world_t *world)
Get current stage id.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:318
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:362
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:311
flecs::entity entity(Args &&... args) const
Create an entity.
void ecs_delete_with(ecs_world_t *world, ecs_id_t id)
Delete all entities with the specified id.
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified id.
void(* ecs_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
Definition flecs.h:621
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:626
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Emplace a component.
void * ecs_ensure_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
void * ecs_ensure_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Combines ensure + modified in single operation.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove generation from entity id.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
bool ecs_exists(const ecs_world_t *world, ecs_entity_t entity)
Test whether an entity exists.
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:57
ecs_entity_t * ecs_set_lookup_path(ecs_world_t *world, const ecs_entity_t *lookup_path)
Set search path for lookup operations.
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
void ecs_atfini(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed when world is destroyed.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init(void)
Create a new world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
float ecs_frame_begin(ecs_world_t *world, float delta_time)
Begin frame.
void ecs_run_post_frame(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed once after frame.
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been signaled.
void ecs_quit(ecs_world_t *world)
Signal exit This operation signals that the application should quit.
void ecs_frame_end(ecs_world_t *world)
End frame.
void * ecs_get_binding_ctx(const ecs_world_t *world)
Get the world binding context.
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issuing new entity ids.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
void ecs_set_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world context.
void ecs_set_binding_ctx(ecs_world_t *world, void *ctx, ecs_ctx_free_t ctx_free)
Set a world binding context.
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
void * ecs_get_ctx(const ecs_world_t *world)
Get the world context.
Id world mixin.
JSON world mixin.
Meta world mixin.
Module world mixin.
Observer world mixin.
Pipeline world mixin.
Plecs world mixin.
Query world mixin.
Rule world mixin.
Snapshot world mixin.
Type that contains information about the world.
Definition flecs.h:1232
float delta_time
Time passed to or computed by ecs_progress.
Definition flecs.h:1238
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1109
The world.
Definition world.hpp:132
bool is_stage() const
Test if is a stage.
Definition world.hpp:339
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:931
void set_automerge(bool automerge) const
Enable/disable auto-merging for world or stage.
Definition world.hpp:363
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:948
void delete_with(entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:943
void merge() const
Merge world or stage.
Definition world.hpp:375
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:920
const flecs::world_info_t * get_info() const
Get the world info.
Definition world.hpp:1043
flecs::entity get_scope() const
Get current scope.
Definition world.hpp:69
T * get_mut() const
Get mutable singleton component.
Definition world.hpp:134
void remove() const
Remove singleton component.
Definition world.hpp:198
void set(A &&value) const
Set singleton pair.
Definition world.hpp:572
ecs_ftime_t delta_time() const
Get delta_time.
Definition world.hpp:1048
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:268
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:493
void readonly_end() const
End readonly mode.
Definition world.hpp:269
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:873
int count() const
Count entities matching a component.
Definition world.hpp:828
flecs::entity target(int32_t index=0) const
Get target for a given pair from a singleton entity.
Definition world.hpp:231
const T * get() const
Get singleton component.
Definition world.hpp:116
void defer(const Func &func) const
Defer all operations called in function.
Definition world.hpp:979
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:1013
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:200
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:279
void reset()
Deletes and recreates the world.
Definition world.hpp:191
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition world.hpp:533
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:989
void set(const A &value) const
Set singleton pair.
Definition world.hpp:564
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:1022
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:414
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:294
world & operator=(const world &obj)=delete
Not allowed to copy a world.
void * get_binding_ctx() const
Get world binding context.
Definition world.hpp:474
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:329
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:904
void defer_resume() const
Resume deferring operations.
Definition world.hpp:997
flecs::entity set_scope() const
Same as set_scope but with type.
Definition world.hpp:74
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition world.hpp:483
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:310
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:857
void * get_ctx() const
Get world context.
Definition world.hpp:456
world(const world &obj)=delete
Not allowed to copy a world.
int count() const
Count entities matching a pair.
Definition world.hpp:848
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:965
bool defer_end() const
End block of operations to defer.
Definition world.hpp:288
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:819
void remove_all(entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:971
void children(Func &&f) const
Iterate entities in root of world Accepts a callback with the following signature:
Definition world.hpp:221
flecs::world get_world() const
Get actual world.
Definition world.hpp:426
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:895
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:866
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:953
flecs::entity lookup(const char *name, bool search_path=true) const
Lookup entity by name.
Definition world.hpp:78
void modified() const
Mark singleton component as modified.
Definition world.hpp:92
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:838
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:241
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition world.hpp:36
bool is_readonly() const
Test whether the current world object is readonly.
Definition world.hpp:438
void add() const
Add singleton component.
Definition world.hpp:175
T & ensure() const
Ensure singleton component.
Definition world.hpp:85
bool readonly_begin(bool multi_threaded=false) const
Begin readonly mode.
Definition world.hpp:261
void set(const T &value) const
Set singleton component.
Definition world.hpp:548
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:887
void enable_range_check(bool enabled) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:505
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:393
void set(T &&value) const
Set singleton component.
Definition world.hpp:555
bool has() const
Test if world has singleton component.
Definition world.hpp:152
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:1005
world()
Create world.
Definition world.hpp:135
void frame_end() const
End frame.
Definition world.hpp:251
void set_binding_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world binding context.
Definition world.hpp:466
void atfini(ecs_fini_action_t action, void *ctx=nullptr) const
Register action to be executed when world is destroyed.
Definition world.hpp:213
world(world_t *w, bool owned=false)
Create world from C world.
Definition world.hpp:149
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:319
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:925
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:937
flecs::entity singleton() const
Get singleton entity for type.
Definition world.hpp:226
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:880
void set_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr) const
Set world context.
Definition world.hpp:448
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:143
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:810
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:959
ref< T > get_ref() const
Get ref singleton component.
Definition world.hpp:110
System module world mixin.
Term world mixin.
Timer module mixin.
flecs::id_t strip_generation(flecs::entity_t e)
Return id without generation.
Definition world.hpp:108
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:114