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_;
118 template <
typename Group>
131 int32_t stage_current,
134 void *param =
nullptr)
const
137 world_,
id_, stage_current, stage_count, delta_time, param);
151template <
typename... Comps,
typename... Args>
152inline system_builder<Comps...>
world::system(Args &&... args)
const {
158template <
typename ArgList>
161template <
typename ... Args>
163 using type = arg_list<remove_reference_t<Args>...>;
166template <
typename ArgList,
typename =
int>
171template <
typename First,
typename ... Args>
173 if_t<is_same<decay_t<First>, flecs::
entity>::value>> {
177template <
typename First,
typename Second,
typename ... Args>
179 if_t<is_same<decay_t<First>, flecs::
iter>::value>> {
189template <
typename ... Components>
190template <
typename Func>
191inline system system_builder<Components...>::each(Func&& func) {
192 if constexpr (
sizeof...(Components) == 0) {
193 using CallbackComponents =
194 typename _::system_each_callback_args<arg_list_t<Func>>::type;
195 return this->each_callback(CallbackComponents{}, FLECS_FWD(func));
198 return this->run_each(FLECS_FWD(func));
202template <
typename ... Components>
203template <
typename ... CallbackComponents,
typename Func>
204inline system system_builder<Components...>::each_callback(
205 _::arg_list<CallbackComponents...>,
208 this->
template prepend_each_callback_signature<CallbackComponents...>();
210 using Delegate =
typename _::each_delegate<
211 typename std::decay<Func>::type, CallbackComponents...>;
213 auto ctx = FLECS_NEW(Delegate)(FLECS_FWD(func));
214 this->desc_.run = Delegate::run_each;
215 this->desc_.run_ctx = ctx;
216 this->desc_.run_ctx_free = _::free_obj<Delegate>;
217 return system(this->world_, &this->desc_);
220template <
typename ... Components>
221template <
typename ... CallbackComponents>
222inline void system_builder<Components...>::prepend_each_callback_signature() {
223 if constexpr (
sizeof...(Components) == 0 &&
sizeof...(CallbackComponents) != 0) {
224 constexpr int32_t callback_term_count =
225 static_cast<int32_t
>(
sizeof...(CallbackComponents));
230 const int32_t existing_term_count = this->term_index_;
231 this->set_term(
nullptr);
233 for (int32_t i = existing_term_count - 1; i >= 0; i --) {
234 this->desc_.query.terms[i + callback_term_count] =
235 this->desc_.query.terms[i];
238 for (int32_t i = 0; i < callback_term_count; i ++) {
242 this->term_index_ = 0;
243 _::sig<CallbackComponents...>(this->world_).populate(
this);
244 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_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.
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.
Component used to provide a tick source to systems.
Use with ecs_system_init() to create or update a system.
void * ctx
Context to be passed to callback (as ecs_iter_t::param).
ecs_entity_t entity
Existing entity to associate with the system (optional).
void * ctx
Userdata for the system.
Type that describes a term (single element in a query).
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.
Class for iterating over query results.
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.
void 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.
void * ctx() const
Get the system context.
system & set_group()
Set the query group.
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.
enable_if_t< V, int > if_t
Convenience enable_if alias using int as default type.