Skip to content

Commit 60c5290

Browse files
#1882 Remove redundant check in flecs_emit
1 parent e9bb107 commit 60c5290

File tree

2 files changed

+62
-68
lines changed

2 files changed

+62
-68
lines changed

distr/flecs.c

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15291,45 +15291,42 @@ void flecs_emit(
1529115291

1529215292
/* Check if this id is a pair of an traversable relationship. If so, we
1529315293
* may have to forward ids from the pair's target. */
15294-
bool is_pair = ECS_IS_PAIR(id);
15295-
if (can_forward && is_pair) {
15296-
if (is_pair && (cr_flags & EcsIdTraversable)) {
15297-
const ecs_event_record_t *er_fwd = NULL;
15298-
if (ECS_PAIR_FIRST(id) == EcsIsA) {
15299-
if (event == EcsOnAdd) {
15300-
if (!world->stages[0]->base) {
15301-
/* Adding an IsA relationship can trigger prefab
15302-
* instantiation, which can instantiate prefab
15303-
* hierarchies for the entity to which the
15304-
* relationship was added. */
15305-
ecs_entity_t tgt = ECS_PAIR_SECOND(id);
15306-
15307-
/* Setting this value prevents flecs_instantiate
15308-
* from being called recursively, in case prefab
15309-
* children also have IsA relationships. */
15310-
world->stages[0]->base = tgt;
15311-
const ecs_entity_t *instances =
15312-
ecs_table_entities(table);
15313-
int32_t e;
15314-
15315-
for (e = 0; e < count; e ++) {
15316-
flecs_instantiate(
15317-
world, tgt, instances[offset + e], NULL);
15318-
}
15319-
15320-
world->stages[0]->base = 0;
15294+
if (can_forward && (cr_flags & EcsIdTraversable)) {
15295+
const ecs_event_record_t *er_fwd = NULL;
15296+
if (ECS_PAIR_FIRST(id) == EcsIsA) {
15297+
if (event == EcsOnAdd) {
15298+
if (!world->stages[0]->base) {
15299+
/* Adding an IsA relationship can trigger prefab
15300+
* instantiation, which can instantiate prefab
15301+
* hierarchies for the entity to which the
15302+
* relationship was added. */
15303+
ecs_entity_t tgt = ECS_PAIR_SECOND(id);
15304+
15305+
/* Setting this value prevents flecs_instantiate
15306+
* from being called recursively, in case prefab
15307+
* children also have IsA relationships. */
15308+
world->stages[0]->base = tgt;
15309+
const ecs_entity_t *instances =
15310+
ecs_table_entities(table);
15311+
int32_t e;
15312+
15313+
for (e = 0; e < count; e ++) {
15314+
flecs_instantiate(
15315+
world, tgt, instances[offset + e], NULL);
1532115316
}
1532215317

15323-
/* Adding an IsA relationship will emit OnSet events for
15324-
* any new reachable components. */
15325-
er_fwd = er_onset;
15318+
world->stages[0]->base = 0;
1532615319
}
15327-
}
1532815320

15329-
/* Forward events for components from pair target */
15330-
flecs_emit_forward(world, er, er_fwd, ids, &it, table, cr);
15331-
ecs_assert(it.event_cur == evtx, ECS_INTERNAL_ERROR, NULL);
15321+
/* Adding an IsA relationship will emit OnSet events for
15322+
* any new reachable components. */
15323+
er_fwd = er_onset;
15324+
}
1533215325
}
15326+
15327+
/* Forward events for components from pair target */
15328+
flecs_emit_forward(world, er, er_fwd, ids, &it, table, cr);
15329+
ecs_assert(it.event_cur == evtx, ECS_INTERNAL_ERROR, NULL);
1533315330
}
1533415331

1533515332
if (er) {

src/observable.c

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,45 +1299,42 @@ void flecs_emit(
12991299

13001300
/* Check if this id is a pair of an traversable relationship. If so, we
13011301
* may have to forward ids from the pair's target. */
1302-
bool is_pair = ECS_IS_PAIR(id);
1303-
if (can_forward && is_pair) {
1304-
if (is_pair && (cr_flags & EcsIdTraversable)) {
1305-
const ecs_event_record_t *er_fwd = NULL;
1306-
if (ECS_PAIR_FIRST(id) == EcsIsA) {
1307-
if (event == EcsOnAdd) {
1308-
if (!world->stages[0]->base) {
1309-
/* Adding an IsA relationship can trigger prefab
1310-
* instantiation, which can instantiate prefab
1311-
* hierarchies for the entity to which the
1312-
* relationship was added. */
1313-
ecs_entity_t tgt = ECS_PAIR_SECOND(id);
1314-
1315-
/* Setting this value prevents flecs_instantiate
1316-
* from being called recursively, in case prefab
1317-
* children also have IsA relationships. */
1318-
world->stages[0]->base = tgt;
1319-
const ecs_entity_t *instances =
1320-
ecs_table_entities(table);
1321-
int32_t e;
1322-
1323-
for (e = 0; e < count; e ++) {
1324-
flecs_instantiate(
1325-
world, tgt, instances[offset + e], NULL);
1326-
}
1327-
1328-
world->stages[0]->base = 0;
1302+
if (can_forward && (cr_flags & EcsIdTraversable)) {
1303+
const ecs_event_record_t *er_fwd = NULL;
1304+
if (ECS_PAIR_FIRST(id) == EcsIsA) {
1305+
if (event == EcsOnAdd) {
1306+
if (!world->stages[0]->base) {
1307+
/* Adding an IsA relationship can trigger prefab
1308+
* instantiation, which can instantiate prefab
1309+
* hierarchies for the entity to which the
1310+
* relationship was added. */
1311+
ecs_entity_t tgt = ECS_PAIR_SECOND(id);
1312+
1313+
/* Setting this value prevents flecs_instantiate
1314+
* from being called recursively, in case prefab
1315+
* children also have IsA relationships. */
1316+
world->stages[0]->base = tgt;
1317+
const ecs_entity_t *instances =
1318+
ecs_table_entities(table);
1319+
int32_t e;
1320+
1321+
for (e = 0; e < count; e ++) {
1322+
flecs_instantiate(
1323+
world, tgt, instances[offset + e], NULL);
13291324
}
13301325

1331-
/* Adding an IsA relationship will emit OnSet events for
1332-
* any new reachable components. */
1333-
er_fwd = er_onset;
1326+
world->stages[0]->base = 0;
13341327
}
1335-
}
13361328

1337-
/* Forward events for components from pair target */
1338-
flecs_emit_forward(world, er, er_fwd, ids, &it, table, cr);
1339-
ecs_assert(it.event_cur == evtx, ECS_INTERNAL_ERROR, NULL);
1329+
/* Adding an IsA relationship will emit OnSet events for
1330+
* any new reachable components. */
1331+
er_fwd = er_onset;
1332+
}
13401333
}
1334+
1335+
/* Forward events for components from pair target */
1336+
flecs_emit_forward(world, er, er_fwd, ids, &it, table, cr);
1337+
ecs_assert(it.event_cur == evtx, ECS_INTERNAL_ERROR, NULL);
13411338
}
13421339

13431340
if (er) {

0 commit comments

Comments
 (0)