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 T& dst = *static_cast<T*>(ecs_get_mut_id(world, entity, id));
19 dst = FLECS_MOV(value);
20
21 ecs_modified_id(world, entity, id);
22}
23
24// set(const T&), T = constructible
25template <typename T, if_t< is_flecs_constructible<T>::value > = 0>
26inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
27 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
28
29 T& dst = *static_cast<T*>(ecs_get_mut_id(world, entity, id));
30 dst = value;
31
32 ecs_modified_id(world, entity, id);
33}
34
35// set(T&&), T = not constructible
36template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
37inline void set(world_t *world, flecs::entity_t entity, T&& value, flecs::id_t id) {
38 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
39
40 T& dst = *static_cast<remove_reference_t<T>*>(ecs_get_mut_id(world, entity, id));
41
42 dst = FLECS_MOV(value);
43
44 ecs_modified_id(world, entity, id);
45}
46
47// set(const T&), T = not constructible
48template <typename T, if_not_t< is_flecs_constructible<T>::value > = 0>
49inline void set(world_t *world, flecs::entity_t entity, const T& value, flecs::id_t id) {
50 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
51
52 T& dst = *static_cast<T*>(ecs_get_mut_id(world, entity, id));
53 dst = value;
54
55 ecs_modified_id(world, entity, id);
56}
57
58// emplace for T(Args...)
59template <typename T, typename ... Args, if_t<
60 std::is_constructible<actual_type_t<T>, Args...>::value ||
61 std::is_default_constructible<actual_type_t<T>>::value > = 0>
62inline void emplace(world_t *world, flecs::entity_t entity, flecs::id_t id, Args&&... args) {
63 ecs_assert(_::cpp_type<T>::size() != 0, ECS_INVALID_PARAMETER, NULL);
64 T& dst = *static_cast<T*>(ecs_emplace_id(world, entity, id));
65
66 FLECS_PLACEMENT_NEW(&dst, T{FLECS_FWD(args)...});
67
68 ecs_modified_id(world, entity, id);
69}
70
71// set(T&&)
72template <typename T, typename A>
73inline void set(world_t *world, entity_t entity, A&& value) {
74 id_t id = _::cpp_type<T>::id(world);
75 flecs::set(world, entity, FLECS_FWD(value), id);
76}
77
78// set(const T&)
79template <typename T, typename A>
80inline void set(world_t *world, entity_t entity, const A& value) {
81 id_t id = _::cpp_type<T>::id(world);
82 flecs::set(world, entity, value, id);
83}
84
89inline flecs::id_t strip_generation(flecs::entity_t e) {
90 return ecs_strip_generation(e);
91}
92
95inline uint32_t get_generation(flecs::entity_t e) {
96 return ECS_GENERATION(e);
97}
98
99struct scoped_world;
100
113struct world {
116 explicit world()
117 : m_world( ecs_init() )
118 , m_owned( true ) { init_builtin_components(); }
119
124 explicit world(int argc, char *argv[])
125 : m_world( ecs_init_w_args(argc, argv) )
126 , m_owned( true ) { init_builtin_components(); }
127
130 explicit world(world_t *w)
131 : m_world( w )
132 , m_owned( false ) { }
133
136 world(const world& obj) = delete;
137
138 world(world&& obj) {
139 m_world = obj.m_world;
140 m_owned = obj.m_owned;
141 obj.m_world = nullptr;
142 obj.m_owned = false;
143 }
144
145 /* Implicit conversion to world_t* */
146 operator world_t*() const { return m_world; }
147
150 world& operator=(const world& obj) = delete;
151
152 world& operator=(world&& obj) {
153 this->~world();
154
155 m_world = obj.m_world;
156 m_owned = obj.m_owned;
157 obj.m_world = nullptr;
158 obj.m_owned = false;
159 return *this;
160 }
161
162 ~world() {
163 if (m_owned && ecs_stage_is_async(m_world)) {
164 ecs_async_stage_free(m_world);
165 } else
166 if (m_owned && m_world) {
167 ecs_fini(m_world);
168 }
169 }
170
172 void reset() {
173 // Can only reset the world if we own the world object.
174 ecs_assert(this->m_owned, ECS_INVALID_OPERATION, NULL);
175 ecs_fini(m_world);
176 m_world = ecs_init();
177 }
178
181 world_t* c_ptr() const {
182 return m_world;
183 }
184
188 const ecs_world_info_t *stats = ecs_get_world_info(m_world);
189 return stats->delta_time;
190 }
191
194 int64_t tick() const {
195 const ecs_world_info_t *stats = ecs_get_world_info(m_world);
196 return stats->frame_count_total;
197 }
198
202 const ecs_world_info_t *stats = ecs_get_world_info(m_world);
203 return stats->world_time_total;
204 }
205
209 void quit() const {
210 ecs_quit(m_world);
211 }
212
215 void atfini(ecs_fini_action_t action, void *ctx) const {
216 ecs_atfini(m_world, action, ctx);
217 }
218
221 bool should_quit() const {
222 return ecs_should_quit(m_world);
223 }
224
244 return ecs_frame_begin(m_world, delta_time);
245 }
246
253 void frame_end() const {
254 ecs_frame_end(m_world);
255 }
256
275 bool readonly_begin() const {
276 return ecs_readonly_begin(m_world);
277 }
278
286 void readonly_end() const {
287 ecs_readonly_end(m_world);
288 }
289
296 bool defer_begin() const {
297 return ecs_defer_begin(m_world);
298 }
299
305 bool defer_end() const {
306 return ecs_defer_end(m_world);
307 }
308
311 bool is_deferred() const {
312 return ecs_is_deferred(m_world);
313 }
314
327 void set_stage_count(int32_t stages) const {
328 ecs_set_stage_count(m_world, stages);
329 }
330
336 int32_t get_stage_count() const {
337 return ecs_get_stage_count(m_world);
338 }
339
346 int32_t get_stage_id() const {
347 return ecs_get_stage_id(m_world);
348 }
349
356 bool is_stage() const {
358 ecs_poly_is(m_world, ecs_world_t) ||
359 ecs_poly_is(m_world, ecs_stage_t),
360 ECS_INVALID_PARAMETER, NULL);
361 return ecs_poly_is(m_world, ecs_stage_t);
362 }
363
380 void set_automerge(bool automerge) const {
381 ecs_set_automerge(m_world, automerge);
382 }
383
392 void merge() const {
393 ecs_merge(m_world);
394 }
395
410 flecs::world get_stage(int32_t stage_id) const {
411 return flecs::world(ecs_get_stage(m_world, stage_id));
412 }
413
432 auto result = flecs::world(ecs_async_stage_new(m_world));
433 result.m_owned = true;
434 return result;
435 }
436
444 /* Safe cast, mutability is checked */
445 return flecs::world(
446 m_world ? const_cast<flecs::world_t*>(ecs_get_world(m_world)) : nullptr);
447 }
448
455 bool is_readonly() const {
456 return ecs_stage_is_readonly(m_world);
457 }
458
465 void set_context(void* ctx) const {
466 ecs_set_context(m_world, ctx);
467 }
468
473 void* get_context() const {
474 return ecs_get_context(m_world);
475 }
476
482 void dim(int32_t entity_count) const {
483 ecs_dim(m_world, entity_count);
484 }
485
492 void set_entity_range(entity_t min, entity_t max) const {
493 ecs_set_entity_range(m_world, min, max);
494 }
495
504 void enable_range_check(bool enabled) const {
505 ecs_enable_range_check(m_world, enabled);
506 }
507
514 flecs::entity set_scope(const flecs::entity_t scope) const;
515
521 flecs::entity get_scope() const;
522
526 template <typename T>
527 flecs::entity set_scope() const;
528
531 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
532 return ecs_set_lookup_path(m_world, search_path);
533 }
534
539 flecs::entity lookup(const char *name) const;
540
543 template <typename T, if_t< !is_callable<T>::value > = 0>
544 void set(const T& value) const {
545 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world), value);
546 }
547
550 template <typename T, if_t< !is_callable<T>::value > = 0>
551 void set(T&& value) const {
552 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world),
553 FLECS_FWD(value));
554 }
555
558 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
559 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
560 void set(const A& value) const {
561 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), value);
562 }
563
566 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
567 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value> = 0>
568 void set(A&& value) const {
569 flecs::set<P>(m_world, _::cpp_type<First>::id(m_world), FLECS_FWD(value));
570 }
571
574 template <typename First, typename Second>
575 void set(Second second, const First& value) const;
576
579 template <typename First, typename Second>
580 void set(Second second, First&& value) const;
581
584 template <typename Func, if_t< is_callable<Func>::value > = 0 >
585 void set(const Func& func) const;
586
587 template <typename T, typename ... Args>
588 void emplace(Args&&... args) const {
589 flecs::id_t component_id = _::cpp_type<T>::id(m_world);
590 flecs::emplace<T>(m_world, component_id, component_id,
591 FLECS_FWD(args)...);
592 }
593
596 template <typename T>
597 T* get_mut() const;
598
601 template <typename T>
602 void modified() const;
603
606 template <typename T>
607 ref<T> get_ref() const;
608
611 template <typename T>
612 const T* get() const;
613
616 template <typename First, typename Second, typename P = flecs::pair<First, Second>,
617 typename A = actual_type_t<P>>
618 const A* get() const;
619
622 template <typename First, typename Second>
623 const First* get(Second second) const;
624
627 template <typename Func, if_t< is_callable<Func>::value > = 0 >
628 void get(const Func& func) const;
629
632 template <typename T>
633 bool has() const;
634
640 template <typename First, typename Second>
641 bool has() const;
642
648 template <typename First>
649 bool has(flecs::id_t second) const;
650
656 bool has(flecs::id_t first, flecs::id_t second) const;
657
660 template <typename T>
661 void add() const;
662
668 template <typename First, typename Second>
669 void add() const;
670
676 template <typename First>
677 void add(flecs::entity_t second) const;
678
684 void add(flecs::entity_t first, flecs::entity_t second) const;
685
688 template <typename T>
689 void remove() const;
690
696 template <typename First, typename Second>
697 void remove() const;
698
704 template <typename First>
705 void remove(flecs::entity_t second) const;
706
712 void remove(flecs::entity_t first, flecs::entity_t second) const;
713
718 template <typename Func>
719 void children(Func&& f) const;
720
723 template <typename T>
724 flecs::entity singleton() const;
725
732 template <typename T>
733 flecs::entity use(const char *alias = nullptr) const;
734
740 flecs::entity use(const char *name, const char *alias = nullptr) const;
741
747 void use(flecs::entity entity, const char *alias = nullptr) const;
748
753 int count(flecs::id_t component_id) const {
754 return ecs_count_id(m_world, component_id);
755 }
756
762 int count(flecs::entity_t first, flecs::entity_t second) const {
763 return ecs_count_id(m_world, ecs_pair(first, second));
764 }
765
770 template <typename T>
771 int count() const {
772 return count(_::cpp_type<T>::id(m_world));
773 }
774
780 template <typename First>
781 int count(flecs::entity_t second) const {
782 return count(_::cpp_type<First>::id(m_world), second);
783 }
784
790 template <typename First, typename Second>
791 int count() const {
792 return count(
793 _::cpp_type<First>::id(m_world),
794 _::cpp_type<Second>::id(m_world));
795 }
796
799 template <typename Func>
800 void with(id_t with_id, const Func& func) const {
801 ecs_id_t prev = ecs_set_with(m_world, with_id);
802 func();
803 ecs_set_with(m_world, prev);
804 }
805
808 template <typename T, typename Func>
809 void with(const Func& func) const {
810 with(this->id<T>(), func);
811 }
812
815 template <typename First, typename Second, typename Func>
816 void with(const Func& func) const {
817 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
818 }
819
822 template <typename First, typename Func>
823 void with(id_t second, const Func& func) const {
824 with(ecs_pair(this->id<First>(), second), func);
825 }
826
829 template <typename Func>
830 void with(id_t first, id_t second, const Func& func) const {
831 with(ecs_pair(first, second), func);
832 }
833
837 template <typename Func>
838 void scope(id_t parent, const Func& func) const {
839 ecs_entity_t prev = ecs_set_scope(m_world, parent);
840 func();
841 ecs_set_scope(m_world, prev);
842 }
843
846 template <typename T, typename Func>
847 void scope(const Func& func) const {
848 flecs::id_t parent = _::cpp_type<T>::id(m_world);
849 scope(parent, func);
850 }
851
855 flecs::scoped_world scope(id_t parent) const;
856
857 template <typename T>
858 flecs::scoped_world scope() const;
859
861 void delete_with(id_t the_id) const {
862 ecs_delete_with(m_world, the_id);
863 }
864
866 void delete_with(entity_t first, entity_t second) const {
867 delete_with(ecs_pair(first, second));
868 }
869
871 template <typename T>
872 void delete_with() const {
874 }
875
877 template <typename First, typename Second>
878 void delete_with() const {
880 }
881
883 void remove_all(id_t the_id) const {
884 ecs_remove_all(m_world, the_id);
885 }
886
888 void remove_all(entity_t first, entity_t second) const {
889 remove_all(ecs_pair(first, second));
890 }
891
893 template <typename T>
894 void remove_all() const {
896 }
897
899 template <typename First, typename Second>
900 void remove_all() const {
902 }
903
907 template <typename Func>
908 void defer(const Func& func) const {
909 ecs_defer_begin(m_world);
910 func();
911 ecs_defer_end(m_world);
912 }
913
918 void defer_suspend() const {
919 ecs_defer_suspend(m_world);
920 }
921
926 void defer_resume() const {
927 ecs_defer_resume(m_world);
928 }
929
934 bool exists(flecs::entity_t e) const {
935 return ecs_exists(m_world, e);
936 }
937
942 bool is_alive(flecs::entity_t e) const {
943 return ecs_is_alive(m_world, e);
944 }
945
951 bool is_valid(flecs::entity_t e) const {
952 return ecs_is_valid(m_world, e);
953 }
954
960 flecs::entity get_alive(flecs::entity_t e) const;
961
962/* Prevent clashing with Unreal define. Unreal applications will have to use
963 * ecs_ensure. */
964#ifndef ensure
971 flecs::entity ensure(flecs::entity_t e) const;
972#endif
973
974 /* Run callback after completing frame */
975 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
976 ecs_run_post_frame(m_world, action, ctx);
977 }
978
979# include "mixins/id/mixin.inl"
981# include "mixins/entity/mixin.inl"
982# include "mixins/event/mixin.inl"
983# include "mixins/term/mixin.inl"
984# include "mixins/filter/mixin.inl"
986# include "mixins/query/mixin.inl"
987# include "mixins/enum/mixin.inl"
988
989# ifdef FLECS_MODULE
990# include "mixins/module/mixin.inl"
991# endif
992# ifdef FLECS_PIPELINE
994# endif
995# ifdef FLECS_SNAPSHOT
997# endif
998# ifdef FLECS_SYSTEM
999# include "mixins/system/mixin.inl"
1000# endif
1001# ifdef FLECS_TIMER
1002# include "mixins/timer/mixin.inl"
1003# endif
1004# ifdef FLECS_RULES
1005# include "mixins/rule/mixin.inl"
1006# endif
1007# ifdef FLECS_PLECS
1008# include "mixins/plecs/mixin.inl"
1009# endif
1010# ifdef FLECS_META
1011# include "mixins/meta/world.inl"
1012# endif
1013# ifdef FLECS_JSON
1014# include "mixins/json/world.inl"
1015# endif
1016# ifdef FLECS_APP
1017# include "mixins/app/mixin.inl"
1018# endif
1019# ifdef FLECS_METRICS
1020# include "mixins/metrics/mixin.inl"
1021# endif
1022# ifdef FLECS_ALERTS
1023# include "mixins/alerts/mixin.inl"
1024# endif
1025
1026public:
1027 void init_builtin_components();
1028
1029 world_t *m_world;
1030 bool m_owned;
1031};
1032
1038 flecs::world_t *w,
1039 flecs::entity_t s) : world(nullptr)
1040 {
1041 m_prev_scope = ecs_set_scope(w, s);
1042 m_world = w;
1043 m_owned = false;
1044 }
1045
1046 ~scoped_world() {
1047 ecs_set_scope(m_world, m_prev_scope);
1048 }
1049
1050 scoped_world(const scoped_world& obj) : world(nullptr) {
1051 m_prev_scope = obj.m_prev_scope;
1052 m_world = obj.m_world;
1053 m_owned = obj.m_owned;
1054 }
1055
1056 flecs::entity_t m_prev_scope;
1057};
1058
1061} // 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 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:282
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:291
uint64_t ecs_id_t
An id.
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:473
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_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_set_context(ecs_world_t *world, void *ctx)
Set a world 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_get_context(const ecs_world_t *world)
Get the world context.
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
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:1003
float delta_time
Time passed to or computed by ecs_progress.
Definition flecs.h:1009
float world_time_total
Time elapsed in simulation.
Definition flecs.h:1016
int64_t frame_count_total
Total number of frames.
Definition flecs.h:1020
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Scoped world.
Definition world.hpp:1036
The world.
Definition world.hpp:113
bool is_stage() const
Test if is a stage.
Definition world.hpp:356
void delete_with() const
Delete all entities with specified component.
Definition world.hpp:872
void set_automerge(bool automerge) const
Enable/disable automerging for world or stage.
Definition world.hpp:380
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition world.hpp:883
void merge() const
Merge world or stage.
Definition world.hpp:392
ecs_ftime_t time() const
Get current simulation time.
Definition world.hpp:201
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition world.hpp:861
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:568
ecs_ftime_t delta_time() const
Get last delta_time.
Definition world.hpp:187
void quit() const
Signal application should quit.
Definition world.hpp:209
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition world.hpp:218
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition world.hpp:492
void readonly_end() const
End staging.
Definition world.hpp:286
void with(const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:816
int count() const
Count entities matching a component.
Definition world.hpp:771
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:908
bool should_quit() const
Test if quit() has been called.
Definition world.hpp:221
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition world.hpp:942
void * get_context() const
Get world context.
Definition world.hpp:473
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:181
bool defer_begin() const
Defer operations until end of frame.
Definition world.hpp:296
void reset()
Deletes and recreates the world.
Definition world.hpp:172
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:531
void defer_suspend() const
Suspend deferring operations.
Definition world.hpp:918
void set(const A &value) const
Set singleton pair.
Definition world.hpp:560
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition world.hpp:951
flecs::world async_stage() const
Create asynchronous stage.
Definition world.hpp:431
bool is_deferred() const
Test whether deferring is enabled.
Definition world.hpp:311
world & operator=(const world &obj)=delete
Not allowed to copy a world.
int32_t get_stage_id() const
Get current stage id.
Definition world.hpp:346
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition world.hpp:847
bool readonly_begin() const
Begin staging.
Definition world.hpp:275
void defer_resume() const
Resume deferring operations.
Definition world.hpp:926
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:482
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition world.hpp:327
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition world.hpp:800
void set_context(void *ctx) const
Set world context.
Definition world.hpp:465
world(const world &obj)=delete
Not allowed to copy a world.
int count() const
Count entities matching a pair.
Definition world.hpp:791
void remove_all() const
Remove all instances of specified pair.
Definition world.hpp:900
bool defer_end() const
End block of operations to defer.
Definition world.hpp:305
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:762
world(world_t *w)
Create world from C world.
Definition world.hpp:130
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:443
void atfini(ecs_fini_action_t action, void *ctx) const
Register action to be executed when world is destroyed.
Definition world.hpp:215
flecs::entity ensure(flecs::entity_t e) const
Ensures that entity with provided generation is alive.
Definition world.hpp:225
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition world.hpp:838
void with(const Func &func) const
All entities created in function are created with type.
Definition world.hpp:809
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition world.hpp:888
void modified() const
Mark singleton component as modified.
Definition world.hpp:84
int64_t tick() const
Get current tick.
Definition world.hpp:194
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition world.hpp:781
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition world.hpp:243
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:455
void add() const
Add singleton component.
Definition world.hpp:149
void set(const T &value) const
Set singleton component.
Definition world.hpp:544
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition world.hpp:830
void enable_range_check(bool enabled) const
Enforce that operations cannot modify entities outside of range.
Definition world.hpp:504
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition world.hpp:410
void set(T &&value) const
Set singleton component.
Definition world.hpp:551
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:934
world()
Create world.
Definition world.hpp:116
void frame_end() const
End frame.
Definition world.hpp:253
int32_t get_stage_count() const
Get number of configured stages.
Definition world.hpp:336
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition world.hpp:866
void delete_with() const
Delete all entities with specified pair.
Definition world.hpp:878
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:823
world(int argc, char *argv[])
Create world with command line arguments.
Definition world.hpp:124
int count(flecs::id_t component_id) const
Count entities matching a component.
Definition world.hpp:753
void remove_all() const
Remove all instances of specified component.
Definition world.hpp:894
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:89
uint32_t get_generation(flecs::entity_t e)
Return entity generation.
Definition world.hpp:95