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

| 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
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
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
87 Base& interval(ecs_ftime_t interval) {
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}
ecs_add_id
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
ecs_remove_id
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Remove a (component) id from an entity.
EcsDependsOn
const ecs_entity_t EcsDependsOn
Used to express dependency relationships.
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_iter_action_t
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:556
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::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::tick_source
Base & tick_source(flecs::entity_t tick_source)
Set tick source.
Definition builder_i.hpp:134
flecs::system_builder_i::rate
Base & rate(int32_t rate)
Set system rate.
Definition builder_i.hpp:113
flecs::system_builder_i::immediate
Base & immediate(bool value=true)
Specify whether system should be ran in staged context.
Definition builder_i.hpp:75
flecs::system_builder_i::ctx
Base & ctx(void *ptr)
Set system context.
Definition builder_i.hpp:140
flecs::system_builder_i::rate
Base & rate(const entity_t tick_source, int32_t rate)
Set system rate.
Definition builder_i.hpp:100
flecs::system_builder_i::run
Base & run(ecs_iter_action_t action)
Set system run callback.
Definition builder_i.hpp:146
flecs::system_builder_i::kind
Base & kind()
Specify in which phase the system should run.
Definition builder_i.hpp:58
flecs::system_builder_i::interval
Base & interval(ecs_ftime_t interval)
Set system interval.
Definition builder_i.hpp:87
flecs::system_builder_i::tick_source
Base & tick_source()
Set tick source.
Definition builder_i.hpp:124
flecs::system_builder_i::multi_threaded
Base & multi_threaded(bool value=true)
Specify whether system can run on multiple threads.
Definition builder_i.hpp:66