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
716 template <typename T>
717 flecs::entity singleton() const;
718
725 template <typename T>
726 flecs::entity use(const char *alias = nullptr) const;
727
733 flecs::entity use(const char *name, const char *alias = nullptr) const;
734
740 void use(flecs::entity entity, const char *alias = nullptr) const;
741
746 int count(flecs::id_t component_id) const {
747 return ecs_count_id(m_world, component_id);
748 }
749
755 int count(flecs::entity_t first, flecs::entity_t second) const {
756 return ecs_count_id(m_world, ecs_pair(first, second));
757 }
758
763 template <typename T>
764 int count() const {
765 return count(_::cpp_type<T>::id(m_world));
766 }
767
773 template <typename First>
774 int count(flecs::entity_t second) const {
775 return count(_::cpp_type<First>::id(m_world), second);
776 }
777
783 template <typename First, typename Second>
784 int count() const {
785 return count(
786 _::cpp_type<First>::id(m_world),
787 _::cpp_type<Second>::id(m_world));
788 }
789
792 template <typename Func>
793 void with(id_t with_id, const Func& func) const {
794 ecs_id_t prev = ecs_set_with(m_world, with_id);
795 func();
796 ecs_set_with(m_world, prev);
797 }
798
801 template <typename T, typename Func>
802 void with(const Func& func) const {
803 with(this->id<T>(), func);
804 }
805
808 template <typename First, typename Second, typename Func>
809 void with(const Func& func) const {
810 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
811 }
812
815 template <typename First, typename Func>
816 void with(id_t second, const Func& func) const {
817 with(ecs_pair(this->id<First>(), second), func);
818 }
819
822 template <typename Func>
823 void with(id_t first, id_t second, const Func& func) const {
824 with(ecs_pair(first, second), func);
825 }
826
830 template <typename Func>
831 void scope(id_t parent, const Func& func) const {
832 ecs_entity_t prev = ecs_set_scope(m_world, parent);
833 func();
834 ecs_set_scope(m_world, prev);
835 }
836
839 template <typename T, typename Func>
840 void scope(const Func& func) const {
841 flecs::id_t parent = _::cpp_type<T>::id(m_world);
842 scope(parent, func);
843 }
844
848 flecs::scoped_world scope(id_t parent) const;
849
850 template <typename T>
851 flecs::scoped_world scope() const;
852
854 void delete_with(id_t the_id) const {
855 ecs_delete_with(m_world, the_id);
856 }
857
859 void delete_with(entity_t first, entity_t second) const {
860 delete_with(ecs_pair(first, second));
861 }
862
864 template <typename T>
865 void delete_with() const {
867 }
868
870 template <typename First, typename Second>
871 void delete_with() const {
873 }
874
876 void remove_all(id_t the_id) const {
877 ecs_remove_all(m_world, the_id);
878 }
879
881 void remove_all(entity_t first, entity_t second) const {
882 remove_all(ecs_pair(first, second));
883 }
884
886 template <typename T>
887 void remove_all() const {
889 }
890
892 template <typename First, typename Second>
893 void remove_all() const {
895 }
896
900 template <typename Func>
901 void defer(const Func& func) const {
902 ecs_defer_begin(m_world);
903 func();
904 ecs_defer_end(m_world);
905 }
906
911 void defer_suspend() const {
912 ecs_defer_suspend(m_world);
913 }
914
919 void defer_resume() const {
920 ecs_defer_resume(m_world);
921 }
922
927 bool exists(flecs::entity_t e) const {
928 return ecs_exists(m_world, e);
929 }
930
935 bool is_alive(flecs::entity_t e) const {
936 return ecs_is_alive(m_world, e);
937 }
938
944 bool is_valid(flecs::entity_t e) const {
945 return ecs_is_valid(m_world, e);
946 }
947
953 flecs::entity get_alive(flecs::entity_t e) const;
954
955/* Prevent clashing with Unreal define. Unreal applications will have to use
956 * ecs_ensure. */
957#ifndef ensure
964 flecs::entity ensure(flecs::entity_t e) const;
965#endif
966
967 /* Run callback after completing frame */
968 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
969 ecs_run_post_frame(m_world, action, ctx);
970 }
971
972# include "mixins/id/mixin.inl"
974# include "mixins/entity/mixin.inl"
975# include "mixins/event/mixin.inl"
976# include "mixins/term/mixin.inl"
977# include "mixins/filter/mixin.inl"
979# include "mixins/query/mixin.inl"
980# include "mixins/enum/mixin.inl"
981
982# ifdef FLECS_MODULE
983# include "mixins/module/mixin.inl"
984# endif
985# ifdef FLECS_PIPELINE
987# endif
988# ifdef FLECS_SNAPSHOT
990# endif
991# ifdef FLECS_SYSTEM
992# include "mixins/system/mixin.inl"
993# endif
994# ifdef FLECS_TIMER
995# include "mixins/timer/mixin.inl"
996# endif
997# ifdef FLECS_RULES
998# include "mixins/rule/mixin.inl"
999# endif
1000# ifdef FLECS_PLECS
1001# include "mixins/plecs/mixin.inl"
1002# endif
1003# ifdef FLECS_META
1004# include "mixins/meta/world.inl"
1005# endif
1006# ifdef FLECS_JSON
1007# include "mixins/json/world.inl"
1008# endif
1009# ifdef FLECS_APP
1010# include "mixins/app/mixin.inl"
1011# endif
1012# ifdef FLECS_METRICS
1013# include "mixins/metrics/mixin.inl"
1014# endif
1015
1016public:
1017 void init_builtin_components();
1018
1019 world_t *m_world;
1020 bool m_owned;
1021};
1022
1028 flecs::world_t *w,
1029 flecs::entity_t s) : world(nullptr)
1030 {
1031 m_prev_scope = ecs_set_scope(w, s);
1032 m_world = w;
1033 m_owned = false;
1034 }
1035
1036 ~scoped_world() {
1037 ecs_set_scope(m_world, m_prev_scope);
1038 }
1039
1040 scoped_world(const scoped_world& obj) : world(nullptr) {
1041 m_prev_scope = obj.m_prev_scope;
1042 m_world = obj.m_world;
1043 m_owned = obj.m_owned;
1044 }
1045
1046 flecs::entity_t m_prev_scope;
1047};
1048
1051} // 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:277
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition: flecs.h:286
uint64_t ecs_id_t
An id.
Definition: flecs.h:274
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:468
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:998
float delta_time
Time passed to or computed by ecs_progress.
Definition: flecs.h:1004
float world_time_total
Time elapsed in simulation.
Definition: flecs.h:1011
int64_t frame_count_total
Total number of frames.
Definition: flecs.h:1015
Entity.
Definition: entity.hpp:30
Class that wraps around a flecs::id_t.
Definition: decl.hpp:27
Scoped world.
Definition: world.hpp:1026
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:865
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:876
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:854
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:213
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:809
int count() const
Count entities matching a component.
Definition: world.hpp:764
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:901
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:935
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:911
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:944
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:840
bool readonly_begin() const
Begin staging.
Definition: world.hpp:275
void defer_resume() const
Resume deferring operations.
Definition: world.hpp:919
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:793
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:784
void remove_all() const
Remove all instances of specified pair.
Definition: world.hpp:893
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:755
world(world_t *w)
Create world from C world.
Definition: world.hpp:130
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:220
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition: world.hpp:831
void with(const Func &func) const
All entities created in function are created with type.
Definition: world.hpp:802
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition: world.hpp:881
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:774
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:823
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:927
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:859
void delete_with() const
Delete all entities with specified pair.
Definition: world.hpp:871
flecs::entity singleton() const
Get singleton entity for type.
Definition: world.hpp:195
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition: world.hpp:816
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:746
void remove_all() const
Remove all instances of specified component.
Definition: world.hpp:887
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