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
8#include "../query/builder_i.hpp"
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
49 template <typename Phase>
50 Base& kind() {
51 return this->kind(_::cpp_type<Phase>::id(world_v()));
52 }
53
58 Base& multi_threaded(bool value = true) {
59 m_desc->multi_threaded = value;
60 return *this;
61 }
62
67 Base& no_readonly(bool value = true) {
68 m_desc->no_readonly = value;
69 return *this;
70 }
71
80 m_desc->interval = interval;
81 return *this;
82 }
83
92 Base& rate(const entity_t tick_source, int32_t rate) {
93 m_desc->rate = rate;
94 m_desc->tick_source = tick_source;
95 return *this;
96 }
97
105 Base& rate(int32_t rate) {
106 m_desc->rate = rate;
107 return *this;
108 }
109
115 Base& tick_source(flecs::entity_t tick_source) {
116 m_desc->tick_source = tick_source;
117 return *this;
118 }
119
121 Base& ctx(void *ptr) {
122 m_desc->ctx = ptr;
123 return *this;
124 }
125
127 Base& run(ecs_iter_action_t action) {
128 m_desc->run = action;
129 return *this;
130 }
131
132protected:
133 virtual flecs::world_t* world_v() = 0;
134
135private:
136 operator Base&() {
137 return *static_cast<Base*>(this);
138 }
139
140 ecs_system_desc_t *m_desc;
141};
142
145}
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:387
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition: flecs.h:42
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 actuall 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 soutce 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.
Definition: builder_i.hpp:115
Base & rate(int32_t rate)
Set system rate.
Definition: builder_i.hpp:105
Base & ctx(void *ptr)
Set system context.
Definition: builder_i.hpp:121
Base & rate(const entity_t tick_source, int32_t rate)
Set system rate.
Definition: builder_i.hpp:92
Base & run(ecs_iter_action_t action)
Set system run callback.
Definition: builder_i.hpp:127
Base & no_readonly(bool value=true)
Specify whether system should be ran in staged context.
Definition: builder_i.hpp:67
Base & kind()
Specify in which phase the system should run.
Definition: builder_i.hpp:50
Base & interval(ecs_ftime_t interval)
Set system interval.
Definition: builder_i.hpp:79
Base & multi_threaded(bool value=true)
Specify whether system can run on multiple threads.
Definition: builder_i.hpp:58
ecs_ftime_t interval()
Get interval.