Flecs v3.1
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
173 world_t* c_ptr() const {
174 return m_world;
175 }
176
180 const ecs_world_info_t *stats = ecs_get_world_info(m_world);
181 return stats->delta_time;
182 }
183
186 int64_t tick() const {
187 const ecs_world_info_t *stats = ecs_get_world_info(m_world);
188 return stats->frame_count_total;
189 }
190
194 const ecs_world_info_t *stats = ecs_get_world_info(m_world);
195 return stats->world_time_total;
196 }
197
201 void quit() const {
202 ecs_quit(m_world);
203 }
204
207 void atfini(ecs_fini_action_t action, void *ctx) const {
208 ecs_atfini(m_world, action, ctx);
209 }
210
213 bool should_quit() const {
214 return ecs_should_quit(m_world);
215 }
216
236 return ecs_frame_begin(m_world, delta_time);
237 }
238
245 void frame_end() const {
246 ecs_frame_end(m_world);
247 }
248
267 bool readonly_begin() const {
268 return ecs_readonly_begin(m_world);
269 }
270
278 void readonly_end() const {
279 ecs_readonly_end(m_world);
280 }
281
288 bool defer_begin() const {
289 return ecs_defer_begin(m_world);
290 }
291
297 bool defer_end() const {
298 return ecs_defer_end(m_world);
299 }
300
303 bool is_deferred() const {
304 return ecs_is_deferred(m_world);
305 }
306
319 void set_stage_count(int32_t stages) const {
320 ecs_set_stage_count(m_world, stages);
321 }
322
328 int32_t get_stage_count() const {
329 return ecs_get_stage_count(m_world);
330 }
331
338 int32_t get_stage_id() const {
339 return ecs_get_stage_id(m_world);
340 }
341
348 bool is_stage() const {
350 ecs_poly_is(m_world, ecs_world_t) ||
351 ecs_poly_is(m_world, ecs_stage_t),
352 ECS_INVALID_PARAMETER, NULL);
353 return ecs_poly_is(m_world, ecs_stage_t);
354 }
355
372 void set_automerge(bool automerge) const {
373 ecs_set_automerge(m_world, automerge);
374 }
375
384 void merge() const {
385 ecs_merge(m_world);
386 }
387
402 flecs::world get_stage(int32_t stage_id) const {
403 return flecs::world(ecs_get_stage(m_world, stage_id));
404 }
405
424 auto result = flecs::world(ecs_async_stage_new(m_world));
425 result.m_owned = true;
426 return result;
427 }
428
436 /* Safe cast, mutability is checked */
437 return flecs::world(
438 m_world ? const_cast<flecs::world_t*>(ecs_get_world(m_world)) : nullptr);
439 }
440
447 bool is_readonly() const {
448 return ecs_stage_is_readonly(m_world);
449 }
450
457 void set_context(void* ctx) const {
458 ecs_set_context(m_world, ctx);
459 }
460
465 void* get_context() const {
466 return ecs_get_context(m_world);
467 }
468
474 void dim(int32_t entity_count) const {
475 ecs_dim(m_world, entity_count);
476 }
477
484 void set_entity_range(entity_t min, entity_t max) const {
485 ecs_set_entity_range(m_world, min, max);
486 }
487
496 void enable_range_check(bool enabled) const {
497 ecs_enable_range_check(m_world, enabled);
498 }
499
506 flecs::entity set_scope(const flecs::entity_t scope) const;
507
513 flecs::entity get_scope() const;
514
518 template <typename T>
519 flecs::entity set_scope() const;
520
523 flecs::entity_t* set_lookup_path(const flecs::entity_t *search_path) const {
524 return ecs_set_lookup_path(m_world, search_path);
525 }
526
531 flecs::entity lookup(const char *name) const;
532
535 template <typename T, if_t< !is_callable<T>::value > = 0>
536 void set(const T& value) const {
537 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world), value);
538 }
539
540 template <typename T, if_t< !is_callable<T>::value > = 0>
541 void set(T&& value) const {
542 flecs::set<T>(m_world, _::cpp_type<T>::id(m_world),
543 FLECS_FWD(value));
544 }
545
548 template <typename Func, if_t< is_callable<Func>::value > = 0 >
549 void set(const Func& func) const;
550
551 template <typename T, typename ... Args>
552 void emplace(Args&&... args) const {
553 flecs::id_t component_id = _::cpp_type<T>::id(m_world);
554 flecs::emplace<T>(m_world, component_id, component_id,
555 FLECS_FWD(args)...);
556 }
557
560 template <typename T>
561 T* get_mut() const;
562
565 template <typename T>
566 void modified() const;
567
570 template <typename T>
571 ref<T> get_ref() const;
572
575 template <typename T>
576 const T* get() const;
577
580 template <typename Func, if_t< is_callable<Func>::value > = 0 >
581 void get(const Func& func) const;
582
585 template <typename T>
586 bool has() const;
587
593 template <typename First, typename Second>
594 bool has() const;
595
601 template <typename First>
602 bool has(flecs::id_t second) const;
603
609 bool has(flecs::id_t first, flecs::id_t second) const;
610
613 template <typename T>
614 void add() const;
615
621 template <typename First, typename Second>
622 void add() const;
623
629 template <typename First>
630 void add(flecs::entity_t second) const;
631
637 void add(flecs::entity_t first, flecs::entity_t second) const;
638
641 template <typename T>
642 void remove() const;
643
646 template <typename T>
647 flecs::entity singleton() const;
648
655 template <typename T>
656 flecs::entity use(const char *alias = nullptr) const;
657
663 flecs::entity use(const char *name, const char *alias = nullptr) const;
664
670 void use(flecs::entity entity, const char *alias = nullptr) const;
671
676 int count(flecs::id_t component_id) const {
677 return ecs_count_id(m_world, component_id);
678 }
679
685 int count(flecs::entity_t first, flecs::entity_t second) const {
686 return ecs_count_id(m_world, ecs_pair(first, second));
687 }
688
693 template <typename T>
694 int count() const {
695 return count(_::cpp_type<T>::id(m_world));
696 }
697
703 template <typename First>
704 int count(flecs::entity_t second) const {
705 return count(_::cpp_type<First>::id(m_world), second);
706 }
707
713 template <typename First, typename Second>
714 int count() const {
715 return count(
716 _::cpp_type<First>::id(m_world),
717 _::cpp_type<Second>::id(m_world));
718 }
719
722 template <typename Func>
723 void with(id_t with_id, const Func& func) const {
724 ecs_id_t prev = ecs_set_with(m_world, with_id);
725 func();
726 ecs_set_with(m_world, prev);
727 }
728
731 template <typename T, typename Func>
732 void with(const Func& func) const {
733 with(this->id<T>(), func);
734 }
735
738 template <typename First, typename Second, typename Func>
739 void with(const Func& func) const {
740 with(ecs_pair(this->id<First>(), this->id<Second>()), func);
741 }
742
745 template <typename First, typename Func>
746 void with(id_t second, const Func& func) const {
747 with(ecs_pair(this->id<First>(), second), func);
748 }
749
752 template <typename Func>
753 void with(id_t first, id_t second, const Func& func) const {
754 with(ecs_pair(first, second), func);
755 }
756
760 template <typename Func>
761 void scope(id_t parent, const Func& func) const {
762 ecs_entity_t prev = ecs_set_scope(m_world, parent);
763 func();
764 ecs_set_scope(m_world, prev);
765 }
766
769 template <typename T, typename Func>
770 void scope(const Func& func) const {
771 flecs::id_t parent = _::cpp_type<T>::id(m_world);
772 scope(parent, func);
773 }
774
778 flecs::scoped_world scope(id_t parent) const;
779
780 template <typename T>
781 flecs::scoped_world scope() const;
782
784 void delete_with(id_t the_id) const {
785 ecs_delete_with(m_world, the_id);
786 }
787
789 void delete_with(entity_t first, entity_t second) const {
790 delete_with(ecs_pair(first, second));
791 }
792
794 template <typename T>
795 void delete_with() const {
797 }
798
800 template <typename First, typename Second>
801 void delete_with() const {
803 }
804
806 void remove_all(id_t the_id) const {
807 ecs_remove_all(m_world, the_id);
808 }
809
811 void remove_all(entity_t first, entity_t second) const {
812 remove_all(ecs_pair(first, second));
813 }
814
816 template <typename T>
817 void remove_all() const {
819 }
820
822 template <typename First, typename Second>
823 void remove_all() const {
825 }
826
830 template <typename Func>
831 void defer(const Func& func) const {
832 ecs_defer_begin(m_world);
833 func();
834 ecs_defer_end(m_world);
835 }
836
841 void defer_suspend() const {
842 ecs_defer_suspend(m_world);
843 }
844
849 void defer_resume() const {
850 ecs_defer_resume(m_world);
851 }
852
857 bool exists(flecs::entity_t e) const {
858 return ecs_exists(m_world, e);
859 }
860
865 bool is_alive(flecs::entity_t e) const {
866 return ecs_is_alive(m_world, e);
867 }
868
874 bool is_valid(flecs::entity_t e) const {
875 return ecs_is_valid(m_world, e);
876 }
877
883 flecs::entity get_alive(flecs::entity_t e) const;
884
885/* Prevent clashing with Unreal define. Unreal applications will have to use
886 * ecs_ensure. */
887#ifndef ensure
894 flecs::entity ensure(flecs::entity_t e) const;
895#endif
896
897 /* Run callback after completing frame */
898 void run_post_frame(ecs_fini_action_t action, void *ctx) const {
899 ecs_run_post_frame(m_world, action, ctx);
900 }
901
902# include "mixins/id/mixin.inl"
904# include "mixins/entity/mixin.inl"
905# include "mixins/event/mixin.inl"
906# include "mixins/term/mixin.inl"
907# include "mixins/filter/mixin.inl"
909# include "mixins/query/mixin.inl"
910# include "mixins/enum/mixin.inl"
911
912# ifdef FLECS_MODULE
913# include "mixins/module/mixin.inl"
914# endif
915# ifdef FLECS_PIPELINE
917# endif
918# ifdef FLECS_SNAPSHOT
920# endif
921# ifdef FLECS_SYSTEM
922# include "mixins/system/mixin.inl"
923# endif
924# ifdef FLECS_TIMER
925# include "mixins/timer/mixin.inl"
926# endif
927# ifdef FLECS_RULES
928# include "mixins/rule/mixin.inl"
929# endif
930# ifdef FLECS_PLECS
931# include "mixins/plecs/mixin.inl"
932# endif
933# ifdef FLECS_META
934# include "mixins/meta/world.inl"
935# endif
936# ifdef FLECS_JSON
937# include "mixins/json/world.inl"
938# endif
939# ifdef FLECS_APP
940# include "mixins/app/mixin.inl"
941# endif
942
943public:
944 void init_builtin_components();
945
946 world_t *m_world;
947 bool m_owned;
948};
949
955 flecs::world_t *w,
956 flecs::entity_t s) : world(nullptr)
957 {
958 m_prev_scope = ecs_set_scope(w, s);
959 m_world = w;
960 m_owned = false;
961 }
962
963 ~scoped_world() {
964 ecs_set_scope(m_world, m_prev_scope);
965 }
966
967 scoped_world(const scoped_world& obj) : world(nullptr) {
968 m_prev_scope = obj.m_prev_scope;
969 m_world = obj.m_world;
970 m_owned = obj.m_owned;
971 }
972
973 flecs::entity_t m_prev_scope;
974};
975
978} // 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:219
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition: flecs.h:228
uint64_t ecs_id_t
An id.
Definition: flecs.h:216
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:410
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:939
float delta_time
Time passed to or computed by ecs_progress.
Definition: flecs.h:946
float world_time_total
Time elapsed in simulation.
Definition: flecs.h:953
int64_t frame_count_total
Total number of frames.
Definition: flecs.h:957
Entity.
Definition: entity.hpp:30
Class that wraps around a flecs::id_t.
Definition: decl.hpp:27
Scoped world.
Definition: world.hpp:953
The world.
Definition: world.hpp:113
bool is_stage() const
Test if is a stage.
Definition: world.hpp:348
void delete_with() const
Delete all entities with specified component.
Definition: world.hpp:795
void set_automerge(bool automerge) const
Enable/disable automerging for world or stage.
Definition: world.hpp:372
void remove_all(id_t the_id) const
Remove all instances of specified id.
Definition: world.hpp:806
void merge() const
Merge world or stage.
Definition: world.hpp:384
ecs_ftime_t time() const
Get current simulation time.
Definition: world.hpp:193
void delete_with(id_t the_id) const
Delete all entities with specified id.
Definition: world.hpp:784
flecs::entity get_scope() const
Get current scope.
Definition: world.hpp:67
T * get_mut() const
Get mut singleton component.
Definition: world.hpp:82
void remove() const
Remove singleton component.
Definition: world.hpp:152
ecs_ftime_t delta_time() const
Get last delta_time.
Definition: world.hpp:179
void quit() const
Signal application should quit.
Definition: world.hpp:201
flecs::entity get_alive(flecs::entity_t e) const
Get alive entity for id.
Definition: world.hpp:176
void set_entity_range(entity_t min, entity_t max) const
Set entity range.
Definition: world.hpp:484
void readonly_end() const
End staging.
Definition: world.hpp:278
void with(const Func &func) const
All entities created in function are created with pair.
Definition: world.hpp:739
int count() const
Count entities matching a component.
Definition: world.hpp:694
const T * get() const
Get singleton component.
Definition: world.hpp:100
void defer(const Func &func) const
Defer all operations called in function.
Definition: world.hpp:831
bool should_quit() const
Test if quit() has been called.
Definition: world.hpp:213
bool is_alive(flecs::entity_t e) const
Check if entity id exists in the world.
Definition: world.hpp:865
void * get_context() const
Get world context.
Definition: world.hpp:465
world_t * c_ptr() const
Obtain pointer to C world object.
Definition: world.hpp:173
bool defer_begin() const
Defer operations until end of frame.
Definition: world.hpp:288
flecs::entity lookup(const char *name) const
Lookup entity by name.
Definition: world.hpp:76
flecs::entity_t * set_lookup_path(const flecs::entity_t *search_path) const
Set search path.
Definition: world.hpp:523
void defer_suspend() const
Suspend deferring operations.
Definition: world.hpp:841
bool is_valid(flecs::entity_t e) const
Check if entity id is valid.
Definition: world.hpp:874
flecs::world async_stage() const
Create asynchronous stage.
Definition: world.hpp:423
bool is_deferred() const
Test whether deferring is enabled.
Definition: world.hpp:303
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:338
void scope(const Func &func) const
Same as scope(parent, func), but with T as parent.
Definition: world.hpp:770
bool readonly_begin() const
Begin staging.
Definition: world.hpp:267
void defer_resume() const
Resume deferring operations.
Definition: world.hpp:849
flecs::entity set_scope() const
Same as set_scope but with type.
Definition: world.hpp:72
void dim(int32_t entity_count) const
Preallocate memory for number of entities.
Definition: world.hpp:474
void set_stage_count(int32_t stages) const
Configure world to have N stages.
Definition: world.hpp:319
void with(id_t with_id, const Func &func) const
All entities created in function are created with id.
Definition: world.hpp:723
void set_context(void *ctx) const
Set world context.
Definition: world.hpp:457
world(const world &obj)=delete
Not allowed to copy a world.
int count() const
Count entities matching a pair.
Definition: world.hpp:714
void remove_all() const
Remove all instances of specified pair.
Definition: world.hpp:823
bool defer_end() const
End block of operations to defer.
Definition: world.hpp:297
int count(flecs::entity_t first, flecs::entity_t second) const
Count entities matching a pair.
Definition: world.hpp:685
world(world_t *w)
Create world from C world.
Definition: world.hpp:130
flecs::world get_world() const
Get actual world.
Definition: world.hpp:435
void atfini(ecs_fini_action_t action, void *ctx) const
Register action to be executed when world is destroyed.
Definition: world.hpp:207
flecs::entity ensure(flecs::entity_t e) const
Ensures that entity with provided generation is alive.
Definition: world.hpp:183
void scope(id_t parent, const Func &func) const
All entities created in function are created in scope.
Definition: world.hpp:761
void with(const Func &func) const
All entities created in function are created with type.
Definition: world.hpp:732
void remove_all(entity_t first, entity_t second) const
Remove all instances of specified pair.
Definition: world.hpp:811
void modified() const
Mark singleton component as modified.
Definition: world.hpp:88
int64_t tick() const
Get current tick.
Definition: world.hpp:186
int count(flecs::entity_t second) const
Count entities matching a pair.
Definition: world.hpp:704
ecs_ftime_t frame_begin(float delta_time=0) const
Begin frame.
Definition: world.hpp:235
flecs::entity use(const char *alias=nullptr) const
Create alias for component.
Definition: world.hpp:34
bool is_readonly() const
Test whether the current world object is readonly.
Definition: world.hpp:447
void add() const
Add singleton component.
Definition: world.hpp:129
void set(const T &value) const
Set singleton component.
Definition: world.hpp:536
void with(id_t first, id_t second, const Func &func) const
All entities created in function are created with pair.
Definition: world.hpp:753
void enable_range_check(bool enabled) const
Enforce that operations cannot modify entities outside of range.
Definition: world.hpp:496
flecs::world get_stage(int32_t stage_id) const
Get stage-specific world pointer.
Definition: world.hpp:402
bool has() const
Test if world has singleton component.
Definition: world.hpp:106
bool exists(flecs::entity_t e) const
Check if entity id exists in the world.
Definition: world.hpp:857
world()
Create world.
Definition: world.hpp:116
void frame_end() const
End frame.
Definition: world.hpp:245
int32_t get_stage_count() const
Get number of configured stages.
Definition: world.hpp:328
void delete_with(entity_t first, entity_t second) const
Delete all entities with specified pair.
Definition: world.hpp:789
void delete_with() const
Delete all entities with specified pair.
Definition: world.hpp:801
flecs::entity singleton() const
Get singleton entity for type.
Definition: world.hpp:158
void with(id_t second, const Func &func) const
All entities created in function are created with pair.
Definition: world.hpp:746
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:676
void remove_all() const
Remove all instances of specified component.
Definition: world.hpp:817
ref< T > get_ref() const
Get ref singleton component.
Definition: world.hpp:94
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