Skip to content

Commit 179d4dd

Browse files
committed
More fixes, hopefully ?
1 parent 322339a commit 179d4dd

2 files changed

Lines changed: 47 additions & 54 deletions

File tree

src/query/engine/eval_toggle.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ flecs_query_row_mask_t flecs_query_get_row_mask(
110110
if (!field_has_bitset) {
111111
if (not_fields & field_bit) {
112112
if (op_ctx->prev_set_fields & field_bit) {
113-
has_bitset = false;
113+
mask = 0;
114+
has_bitset = true;
114115
break;
115116
}
116117
}
@@ -256,11 +257,7 @@ bool flecs_query_toggle_cmp(
256257

257258
/* If table doesn't have bitset columns, all columns match */
258259
if (!(op_ctx->has_bitset = row_mask.has_bitset)) {
259-
if (!not_fields) {
260-
return true;
261-
} else {
262-
goto done;
263-
}
260+
return true;
264261
}
265262

266263
/* No enabled bits */
@@ -388,4 +385,3 @@ repeat: {}
388385

389386
return result;
390387
}
391-

test/query/src/Toggle.c

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6000,15 +6000,9 @@ void Toggle_toggle_0_src(void) {
60006000
}
60016001

60026002
static
6003-
void Toggle_or_toggle_count_matches(ecs_iter_t *it) {
6004-
int32_t *match_count = it->ctx;
6005-
*match_count += it->count;
6006-
}
6007-
6008-
static
6009-
ecs_entity_t Toggle_or_toggle_setup(
6003+
ecs_query_t* Toggle_or_toggle_setup(
60106004
ecs_world_t *world,
6011-
int32_t *match_count,
6005+
ecs_entity_t *e_out,
60126006
ecs_entity_t *has_changed_position,
60136007
ecs_entity_t *has_changed_rotation,
60146008
ecs_entity_t *has_changed_scale)
@@ -6028,18 +6022,16 @@ ecs_entity_t Toggle_or_toggle_setup(
60286022
if (has_changed_rotation) *has_changed_rotation = HasChangedRotation;
60296023
if (has_changed_scale) *has_changed_scale = HasChangedScale;
60306024

6031-
ecs_system(world, {
6032-
.query.terms = {
6025+
ecs_query_t *q = ecs_query(world, {
6026+
.terms = {
60336027
{ .id = ecs_id(Position) },
60346028
{ .id = ecs_id(Velocity) },
60356029
{ .id = ecs_id(Mass) },
60366030
{ .id = HasChangedPosition, .oper = EcsOr },
60376031
{ .id = HasChangedRotation, .oper = EcsOr },
60386032
{ .id = HasChangedScale }
60396033
},
6040-
.query.cache_kind = cache_kind,
6041-
.callback = Toggle_or_toggle_count_matches,
6042-
.ctx = match_count
6034+
.cache_kind = cache_kind
60436035
});
60446036

60456037
ecs_entity_t e = ecs_entity(world, { .name = "e" });
@@ -6054,88 +6046,93 @@ ecs_entity_t Toggle_or_toggle_setup(
60546046
ecs_enable_id(world, e, HasChangedRotation, false);
60556047
ecs_enable_id(world, e, HasChangedScale, false);
60566048

6057-
return e;
6049+
if (e_out) *e_out = e;
6050+
6051+
return q;
6052+
}
6053+
6054+
static
6055+
int32_t Toggle_or_toggle_count(ecs_world_t *world, ecs_query_t *q) {
6056+
int32_t count = 0;
6057+
ecs_iter_t it = ecs_query_iter(world, q);
6058+
while (ecs_query_next(&it)) {
6059+
count += it.count;
6060+
}
6061+
return count;
60586062
}
60596063

60606064
void Toggle_or_toggle_first_branch_matches(void) {
60616065
ecs_world_t *world = ecs_mini();
6062-
int32_t match_count = 0;
60636066
ecs_entity_t HasChangedPosition = 0;
6064-
ecs_entity_t e = Toggle_or_toggle_setup(
6065-
world, &match_count, &HasChangedPosition, NULL, NULL);
6067+
ecs_entity_t e = 0;
6068+
ecs_query_t *q = Toggle_or_toggle_setup(
6069+
world, &e, &HasChangedPosition, NULL, NULL);
60666070

6067-
ecs_progress(world, 0);
6068-
test_int(0, match_count);
6071+
test_int(0, Toggle_or_toggle_count(world, q));
60696072

6070-
match_count = 0;
60716073
ecs_enable_id(world, e, HasChangedPosition, true);
6072-
ecs_progress(world, 0);
6073-
test_int(1, match_count);
6074+
test_int(1, Toggle_or_toggle_count(world, q));
60746075

6076+
ecs_query_fini(q);
60756077
ecs_fini(world);
60766078
}
60776079

60786080
void Toggle_or_toggle_second_branch_matches(void) {
60796081
ecs_world_t *world = ecs_mini();
6080-
int32_t match_count = 0;
60816082
ecs_entity_t HasChangedRotation = 0;
6082-
ecs_entity_t e = Toggle_or_toggle_setup(
6083-
world, &match_count, NULL, &HasChangedRotation, NULL);
6083+
ecs_entity_t e = 0;
6084+
ecs_query_t *q = Toggle_or_toggle_setup(
6085+
world, &e, NULL, &HasChangedRotation, NULL);
60846086

6085-
ecs_progress(world, 0);
6086-
test_int(0, match_count);
6087+
test_int(0, Toggle_or_toggle_count(world, q));
60876088

6088-
match_count = 0;
60896089
ecs_enable_id(world, e, HasChangedRotation, true);
6090-
ecs_progress(world, 0);
6091-
test_int(1, match_count);
6090+
test_int(1, Toggle_or_toggle_count(world, q));
60926091

6092+
ecs_query_fini(q);
60936093
ecs_fini(world);
60946094
}
60956095

60966096
void Toggle_or_toggle_third_branch_matches(void) {
60976097
ecs_world_t *world = ecs_mini();
6098-
int32_t match_count = 0;
60996098
ecs_entity_t HasChangedScale = 0;
6100-
ecs_entity_t e = Toggle_or_toggle_setup(
6101-
world, &match_count, NULL, NULL, &HasChangedScale);
6099+
ecs_entity_t e = 0;
6100+
ecs_query_t *q = Toggle_or_toggle_setup(
6101+
world, &e, NULL, NULL, &HasChangedScale);
61026102

6103-
ecs_progress(world, 0);
6104-
test_int(0, match_count);
6103+
test_int(0, Toggle_or_toggle_count(world, q));
61056104

6106-
match_count = 0;
61076105
ecs_enable_id(world, e, HasChangedScale, true);
6108-
ecs_progress(world, 0);
6109-
test_int(1, match_count);
6106+
test_int(1, Toggle_or_toggle_count(world, q));
61106107

6108+
ecs_query_fini(q);
61116109
ecs_fini(world);
61126110
}
61136111

61146112
void Toggle_or_toggle_all_branches_match_once(void) {
61156113
ecs_world_t *world = ecs_mini();
6116-
int32_t match_count = 0;
61176114
ecs_entity_t HasChangedPosition = 0, HasChangedRotation = 0, HasChangedScale = 0;
6118-
ecs_entity_t e = Toggle_or_toggle_setup(
6119-
world, &match_count,
6115+
ecs_entity_t e = 0;
6116+
ecs_query_t *q = Toggle_or_toggle_setup(
6117+
world, &e,
61206118
&HasChangedPosition, &HasChangedRotation, &HasChangedScale);
61216119

61226120
ecs_enable_id(world, e, HasChangedPosition, true);
61236121
ecs_enable_id(world, e, HasChangedRotation, true);
61246122
ecs_enable_id(world, e, HasChangedScale, true);
61256123

6126-
ecs_progress(world, 0);
6127-
test_int(1, match_count);
6124+
test_int(1, Toggle_or_toggle_count(world, q));
61286125

6126+
ecs_query_fini(q);
61296127
ecs_fini(world);
61306128
}
61316129

61326130
void Toggle_or_toggle_no_branches_match(void) {
61336131
ecs_world_t *world = ecs_mini();
6134-
int32_t match_count = 0;
6135-
Toggle_or_toggle_setup(world, &match_count, NULL, NULL, NULL);
6132+
ecs_query_t *q = Toggle_or_toggle_setup(world, NULL, NULL, NULL, NULL);
61366133

6137-
ecs_progress(world, 0);
6138-
test_int(0, match_count);
6134+
test_int(0, Toggle_or_toggle_count(world, q));
61396135

6136+
ecs_query_fini(q);
61406137
ecs_fini(world);
61416138
}

0 commit comments

Comments
 (0)