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:
24 : BaseClass(&desc->query)
25 , desc_(desc) { }
26
31 Base& kind(entity_t phase) {
33 world_v(), desc_->entity, EcsDependsOn, 0);
34 if (cur_phase) {
35 ecs_remove_id(world_v(), desc_->entity, ecs_dependson(cur_phase));
36 ecs_remove_id(world_v(), desc_->entity, cur_phase);
37 }
38 if (phase) {
39 ecs_add_id(world_v(), desc_->entity, ecs_dependson(phase));
40 ecs_add_id(world_v(), desc_->entity, phase);
41 }
42 return *this;
43 }
44
49 template <typename E, if_t<is_enum<E>::value> = 0>
50 Base& kind(E phase)
51 {
52 const auto& et = enum_type<E>(this->world_v());
53 flecs::entity_t target = et.entity(phase);
54 return this->kind(target);
55 }
56
61 template <typename Phase>
62 Base& kind() {
63 return this->kind(_::type<Phase>::id(world_v()));
64 }
65
70 Base& multi_threaded(bool value = true) {
71 desc_->multi_threaded = value;
72 return *this;
73 }
74
79 Base& immediate(bool value = true) {
80 desc_->immediate = value;
81 return *this;
82 }
83
92 desc_->interval = interval;
93 return *this;
94 }
95
104 Base& rate(const entity_t tick_source, int32_t rate) {
105 desc_->rate = rate;
106 desc_->tick_source = tick_source;
107 return *this;
108 }
109
117 Base& rate(int32_t rate) {
118 desc_->rate = rate;
119 return *this;
120 }
121
127 template<typename T>
128 Base& tick_source() {
129 desc_->tick_source = _::type<T>::id(world_v());
130 return *this;
131 }
132
139 desc_->tick_source = tick_source;
140 return *this;
141 }
142
144 Base& ctx(void *ptr) {
145 desc_->ctx = ptr;
146 return *this;
147 }
148
150 Base& run(ecs_iter_action_t action) {
151 desc_->run = action;
152 return *this;
153 }
154
155protected:
156 virtual flecs::world_t* world_v() override = 0;
157
158private:
159 operator Base&() {
160 return *static_cast<Base*>(this);
161 }
162
163 ecs_system_desc_t *desc_;
164};
165
166}
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Remove a component from an entity.
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
const ecs_entity_t EcsDependsOn
Used to express dependency relationships.
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_world_t world_t
World type.
Definition c_types.hpp:18
ecs_entity_t ecs_get_target(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, int32_t index)
Get the target of a relationship.
#define ecs_dependson(e)
Construct a DependsOn pair.
Definition flecs_c.h:926
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:577
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
Query builder interface.
Use with ecs_system_init() to create or update a system.
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
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_entity_t entity
Existing entity to associate with the system (optional).
Definition system.h:42
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:50
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:79
Base & ctx(void *ptr)
Set the system context.
Base & rate(const entity_t tick_source, int32_t rate)
Set the system rate.
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:62
Base & interval(ecs_ftime_t interval)
Set the system interval.
Definition builder_i.hpp:91
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:70
Base & desc()
Use with cascade() to iterate results in descending (bottom-to-top) order.