Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
builder_i.hpp
Go to the documentation of this file.
1
6#pragma once
7
9
10namespace flecs
11{
12
17template<typename Base, typename ... Components>
18struct system_builder_i : query_builder_i<Base, Components ...> {
19private:
20 using BaseClass = query_builder_i<Base, Components ...>;
21
22public:
23 system_builder_i(ecs_system_desc_t *desc, int32_t term_index = 0)
24 : BaseClass(&desc->query, term_index)
25 , desc_(desc) { }
26
31 Base& kind(entity_t phase) {
32 desc_->phase = phase;
33 return *this;
34 }
35
40 template <typename E, if_t<is_enum<E>::value> = 0>
41 Base& kind(E phase)
42 {
43 const auto& et = enum_type<E>(this->world_v());
44 flecs::entity_t target = et.entity(phase);
45 return this->kind(target);
46 }
47
52 template <typename Phase>
53 Base& kind() {
54 return this->kind(_::type<Phase>::id(world_v()));
55 }
56
61 Base& multi_threaded(bool value = true) {
62 desc_->multi_threaded = value;
63 return *this;
64 }
65
70 Base& immediate(bool value = true) {
71 desc_->immediate = value;
72 return *this;
73 }
74
83 desc_->interval = interval;
84 return *this;
85 }
86
95 Base& rate(const entity_t tick_source, int32_t rate) {
96 desc_->rate = rate;
97 desc_->tick_source = tick_source;
98 return *this;
99 }
100
108 Base& rate(int32_t rate) {
109 desc_->rate = rate;
110 return *this;
111 }
112
118 template<typename T>
119 Base& tick_source() {
120 desc_->tick_source = _::type<T>::id(world_v());
121 return *this;
122 }
123
130 desc_->tick_source = tick_source;
131 return *this;
132 }
133
135 Base& ctx(void *ptr) {
136 desc_->ctx = ptr;
137 return *this;
138 }
139
141 Base& run(ecs_iter_action_t action) {
142 desc_->run = action;
143 return *this;
144 }
145
146protected:
147 virtual flecs::world_t* world_v() override = 0;
148
149private:
150 operator Base&() {
151 return *static_cast<Base*>(this);
152 }
153
154 ecs_system_desc_t *desc_;
155};
156
157}
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_world_t world_t
World type.
Definition c_types.hpp:18
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:589
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
Query builder interface.
Use with ecs_system_init() and ecs_system_update().
Definition system.h:38
int32_t rate
Rate at which the system should run.
Definition system.h:91
void * ctx
Context to be passed to callback (as ecs_iter_t::param).
Definition system.h:70
ecs_entity_t phase
Optional pipeline phase for the system to run in.
Definition system.h:49
bool multi_threaded
If true, the system will be run on multiple threads.
Definition system.h:97
bool immediate
If true, the system will have access to the actual world.
Definition system.h:101
ecs_ftime_t interval
Interval in seconds at which the system should run.
Definition system.h:88
ecs_run_action_t run
Callback that is invoked when a system is run.
Definition system.h:67
ecs_entity_t tick_source
External tick source that determines when the system ticks.
Definition system.h:94
Query builder interface.
Definition builder_i.hpp:18
System builder interface.
Definition builder_i.hpp:18
Base & kind(entity_t phase)
Specify in which phase the system should run.
Definition builder_i.hpp:31
Base & kind(E phase)
Specify in which phase the system should run, using an enum constant.
Definition builder_i.hpp:41
Base & tick_source(flecs::entity_t tick_source)
Set the tick source.
Base & rate(int32_t rate)
Set the system rate.
Base & immediate(bool value=true)
Specify whether the system should be run in an immediate (non-staged) context.
Definition builder_i.hpp:70
Base & ctx(void *ptr)
Set the system context.
Base & rate(const entity_t tick_source, int32_t rate)
Set the system rate.
Definition builder_i.hpp:95
Base & run(ecs_iter_action_t action)
Set the system run callback.
Base & kind()
Specify in which phase the system should run.
Definition builder_i.hpp:53
Base & interval(ecs_ftime_t interval)
Set the system interval.
Definition builder_i.hpp:82
Base & tick_source()
Set the tick source.
Base & multi_threaded(bool value=true)
Specify whether the system can run on multiple threads.
Definition builder_i.hpp:61
Base & desc()
Use with cascade() to iterate results in descending (bottom-to-top) order.