Skip to content

Commit

Permalink
#516 ensure builtin symbols can be looked up by symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Nov 4, 2021
1 parent afc4da7 commit d807ad1
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 25 deletions.
10 changes: 6 additions & 4 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -39351,7 +39351,7 @@ void ensure_module_tag(ecs_iter_t *it) {
/* -- Iterable mixins -- */

static
void on_add_iterable_init(
void on_event_iterable_init(
const ecs_world_t *world,
const ecs_poly_t *poly, /* Observable */
ecs_iter_t *it,
Expand Down Expand Up @@ -39611,8 +39611,9 @@ void flecs_bootstrap(
ecs_add_id(world, EcsOnDeleteObject, EcsFinal);
ecs_add_id(world, EcsDefaultChildComponent, EcsFinal);

/* Make EcsOnAdd event iterable to enable .yield_existing */
ecs_set(world, EcsOnAdd, EcsIterable, { .init = on_add_iterable_init });
/* Make EcsOnAdd, EcsOnSet events iterable to enable .yield_existing */
ecs_set(world, EcsOnAdd, EcsIterable, { .init = on_event_iterable_init });
ecs_set(world, EcsOnSet, EcsIterable, { .init = on_event_iterable_init });

/* Define triggers for when relationship cleanup rules are assigned */
ecs_trigger_init(world, &(ecs_trigger_desc_t){
Expand Down Expand Up @@ -39952,7 +39953,8 @@ void flecs_bootstrap_hierarchy(ecs_world_t *world) {
ecs_trigger_init(world, &(ecs_trigger_desc_t){
.term = {.id = ecs_pair(ecs_id(EcsIdentifier), EcsSymbol)},
.callback = on_set_symbol,
.events = {EcsOnSet}
.events = {EcsOnSet},
.yield_existing = true
});
}

Expand Down
7 changes: 4 additions & 3 deletions src/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void ensure_module_tag(ecs_iter_t *it) {
/* -- Iterable mixins -- */

static
void on_add_iterable_init(
void on_event_iterable_init(
const ecs_world_t *world,
const ecs_poly_t *poly, /* Observable */
ecs_iter_t *it,
Expand Down Expand Up @@ -416,8 +416,9 @@ void flecs_bootstrap(
ecs_add_id(world, EcsOnDeleteObject, EcsFinal);
ecs_add_id(world, EcsDefaultChildComponent, EcsFinal);

/* Make EcsOnAdd event iterable to enable .yield_existing */
ecs_set(world, EcsOnAdd, EcsIterable, { .init = on_add_iterable_init });
/* Make EcsOnAdd, EcsOnSet events iterable to enable .yield_existing */
ecs_set(world, EcsOnAdd, EcsIterable, { .init = on_event_iterable_init });
ecs_set(world, EcsOnSet, EcsIterable, { .init = on_event_iterable_init });

/* Define triggers for when relationship cleanup rules are assigned */
ecs_trigger_init(world, &(ecs_trigger_desc_t){
Expand Down
3 changes: 2 additions & 1 deletion src/hierarchy.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ void flecs_bootstrap_hierarchy(ecs_world_t *world) {
ecs_trigger_init(world, &(ecs_trigger_desc_t){
.term = {.id = ecs_pair(ecs_id(EcsIdentifier), EcsSymbol)},
.callback = on_set_symbol,
.events = {EcsOnSet}
.events = {EcsOnSet},
.yield_existing = true
});
}

Expand Down
7 changes: 4 additions & 3 deletions test/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1494,9 +1494,10 @@
"trigger_on_prefab",
"trigger_on_disabled",
"trigger_cleanup_2_w_self_super_id",
"yield_existing",
"yield_existing_2_tables",
"yield_existing_wildcard_pair"
"on_add_yield_existing",
"on_add_yield_existing_2_tables",
"on_add_yield_existing_wildcard_pair",
"on_set_yield_existing"
]
}, {
"id": "Observer",
Expand Down
1 change: 0 additions & 1 deletion test/api/src/Lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ void Lookup_lookup_path_wildcard_from_scope() {
}

void Lookup_resolve_builtin_symbols() {
test_quarantine("Nov 3 2021");
ecs_world_t *world = ecs_init();

test_assert(ecs_lookup_symbol(world, "EcsComponent", false) == ecs_id(EcsComponent));
Expand Down
90 changes: 87 additions & 3 deletions test/api/src/Trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ void Trigger_w_value(ecs_iter_t *it) {
test_int(p->y, 20);
}

static
void Trigger_n_w_values(ecs_iter_t *it) {
probe_system_w_ctx(it, it->ctx);

Position *p = ecs_term(it, Position, 1);

test_assert(it->entities != NULL);

int i;
for (i = 0; i < it->count; i ++) {
test_assert(it->entities[i] != 0);
test_int(p[i].x, 10 + i * 20);
test_int(p[i].y, 20 + i * 20);
}
}

void TriggerAdd(ecs_iter_t *it) {
ecs_id_t id = *(ecs_id_t*)it->ctx;

Expand Down Expand Up @@ -751,6 +767,9 @@ void Trigger_on_remove_pair_wildcard() {
test_int(ctx.e[0], e);
test_int(ctx.c[0][0], ecs_pair(Pred, Obj));

// Delete trigger so it doesn't go crazy while shutting down the world
ecs_delete(world, t);

ecs_fini(world);
}

Expand Down Expand Up @@ -1384,6 +1403,9 @@ void Trigger_un_set_pair_wildcard() {
test_int(ctx.e[0], e);
test_int(ctx.c[0][0], ecs_pair(Rel, Obj));

// Delete trigger so it doesn't go crazy while shutting down the world
ecs_delete(world, t);

ecs_fini(world);
}

Expand Down Expand Up @@ -2533,7 +2555,7 @@ void Trigger_trigger_cleanup_2_w_self_super_id() {
/* Ensure two triggers for Tag and Tag(super) are cleaned up correctly */
}

void Trigger_yield_existing() {
void Trigger_on_add_yield_existing() {
ecs_world_t *world = ecs_init();

ECS_TAG(world, Tag);
Expand Down Expand Up @@ -2569,10 +2591,15 @@ void Trigger_yield_existing() {
test_int(ctx.e[2], e3);
test_int(ctx.c[0][0], Tag);

// Ensure normal triggering also still works
ctx = (Probe){0};
ecs_new(world, Tag);
test_int(ctx.invoked, 1);

ecs_fini(world);
}

void Trigger_yield_existing_2_tables() {
void Trigger_on_add_yield_existing_2_tables() {
ecs_world_t *world = ecs_init();

ECS_TAG(world, TagA);
Expand Down Expand Up @@ -2612,10 +2639,15 @@ void Trigger_yield_existing_2_tables() {
test_int(ctx.c[0][0], TagA);
test_int(ctx.c[1][0], TagA);

// Ensure normal triggering also still works
ctx = (Probe){0};
ecs_new(world, TagA);
test_int(ctx.invoked, 1);

ecs_fini(world);
}

void Trigger_yield_existing_wildcard_pair() {
void Trigger_on_add_yield_existing_wildcard_pair() {
ecs_world_t *world = ecs_init();

ECS_TAG(world, Rel);
Expand Down Expand Up @@ -2654,5 +2686,57 @@ void Trigger_yield_existing_wildcard_pair() {
test_int(ctx.c[0][0], ecs_pair(Rel, ObjA));
test_int(ctx.c[1][0], ecs_pair(Rel, ObjB));

// Ensure normal triggering also still works
ctx = (Probe){0};
ecs_new_w_pair(world, Rel, ObjA);
test_int(ctx.invoked, 1);

ecs_fini(world);
}

void Trigger_on_set_yield_existing() {
ecs_world_t *world = ecs_init();

ECS_COMPONENT(world, Position);

/* Create entities before trigger */
ecs_entity_t e1 = ecs_set(world, 0, Position, {10, 20});
ecs_entity_t e2 = ecs_set(world, 0, Position, {30, 40});
ecs_entity_t e3 = ecs_set(world, 0, Position, {50, 60});

test_assert(e1 != 0);
test_assert(e2 != 0);
test_assert(e3 != 0);

Probe ctx = {0};
ecs_entity_t t = ecs_trigger_init(world, &(ecs_trigger_desc_t){
.term.id = ecs_id(Position),
.events = {EcsOnSet},
.callback = Trigger_n_w_values,
.ctx = &ctx,
.yield_existing = true
});

test_int(ctx.invoked, 1);
test_int(ctx.count, 3);
test_int(ctx.system, t);
test_int(ctx.event, EcsOnAdd);
test_int(ctx.event_id, ecs_id(Position));
test_int(ctx.term_count, 1);
test_null(ctx.param);

test_int(ctx.e[0], e1);
test_int(ctx.e[1], e2);
test_int(ctx.e[2], e3);
test_int(ctx.c[0][0], ecs_id(Position));

// Ensure normal triggering also still works
ctx = (Probe){0};
ecs_entity_t e = ecs_new(world, Position);
test_int(ctx.invoked, 0);

ecs_set(world, e, Position, {10, 20});
test_int(ctx.invoked, 1);

ecs_fini(world);
}
25 changes: 15 additions & 10 deletions test/api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,10 @@ void Trigger_readonly_term(void);
void Trigger_trigger_on_prefab(void);
void Trigger_trigger_on_disabled(void);
void Trigger_trigger_cleanup_2_w_self_super_id(void);
void Trigger_yield_existing(void);
void Trigger_yield_existing_2_tables(void);
void Trigger_yield_existing_wildcard_pair(void);
void Trigger_on_add_yield_existing(void);
void Trigger_on_add_yield_existing_2_tables(void);
void Trigger_on_add_yield_existing_wildcard_pair(void);
void Trigger_on_set_yield_existing(void);

// Testsuite 'Observer'
void Observer_2_terms_w_on_add(void);
Expand Down Expand Up @@ -7651,16 +7652,20 @@ bake_test_case Trigger_testcases[] = {
Trigger_trigger_cleanup_2_w_self_super_id
},
{
"yield_existing",
Trigger_yield_existing
"on_add_yield_existing",
Trigger_on_add_yield_existing
},
{
"yield_existing_2_tables",
Trigger_yield_existing_2_tables
"on_add_yield_existing_2_tables",
Trigger_on_add_yield_existing_2_tables
},
{
"yield_existing_wildcard_pair",
Trigger_yield_existing_wildcard_pair
"on_add_yield_existing_wildcard_pair",
Trigger_on_add_yield_existing_wildcard_pair
},
{
"on_set_yield_existing",
Trigger_on_set_yield_existing
}
};

Expand Down Expand Up @@ -10798,7 +10803,7 @@ static bake_test_suite suites[] = {
"Trigger",
NULL,
NULL,
67,
68,
Trigger_testcases
},
{
Expand Down

0 comments on commit d807ad1

Please sign in to comment.