Flecs: include/flecs/addons/cpp/mixins/system/builder_i.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| 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
5
6#pragma once
7
8#include "../query/builder_i.hpp"
9
10namespace flecs
11{
12
17template<typename Base, typename ... Components>
18 struct 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)
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
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
91 Base& interval(ecs_ftime_t interval) {
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
138 Base& tick_source(flecs::entity_t tick_source) {
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}
ecs_remove_id
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Remove a component from an entity.
ecs_add_id
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
EcsDependsOn
const ecs_entity_t EcsDependsOn
Used to express dependency relationships.
flecs::entity_t
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
ecs_get_target
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.
ecs_dependson
#define ecs_dependson(e)
Construct a DependsOn pair.
Definition flecs_c.h:926
ecs_iter_action_t
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:577
ecs_ftime_t
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
builder_i.hpp
Query builder interface.
ecs_system_desc_t
Use with ecs_system_init() to create or update a system.
Definition system.h:38
flecs::_::type
Definition flecs.hpp:39
flecs::query_builder_i< Base, Components ... >::query_builder_i
query_builder_i(ecs_query_desc_t *desc, int32_t term_index=0)
Definition builder_i.hpp:20
flecs::system_builder_i::kind
Base & kind(entity_t phase)
Specify in which phase the system should run.
Definition builder_i.hpp:31
flecs::system_builder_i::kind
Base & kind(E phase)
Specify in which phase the system should run, using an enum constant.
Definition builder_i.hpp:50
flecs::system_builder_i::tick_source
Base & tick_source(flecs::entity_t tick_source)
Set the tick source.
Definition builder_i.hpp:138
flecs::system_builder_i::rate
Base & rate(int32_t rate)
Set the system rate.
Definition builder_i.hpp:117
flecs::system_builder_i::immediate
Base & immediate(bool value=true)
Specify whether the system should be run in an immediate (non-staged) context.
Definition builder_i.hpp:79
flecs::system_builder_i::ctx
Base & ctx(void *ptr)
Set the system context.
Definition builder_i.hpp:144
flecs::system_builder_i::rate
Base & rate(const entity_t tick_source, int32_t rate)
Set the system rate.
Definition builder_i.hpp:104
flecs::system_builder_i::run
Base & run(ecs_iter_action_t action)
Set the system run callback.
Definition builder_i.hpp:150
flecs::system_builder_i::kind
Base & kind()
Specify in which phase the system should run.
Definition builder_i.hpp:62
flecs::system_builder_i::interval
Base & interval(ecs_ftime_t interval)
Set the system interval.
Definition builder_i.hpp:91
flecs::system_builder_i::tick_source
Base & tick_source()
Set the tick source.
Definition builder_i.hpp:128
flecs::system_builder_i::multi_threaded
Base & multi_threaded(bool value=true)
Specify whether the system can run on multiple threads.
Definition builder_i.hpp:70
flecs::term_builder_i::desc
Base & desc()
Use with cascade() to iterate results in descending (bottom-to-top) order.
Definition builder_i.hpp:264