15template <
typename ... Components>
18 "all sparse_query components must have the dont_fragment trait and "
19 "must not declare the on_instantiate::inherit policy");
31 template <
typename Func>
32 void each(Func&& func)
const {
33 each_impl(std::index_sequence_for<Components...>{}, func);
39 each([&](Components&...) { result ++; });
47 template <
size_t ... Is,
typename Func>
48 void each_impl(std::index_sequence<Is...>,
const Func& func)
const {
49 constexpr size_t n =
sizeof...(Components);
51 ecs_sparse_t *
sparse[n] = { storage(ids_[Is])... };
52 for (
size_t f = 0; f < n; f ++) {
59 for (
size_t f = 1; f < n; f ++) {
65 const uint64_t *entities = flecs_sparse_ids(sparse[lead]);
66 int32_t
count = sparse[lead]->count - 1;
68 for (int32_t i = 0; i <
count; i ++) {
69 uint64_t e = entities[i];
71 if (!(... && (ptrs[Is] = flecs_sparse_get_w_check(
72 sparse[Is], ECS_SIZEOF(remove_reference_t<Components>), e,
79 if (flecs_table_flags(r->table) &
80 (EcsTableNotQueryable|EcsTableIsPrefab|EcsTableIsDisabled))
85 if constexpr (std::is_invocable<
88 func(flecs::entity(world_, e),
89 (*
static_cast<remove_reference_t<Components>*
>(
92 func((*
static_cast<remove_reference_t<Components>*
>(
100 return cr ? flecs_component_get_sparse(cr) : nullptr;
103 void assert_policies()
const {
109 "sparse_query component has the OnInstantiate Inherit trait, "
110 "which sparse queries cannot match; add the on_instantiate "
111 "trait at compile time instead");
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_OPERATION
Invalid operation error code.
struct ecs_component_record_t ecs_component_record_t
Information about a (component) ID, such as type info and tables with the ID.
struct ecs_record_t ecs_record_t
Information about an entity, like its table and row.
ecs_world_t world_t
World type.
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.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get the world from a poly.
int32_t count() const
Return the number of entities matched by the query.
void each(Func &&func) const
Iterate the query.
Trait that marks a component as Sparse at compile time.
flecs::entity entity(Args &&... args) const
Create an entity.