Skip to content

Commit

Permalink
Support queries with 32 terms
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jun 22, 2024
1 parent 739f7d2 commit feb3d84
Show file tree
Hide file tree
Showing 17 changed files with 568 additions and 273 deletions.
19 changes: 8 additions & 11 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43510,7 +43510,7 @@ bool flecs_json_serialize_iter_result_ids(

ecs_world_t *world = it->world;
int16_t f, field_count = flecs_ito(int16_t, it->field_count);
int16_t field_mask = flecs_ito(int16_t, (1 << field_count) - 1);
uint16_t field_mask = flecs_ito(uint16_t, (1 << field_count) - 1);
if (q->static_id_fields == field_mask) {
/* All matched ids are static, nothing to serialize */
return false;
Expand Down Expand Up @@ -64679,7 +64679,7 @@ int flecs_query_compile_begin_member_term(
first_id = ECS_TERM_REF_ID(&term->first);

/* First compile as if it's a regular term, to match the component */
term->flags_ &= (ecs_termset_t)~EcsTermIsMember;
term->flags_ &= (uint16_t)~EcsTermIsMember;

/* Replace term id with member parent (the component) */
ecs_entity_t component = ecs_get_parent(world, first_id);
Expand Down Expand Up @@ -67579,9 +67579,9 @@ bool flecs_query_get_fixed_monitor(

for (i = 0; i < term_count; i ++) {
ecs_term_t *term = &terms[i];
int32_t field_index = term->field_index;
int16_t field_index = term->field_index;

if (!(q->read_fields & (1 << field_index))) {
if (!(q->read_fields & flecs_ito(uint32_t, 1 << field_index))) {
continue; /* If term doesn't read data there's nothing to track */
}

Expand Down Expand Up @@ -67876,13 +67876,10 @@ void flecs_query_mark_fields_dirty(
return;
}

// printf("%s\n", ecs_query_str(q));
// printf("[%s]\n", ecs_table_str(it->world, it->table));

ecs_world_t *world = q->world;
int32_t i, field_count = q->field_count;
int16_t i, field_count = q->field_count;
for (i = 0; i < field_count; i ++) {
if (!(write_fields & (1 << i))) {
if (!(write_fields & flecs_ito(uint32_t, 1 << i))) {
continue; /* If term doesn't write data there's nothing to track */
}

Expand All @@ -67896,7 +67893,7 @@ void flecs_query_mark_fields_dirty(
continue;
}

if (q->shared_readonly_fields & (1 << i)) {
if (q->shared_readonly_fields & flecs_ito(uint32_t, 1 << i)) {
/* Shared fields that aren't marked explicitly as out/inout
* default to readonly */
continue;
Expand Down Expand Up @@ -67932,7 +67929,7 @@ void flecs_query_mark_fixed_fields_dirty(
ecs_world_t *world = q->world;
int32_t i, field_count = q->field_count;
for (i = 0; i < field_count; i ++) {
if (!(fixed_write_fields & (1 << i))) {
if (!(fixed_write_fields & flecs_ito(uint32_t, 1 << i))) {
continue; /* If term doesn't write data there's nothing to track */
}

Expand Down
2 changes: 1 addition & 1 deletion flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
/** \def FLECS_TERM_COUNT_MAX
* Maximum number of terms in queries. Should not be set higher than 64. */
#ifndef FLECS_TERM_COUNT_MAX
#define FLECS_TERM_COUNT_MAX 16
#define FLECS_TERM_COUNT_MAX 32
#endif

/** \def FLECS_TERM_ARG_COUNT_MAX
Expand Down
2 changes: 1 addition & 1 deletion include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
/** \def FLECS_TERM_COUNT_MAX
* Maximum number of terms in queries. Should not be set higher than 64. */
#ifndef FLECS_TERM_COUNT_MAX
#define FLECS_TERM_COUNT_MAX 16
#define FLECS_TERM_COUNT_MAX 32
#endif

/** \def FLECS_TERM_ARG_COUNT_MAX
Expand Down
2 changes: 1 addition & 1 deletion src/addons/json/serialize_iter_result_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool flecs_json_serialize_iter_result_ids(

ecs_world_t *world = it->world;
int16_t f, field_count = flecs_ito(int16_t, it->field_count);
int16_t field_mask = flecs_ito(int16_t, (1 << field_count) - 1);
uint16_t field_mask = flecs_ito(uint16_t, (1 << field_count) - 1);
if (q->static_id_fields == field_mask) {
/* All matched ids are static, nothing to serialize */
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/query/compiler/compiler_term.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ int flecs_query_compile_begin_member_term(
first_id = ECS_TERM_REF_ID(&term->first);

/* First compile as if it's a regular term, to match the component */
term->flags_ &= (ecs_termset_t)~EcsTermIsMember;
term->flags_ &= (uint16_t)~EcsTermIsMember;

/* Replace term id with member parent (the component) */
ecs_entity_t component = ecs_get_parent(world, first_id);
Expand Down
15 changes: 6 additions & 9 deletions src/query/engine/change_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ bool flecs_query_get_fixed_monitor(

for (i = 0; i < term_count; i ++) {
ecs_term_t *term = &terms[i];
int32_t field_index = term->field_index;
int16_t field_index = term->field_index;

if (!(q->read_fields & (1 << field_index))) {
if (!(q->read_fields & flecs_ito(uint32_t, 1 << field_index))) {
continue; /* If term doesn't read data there's nothing to track */
}

Expand Down Expand Up @@ -429,13 +429,10 @@ void flecs_query_mark_fields_dirty(
return;
}

// printf("%s\n", ecs_query_str(q));
// printf("[%s]\n", ecs_table_str(it->world, it->table));

ecs_world_t *world = q->world;
int32_t i, field_count = q->field_count;
int16_t i, field_count = q->field_count;
for (i = 0; i < field_count; i ++) {
if (!(write_fields & (1 << i))) {
if (!(write_fields & flecs_ito(uint32_t, 1 << i))) {
continue; /* If term doesn't write data there's nothing to track */
}

Expand All @@ -449,7 +446,7 @@ void flecs_query_mark_fields_dirty(
continue;
}

if (q->shared_readonly_fields & (1 << i)) {
if (q->shared_readonly_fields & flecs_ito(uint32_t, 1 << i)) {
/* Shared fields that aren't marked explicitly as out/inout
* default to readonly */
continue;
Expand Down Expand Up @@ -485,7 +482,7 @@ void flecs_query_mark_fixed_fields_dirty(
ecs_world_t *world = q->world;
int32_t i, field_count = q->field_count;
for (i = 0; i < field_count; i ++) {
if (!(fixed_write_fields & (1 << i))) {
if (!(fixed_write_fields & flecs_ito(uint32_t, 1 << i))) {
continue; /* If term doesn't write data there's nothing to track */
}

Expand Down
53 changes: 33 additions & 20 deletions test/cpp/include/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,39 @@ class Pod {
static int move_ctor_invoked;
};

struct TagA { };
struct TagB { };
struct TagC { };
struct TagD { };
struct TagE { };
struct TagF { };
struct TagG { };
struct TagH { };
struct TagI { };
struct TagJ { };
struct TagK { };
struct TagL { };
struct TagM { };
struct TagN { };
struct TagO { };
struct TagP { };
struct TagQ { };
struct TagR { };
struct TagS { };
struct TagT { };
struct Tag0 { };
struct Tag1 { };
struct Tag2 { };
struct Tag3 { };
struct Tag4 { };
struct Tag5 { };
struct Tag6 { };
struct Tag7 { };
struct Tag8 { };
struct Tag9 { };
struct Tag10 { };
struct Tag11 { };
struct Tag12 { };
struct Tag13 { };
struct Tag14 { };
struct Tag15 { };
struct Tag16 { };
struct Tag17 { };
struct Tag18 { };
struct Tag19 { };
struct Tag20 { };
struct Tag21 { };
struct Tag22 { };
struct Tag23 { };
struct Tag24 { };
struct Tag25 { };
struct Tag26 { };
struct Tag27 { };
struct Tag28 { };
struct Tag29 { };
struct Tag30 { };
struct Tag31 { };
struct Tag32 { };

template <typename T>
struct Template {
Expand Down
2 changes: 2 additions & 0 deletions test/cpp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@
"world_each_filter_2_components_no_entity",
"10_terms",
"16_terms",
"32_terms",
"33_terms",
"term_after_arg",
"name_arg",
"const_in_term",
Expand Down
Loading

0 comments on commit feb3d84

Please sign in to comment.