8template <
typename ... Components>
11template <
typename ... Components>
14template <
typename ... Components>
15struct worker_iterable;
17template <
typename ... Components>
29 template <
typename Func>
30 void each(Func&& func)
const {
31 each(
nullptr, FLECS_FWD(func));
34 template <
typename Func>
35 void each(flecs::world_t *
world, Func&& func)
const {
36 iterate<_::each_delegate>(
world, FLECS_FWD(func),
37 this->next_each_action());
40 template <
typename Func>
42 iterate<_::each_delegate>(it.world(), FLECS_FWD(func),
43 this->next_each_action());
46 template <
typename Func>
48 iterate<_::each_delegate>(e.world(), FLECS_FWD(func),
49 this->next_each_action());
52 template <
typename Func>
54 return iterate_find<_::find_delegate>(
nullptr, FLECS_FWD(func),
55 this->next_each_action());
69 template <
typename Func>
70 void iter(Func&& func)
const {
71 iterate<_::iter_delegate>(
nullptr, FLECS_FWD(func),
75 template <
typename Func>
76 void iter(flecs::world_t *
world, Func&& func)
const {
77 iterate<_::iter_delegate>(
world, FLECS_FWD(func),
81 template <
typename Func>
83 iterate<_::iter_delegate>(it.world(), FLECS_FWD(func),
87 template <
typename Func>
89 iterate<_::iter_delegate>(e.world(), FLECS_FWD(func),
119 return this->
iter().count();
124 return this->
iter().is_true();
134 friend iter_iterable<Components...>;
135 friend page_iterable<Components...>;
136 friend worker_iterable<Components...>;
138 virtual ecs_iter_t get_iter(flecs::world_t *stage)
const = 0;
142 template <
template<
typename Func,
typename ... Comps>
class Delegate, typename Func, typename NextFunc, typename ... Args>
143 void iterate(flecs::world_t *stage, Func&& func, NextFunc next, Args &&... args) const {
144 ecs_iter_t it = this->get_iter(stage);
145 if (Delegate<Func, Components...>::instanced()) {
146 ECS_BIT_SET(it.flags, EcsIterIsInstanced);
149 while (next(&it, FLECS_FWD(args)...)) {
150 Delegate<Func, Components...>(func).invoke(&it);
154 template <
template<
typename Func,
typename ... Comps>
class Delegate, typename Func, typename NextFunc, typename ... Args>
155 flecs::entity iterate_find(flecs::world_t *stage, Func&& func, NextFunc next, Args &&... args) const {
156 ecs_iter_t it = this->get_iter(stage);
157 if (Delegate<Func, Components...>::instanced()) {
158 ECS_BIT_SET(it.flags, EcsIterIsInstanced);
162 while (!result && next(&it, FLECS_FWD(args)...)) {
163 result = Delegate<Func, Components...>(func).invoke(&it);
172template <
typename ... Components>
174 template <
typename Iterable>
177 m_it = it->get_iter(
world);
178 m_next = it->next_action();
179 m_next_each = it->next_action();
182 iter_iterable<Components...>& set_var(
int var_id, flecs::entity_t value) {
183 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, 0);
198 while (m_next_each(&m_it)) {
199 result += m_it.count;
206 bool result = m_next_each(&m_it);
216 if (m_next_each(&m_it) && m_it.count) {
230 template <
typename Group>
237 ecs_iter_t get_iter(flecs::world_t *
world)
const {
239 ecs_iter_t result = m_it;
240 result.world =
world;
260template <
typename ... Components>
266template <
typename ... Components>
268 template <
typename Iterable>
273 m_chain_it = it->get_iter(
nullptr);
277 ecs_iter_t get_iter(flecs::world_t*)
const {
290 ecs_iter_t m_chain_it;
295template <
typename ... Components>
303template <
typename ... Components>
309 m_chain_it = it->get_iter(
nullptr);
313 ecs_iter_t get_iter(flecs::world_t*)
const {
326 ecs_iter_t m_chain_it;
331template <
typename ... Components>
#define ecs_assert(condition, error_code,...)
Assert.
bool(* ecs_iter_next_action_t)(ecs_iter_t *it)
Function prototype for iterating an iterator.
ecs_iter_t ecs_worker_iter(const ecs_iter_t *it, int32_t index, int32_t count)
Create a worker iterator.
void ecs_iter_fini(ecs_iter_t *it)
Cleanup iterator resources.
ecs_iter_t ecs_page_iter(const ecs_iter_t *it, int32_t offset, int32_t limit)
Create a paged iterator.
void ecs_iter_set_var(ecs_iter_t *it, int32_t var_id, ecs_entity_t entity)
Set value for iterator variable.
bool ecs_worker_next(ecs_iter_t *it)
Progress a worker iterator.
bool ecs_page_next(ecs_iter_t *it)
Progress a paged iterator.
void ecs_query_set_group(ecs_iter_t *it, uint64_t group_id)
Set group to iterate for query iterator.
flecs::entity first() const
Get first element from a pair.
Class for iterating over query results.
bool is_true() const
Return whether iterable has any matches.
flecs::entity first() const
Return first entity matched by iterable.
void each(Func &&func) const
Each iterator.
int32_t count() const
Return number of entities matched by iterable.
void iter(Func &&func) const
Iter iterator.
page_iterable< Components... > page(int32_t offset, int32_t limit)
Page iterator.
worker_iterable< Components... > worker(int32_t index, int32_t count)
Worker iterator.
iter_iterable< Components... > iter(flecs::world_t *world=nullptr) const
Create iterator.