Flecs v3.2
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 , m_desc(desc) { }
26
31 Base& kind(entity_t phase) {
32 flecs::entity_t cur_phase = ecs_get_target(
33 world_v(), m_desc->entity, EcsDependsOn, 0);
34 if (cur_phase) {
35 ecs_remove_id(world_v(), m_desc->entity, ecs_dependson(cur_phase));
36 ecs_remove_id(world_v(), m_desc->entity, cur_phase);
37 }
38 if (phase) {
39 ecs_add_id(world_v(), m_desc->entity, ecs_dependson(phase));
40 ecs_add_id(world_v(), m_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(_::cpp_type<Phase>::id(world_v()));
60 }
61
66 Base& multi_threaded(bool value = true) {
67 m_desc->multi_threaded = value;
68 return *this;
69 }
70
75 Base& no_readonly(bool value = true) {
76 m_desc->no_readonly = value;
77 return *this;
78 }
79
88 m_desc->interval = interval;
89 return *this;
90 }
91
100 Base& rate(const entity_t tick_source, int32_t rate) {
101 m_desc->rate = rate;
102 m_desc->tick_source = tick_source;
103 return *this;
104 }
105
113 Base& rate(int32_t rate) {
114 m_desc->rate = rate;
115 return *this;
116 }
117
123 template<typename T>
124 Base& tick_source() {
125 m_desc->tick_source = _::cpp_type<T>::id(world_v());
126 return *this;
127 }
128
134 Base& tick_source(flecs::entity_t tick_source) {
135 m_desc->tick_source = tick_source;
136 return *this;
137 }
138
140 Base& ctx(void *ptr) {
141 m_desc->ctx = ptr;
142 return *this;
143 }
144
146 Base& run(ecs_iter_action_t action) {
147 m_desc->run = action;
148 return *this;
149 }
150
151protected:
152 virtual flecs::world_t* world_v() = 0;
153
154private:
155 operator Base&() {
156 return *static_cast<Base*>(this);
157 }
158
159 ecs_system_desc_t *m_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:527
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:43
Query builder interface.
Use with ecs_system_init()
Definition system.h:38
int32_t rate
Rate at which the system should run.
Definition system.h:82
void * ctx
Context to be passed to callback (as ecs_iter_t::param)
Definition system.h:67
bool multi_threaded
If true, system will be ran on multiple threads.
Definition system.h:88
bool no_readonly
If true, system will have access to the actual world.
Definition system.h:92
ecs_ftime_t interval
Interval in seconds at which the system should run.
Definition system.h:79
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:59
ecs_entity_t tick_source
External tick source that determines when system ticks.
Definition system.h:85
Query builder interface.
Definition builder_i.hpp:17
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 & 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 & no_readonly(bool value=true)
Specify whether system should be ran in staged context.
Definition builder_i.hpp:75
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