Flecs v4.0
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) {
32 flecs::entity_t cur_phase = ecs_get_target(
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
45 template <typename E, if_t<is_enum<E>::value> = 0>
46 Base& kind(E phase)
47 {
48 const auto& et = enum_type<E>(this->world_v());
49 flecs::entity_t target = et.entity(phase);
50 return this->kind(target);
51 }
52
57 template <typename Phase>
58 Base& kind() {
59 return this->kind(_::type<Phase>::id(world_v()));
60 }
61
66 Base& multi_threaded(bool value = true) {
67 desc_->multi_threaded = value;
68 return *this;
69 }
70
75 Base& immediate(bool value = true) {
76 desc_->immediate = value;
77 return *this;
78 }
79
88 desc_->interval = interval;
89 return *this;
90 }
91
100 Base& rate(const entity_t tick_source, int32_t rate) {
101 desc_->rate = rate;
102 desc_->tick_source = tick_source;
103 return *this;
104 }
105
113 Base& rate(int32_t rate) {
114 desc_->rate = rate;
115 return *this;
116 }
117
123 template<typename T>
124 Base& tick_source() {
125 desc_->tick_source = _::type<T>::id(world_v());
126 return *this;
127 }
128
134 Base& tick_source(flecs::entity_t tick_source) {
135 desc_->tick_source = tick_source;
136 return *this;
137 }
138
140 Base& ctx(void *ptr) {
141 desc_->ctx = ptr;
142 return *this;
143 }
144
146 Base& run(ecs_iter_action_t action) {
147 desc_->run = action;
148 return *this;
149 }
150
151protected:
152 virtual flecs::world_t* world_v() override = 0;
153
154private:
155 operator Base&() {
156 return *static_cast<Base*>(this);
157 }
158
159 ecs_system_desc_t *desc_;
160};
161
162}
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Remove a (component) id from an entity.
const ecs_entity_t EcsDependsOn
Used to express dependency relationships.
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.
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:546
#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:87
void * ctx
Context to be passed to callback (as ecs_iter_t::param)
Definition system.h:66
bool multi_threaded
If true, system will be ran on multiple threads.
Definition system.h:93
bool immediate
If true, system will have access to the actual world.
Definition system.h:97
ecs_ftime_t interval
Interval in seconds at which the system should run.
Definition system.h:84
ecs_entity_t entity
Existing entity to associate with system (optional)
Definition system.h:42
ecs_query_desc_t query
System query parameters.
Definition system.h:45
ecs_run_action_t run
Callback that is invoked when a system is ran.
Definition system.h:63
ecs_entity_t tick_source
External tick source that determines when system ticks.
Definition system.h:90
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 & tick_source(flecs::entity_t tick_source)
Set tick source.
Base & rate(int32_t rate)
Set system rate.
Base & immediate(bool value=true)
Specify whether system should be ran in staged context.
Definition builder_i.hpp:75
Base & ctx(void *ptr)
Set system context.
Base & rate(const entity_t tick_source, int32_t rate)
Set system rate.
Base & run(ecs_iter_action_t action)
Set system run callback.
Base & kind()
Specify in which phase the system should run.
Definition builder_i.hpp:58
Base & interval(ecs_ftime_t interval)
Set system interval.
Definition builder_i.hpp:87
Base & tick_source()
Set tick source.
Base & multi_threaded(bool value=true)
Specify whether system can run on multiple threads.
Definition builder_i.hpp:66