22 int32_t stage_current,
28 , delta_time_(delta_time)
30 , stage_current_(stage_current)
31 , stage_count_(stage_count) { }
55 stage_, id_, stage_current_, stage_count_, delta_time_,
58 ecs_run(stage_, id_, delta_time_, param_);
69 int32_t stage_current_;
107 template <
typename Func>
110 typename std::decay<Func>::type>;
112 _::set_callback<Delegate, Delegate::run, true>(desc, FLECS_FWD(func));
118 template <
typename Func>
120 using CallbackComponents =
123 _::set_each_callback<false>(desc, FLECS_FWD(func), CallbackComponents{});
130 template <
typename Func>
132 using CallbackComponents =
135 _::set_each_callback<true>(desc, FLECS_FWD(func), CallbackComponents{});
152 template <
typename Group>
165 int32_t stage_current,
168 void *param =
nullptr)
const
171 world_,
id_, stage_current, stage_count, delta_time, param);
185template <
typename... Comps,
typename... Args>
198template <
typename ... Components>
199template <
typename Func>
200inline system system_builder<Components...>::each(Func&& func) {
201 if constexpr (
sizeof...(Components) == 0) {
202 using CallbackComponents =
204 return this->each_callback(CallbackComponents{}, FLECS_FWD(func));
207 return this->run_each(FLECS_FWD(func));
211template <
typename ... Components>
212template <
typename ... CallbackComponents,
typename Func>
213inline system system_builder<Components...>::each_callback(
214 _::arg_list<CallbackComponents...>,
217 this->
template prepend_each_callback_signature<CallbackComponents...>();
219 _::set_each_callback<true>(this->desc_, FLECS_FWD(func),
220 _::arg_list<CallbackComponents...>{});
221 return system(this->world_, &this->desc_);
224template <
typename ... Components>
225template <
typename ... CallbackComponents>
226inline void system_builder<Components...>::prepend_each_callback_signature() {
227 if constexpr (
sizeof...(Components) == 0 &&
sizeof...(CallbackComponents) != 0) {
228 constexpr int32_t callback_term_count =
229 static_cast<int32_t
>(
sizeof...(CallbackComponents));
234 const int32_t existing_term_count = this->term_index_;
235 this->set_term(
nullptr);
237 for (int32_t i = existing_term_count - 1; i >= 0; i --) {
238 this->desc_.query.terms[i + callback_term_count] =
239 this->desc_.query.terms[i];
242 for (int32_t i = 0; i < callback_term_count; i ++) {
246 this->term_index_ = 0;
247 _::populate_signature<CallbackComponents...>(this->world_,
this);
248 this->term_index_ = existing_term_count + callback_term_count;
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
FLECS_API const ecs_system_t * ecs_system_get(const ecs_world_t *world, ecs_entity_t system)
Get a system object.
FLECS_API ecs_entity_t ecs_run(ecs_world_t *world, ecs_entity_t system, ecs_ftime_t delta_time, void *param)
Run a specific system manually.
FLECS_API ecs_entity_t ecs_system_init(ecs_world_t *world, const ecs_system_desc_t *desc)
Create a system.
FLECS_API void ecs_system_set_group(ecs_world_t *world, ecs_entity_t system, uint64_t group_id)
Set query group for system.
FLECS_API ecs_entity_t ecs_system_update(ecs_world_t *world, ecs_entity_t system, const ecs_system_desc_t *desc)
Update an existing system.
FLECS_API ecs_entity_t ecs_run_worker(ecs_world_t *world, ecs_entity_t system, int32_t stage_current, int32_t stage_count, ecs_ftime_t delta_time, void *param)
Same as ecs_run(), but subdivides entities across a number of provided stages.
struct ecs_term_t ecs_term_t
A term is a single element in a query.
flecs::system system(flecs::entity e) const
Upcast an entity to a system.
EcsTickSource TickSource
Tick source component.
flecs::component< T > component(Args &&... args) const
Find or register a component.
ecs_entity_t entity_t
Entity type.
ecs_world_t world_t
World type.
#define ecs_ftime_t
Customizable precision for scalar time values.
#define FLECS_TERM_COUNT_MAX
Maximum number of terms in queries.
Use with ecs_system_init() and ecs_system_update().
void * ctx
Context to be passed to callback (as ecs_iter_t::param).
void * ctx
Userdata for the system.
Extract the component argument list from an each-callback signature.
entity()
Default constructor.
Class that wraps around a flecs::id_t.
flecs::id_t id_
The raw ID value.
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Fluent interface for running a system.
~system_runner_fluent()
Destructor.
system_runner_fluent & stage(flecs::world &stage)
Set the stage for the system runner.
system_runner_fluent & limit(int32_t limit)
Set the limit for the system runner.
system_runner_fluent(world_t *world, entity_t id, int32_t stage_current, int32_t stage_count, ecs_ftime_t delta_time, void *param)
Construct a system runner.
system_runner_fluent & offset(int32_t offset)
Set the offset for the system runner.
system & set_group(uint64_t group_id)
Set the query group.
system & run_each(Func &&func)
Replace the system's run callback and use an each callback for iteration.
system & ctx(void *ctx)
Set the system context.
system(flecs::world_t *world, const ecs_system_desc_t *desc)
Construct from a world and a system descriptor.
flecs::query query() const
Get the query for this system.
system_runner_fluent run(ecs_ftime_t delta_time=0.0f, void *param=nullptr) const
Run the system.
system & each(Func &&func)
Replace the system's each callback.
void * ctx() const
Get the system context.
system & set_group()
Set the query group.
system & run(Func &&func)
Replace the system's run callback.
entity()
Default constructor.
system()
Default constructor.
system_runner_fluent run_worker(int32_t stage_current, int32_t stage_count, ecs_ftime_t delta_time=0.0f, void *param=nullptr) const
Run the system on a specific worker stage.
world_t * world_
Pointer to the underlying C world.
world_t * c_ptr() const
Obtain a pointer to the C world object.
Timer module system mixin.