22 int32_t stage_current,
28 , delta_time_(delta_time)
30 , stage_current_(stage_current)
31 , stage_count_(stage_count) { }
47 stage_ =
stage.c_ptr();
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>;
111 auto ctx = FLECS_NEW(Delegate)(FLECS_FWD(func));
113 desc.
run = Delegate::run;
121 template <
typename Func>
123 using CallbackComponents =
125 return each_callback(CallbackComponents{}, FLECS_FWD(func));
130 template <
typename Func>
132 using CallbackComponents =
134 return run_each_callback(CallbackComponents{}, FLECS_FWD(func));
149 template <
typename Group>
162 int32_t stage_current,
165 void *param =
nullptr)
const
168 world_,
id_, stage_current, stage_count, delta_time, param);
176 template <
typename ... CallbackComponents,
typename Func>
177 system& each_callback(_::arg_list<CallbackComponents...>, Func&& func) {
179 typename std::decay<Func>::type, CallbackComponents...>;
180 auto ctx = FLECS_NEW(Delegate)(FLECS_FWD(func));
189 template <
typename ... CallbackComponents,
typename Func>
190 system& run_each_callback(_::arg_list<CallbackComponents...>, Func&& func) {
191 using Delegate =
typename _::each_delegate<
192 typename std::decay<Func>::type, CallbackComponents...>;
193 auto ctx = FLECS_NEW(Delegate)(FLECS_FWD(func));
195 desc.
run = Delegate::run_each;
208template <
typename... Comps,
typename... Args>
209inline system_builder<Comps...>
world::system(Args &&... args)
const {
221template <
typename ... Components>
222template <
typename Func>
223inline system system_builder<Components...>::each(Func&& func) {
224 if constexpr (
sizeof...(Components) == 0) {
225 using CallbackComponents =
226 typename _::each_callback_args<arg_list_t<Func>>::type;
227 return this->each_callback(CallbackComponents{}, FLECS_FWD(func));
230 return this->run_each(FLECS_FWD(func));
234template <
typename ... Components>
235template <
typename ... CallbackComponents,
typename Func>
236inline system system_builder<Components...>::each_callback(
237 _::arg_list<CallbackComponents...>,
240 this->
template prepend_each_callback_signature<CallbackComponents...>();
242 using Delegate =
typename _::each_delegate<
243 typename std::decay<Func>::type, CallbackComponents...>;
245 auto ctx = FLECS_NEW(Delegate)(FLECS_FWD(func));
246 this->desc_.run = Delegate::run_each;
247 this->desc_.run_ctx = ctx;
248 this->desc_.run_ctx_free = _::free_obj<Delegate>;
249 return system(this->world_, &this->desc_);
252template <
typename ... Components>
253template <
typename ... CallbackComponents>
254inline void system_builder<Components...>::prepend_each_callback_signature() {
255 if constexpr (
sizeof...(Components) == 0 &&
sizeof...(CallbackComponents) != 0) {
256 constexpr int32_t callback_term_count =
257 static_cast<int32_t
>(
sizeof...(CallbackComponents));
262 const int32_t existing_term_count = this->term_index_;
263 this->set_term(
nullptr);
265 for (int32_t i = existing_term_count - 1; i >= 0; i --) {
266 this->desc_.query.terms[i + callback_term_count] =
267 this->desc_.query.terms[i];
270 for (int32_t i = 0; i < callback_term_count; i ++) {
274 this->term_index_ = 0;
275 _::sig<CallbackComponents...>(this->world_).populate(
this);
276 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.
EcsTickSource TickSource
Tick source component.
flecs::system system(flecs::entity e) const
Upcast an entity to a system.
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).
ecs_ctx_free_t run_ctx_free
Callback to free run ctx.
void * callback_ctx
Context associated with callback (for language bindings).
void * run_ctx
Context associated with run (for language bindings).
ecs_iter_action_t callback
Callback that is run for each result returned by the system's query.
ecs_ctx_free_t callback_ctx_free
Callback to free callback ctx.
ecs_run_action_t run
Callback that is invoked when a system is run.
void * ctx
Userdata for the system.
Type that describes a term (single element in a query).
Extract the component argument list from an each-callback signature.
flecs::type type() const
Get the entity's type.
entity()
Default constructor.
Class that wraps around a flecs::id_t.
flecs::world world() const
Get the world.
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(flecs::world_t *world, ecs_system_desc_t *desc)
Construct from a world and a system descriptor.
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.
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.
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.
Timer module system mixin.