Skip to content

Commit 2a1756d

Browse files
authored
Merge branch 'SanderMertens:master' into master
2 parents 63ab160 + 4e22b78 commit 2a1756d

7 files changed

Lines changed: 50 additions & 6 deletions

File tree

distr/flecs.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15696,6 +15696,7 @@ void flecs_emit_forward_table_up(
1569615696
const EcsParent *parent = ecs_get(world, tgt, EcsParent);
1569715697
ecs_assert(parent != NULL, ECS_INTERNAL_ERROR, NULL);
1569815698
ecs_assert(parent->value != 0, ECS_INTERNAL_ERROR, NULL);
15699+
1569915700
cr = flecs_components_get(world, ecs_childof(parent->value));
1570015701
ecs_assert(cr != NULL, ECS_INTERNAL_ERROR, NULL);
1570115702
}
@@ -16242,8 +16243,7 @@ void flecs_emit(
1624216243

1624316244
for (p = 0; p < parent_count; p ++) {
1624416245
ecs_entity_t parent = parents[p].value;
16245-
ecs_assert(parent != 0, ECS_INTERNAL_ERROR, NULL);
16246-
if (flecs_entities_is_alive(world, parent)) {
16246+
if (parent && flecs_entities_is_alive(world, parent)) {
1624716247
ecs_id_t pair = ecs_childof(parent);
1624816248
ecs_type_t type = { .count = 1, .array = &pair };
1624916249
pdesc.ids = &type;
@@ -20669,6 +20669,8 @@ ecs_type_t flecs_prefab_spawner_build_type(
2066920669
ecs_type_t dst = {0};
2067020670
ecs_type_t *src = &table->type;
2067120671

20672+
flecs_type_add(world, &dst, ecs_id(EcsParent));
20673+
2067220674
int32_t i, count = src->count;
2067320675
for (i = 0; i < count; i ++) {
2067420676
ecs_id_t id = src->array[i];
@@ -20909,6 +20911,7 @@ void flecs_spawner_instantiate(
2090920911
ecs_assert(cr != NULL, ECS_INTERNAL_ERROR, NULL);
2091020912

2091120913
int32_t parent_column = table->component_map[ecs_id(EcsParent)];
20914+
ecs_assert(parent_column != 0, ECS_INTERNAL_ERROR, NULL);
2091220915
EcsParent *parent_ptr = table->data.columns[parent_column - 1].data;
2091320916
parent_ptr = &parent_ptr[row];
2091420917
parent_ptr->value = parent;
@@ -41161,6 +41164,8 @@ void flecs_bootstrap_parent_component(
4116141164
.ctor = flecs_default_ctor,
4116241165
.on_replace = flecs_on_replace_parent
4116341166
});
41167+
41168+
ecs_add_pair(world, ecs_id(EcsParent), EcsOnInstantiate, EcsDontInherit);
4116441169
}
4116541170

4116641171

src/observable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ void flecs_emit_forward_table_up(
837837
const EcsParent *parent = ecs_get(world, tgt, EcsParent);
838838
ecs_assert(parent != NULL, ECS_INTERNAL_ERROR, NULL);
839839
ecs_assert(parent->value != 0, ECS_INTERNAL_ERROR, NULL);
840+
840841
cr = flecs_components_get(world, ecs_childof(parent->value));
841842
ecs_assert(cr != NULL, ECS_INTERNAL_ERROR, NULL);
842843
}
@@ -1383,8 +1384,7 @@ void flecs_emit(
13831384

13841385
for (p = 0; p < parent_count; p ++) {
13851386
ecs_entity_t parent = parents[p].value;
1386-
ecs_assert(parent != 0, ECS_INTERNAL_ERROR, NULL);
1387-
if (flecs_entities_is_alive(world, parent)) {
1387+
if (parent && flecs_entities_is_alive(world, parent)) {
13881388
ecs_id_t pair = ecs_childof(parent);
13891389
ecs_type_t type = { .count = 1, .array = &pair };
13901390
pdesc.ids = &type;

src/storage/non_fragmenting_childof.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,6 @@ void flecs_bootstrap_parent_component(
432432
.ctor = flecs_default_ctor,
433433
.on_replace = flecs_on_replace_parent
434434
});
435+
436+
ecs_add_pair(world, ecs_id(EcsParent), EcsOnInstantiate, EcsDontInherit);
435437
}

src/tree_spawner.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ ecs_type_t flecs_prefab_spawner_build_type(
5252
ecs_type_t dst = {0};
5353
ecs_type_t *src = &table->type;
5454

55+
flecs_type_add(world, &dst, ecs_id(EcsParent));
56+
5557
int32_t i, count = src->count;
5658
for (i = 0; i < count; i ++) {
5759
ecs_id_t id = src->array[i];
@@ -292,6 +294,7 @@ void flecs_spawner_instantiate(
292294
ecs_assert(cr != NULL, ECS_INTERNAL_ERROR, NULL);
293295

294296
int32_t parent_column = table->component_map[ecs_id(EcsParent)];
297+
ecs_assert(parent_column != 0, ECS_INTERNAL_ERROR, NULL);
295298
EcsParent *parent_ptr = table->data.columns[parent_column - 1].data;
296299
parent_ptr = &parent_ptr[row];
297300
parent_ptr->value = parent;

test/core/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@
965965
"defer_reparent_to_deleted_parent",
966966
"delete_mixed_tree_1",
967967
"delete_mixed_tree_2",
968-
"delete_mixed_tree_3"
968+
"delete_mixed_tree_3",
969+
"delete_mixed_tree_4"
969970
]
970971
}, {
971972
"id": "Hierarchies",

test/core/src/NonFragmentingChildOf.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,3 +5805,31 @@ void NonFragmentingChildOf_delete_mixed_tree_3(void) {
58055805

58065806
ecs_fini(world);
58075807
}
5808+
5809+
void NonFragmentingChildOf_delete_mixed_tree_4(void) {
5810+
ecs_world_t *world = ecs_init();
5811+
5812+
ECS_TAG(world, Foo);
5813+
5814+
ecs_entity_t a = ecs_new(world);
5815+
ecs_entity_t b = ecs_new(world);
5816+
ecs_set(world, b, EcsParent, {a});
5817+
5818+
ecs_entity_t c = ecs_new(world);
5819+
ecs_add_pair(world, c, EcsIsA, b);
5820+
test_assert(!ecs_has(world, c, EcsParent));
5821+
5822+
ecs_entity_t d = ecs_new(world);
5823+
ecs_add_pair(world, d, EcsChildOf, c);
5824+
5825+
ecs_delete(world, a);
5826+
test_assert(!ecs_is_alive(world, a));
5827+
test_assert(!ecs_is_alive(world, b));
5828+
test_assert(!ecs_has_pair(world, c, EcsIsA, EcsWildcard));
5829+
5830+
test_assert(ecs_is_alive(world, c));
5831+
test_assert(ecs_is_alive(world, d));
5832+
ecs_add(world, d, Foo);
5833+
5834+
ecs_fini(world);
5835+
}

test/core/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ void NonFragmentingChildOf_defer_reparent_to_deleted_parent(void);
934934
void NonFragmentingChildOf_delete_mixed_tree_1(void);
935935
void NonFragmentingChildOf_delete_mixed_tree_2(void);
936936
void NonFragmentingChildOf_delete_mixed_tree_3(void);
937+
void NonFragmentingChildOf_delete_mixed_tree_4(void);
937938

938939
// Testsuite 'Hierarchies'
939940
void Hierarchies_setup(void);
@@ -6828,6 +6829,10 @@ bake_test_case NonFragmentingChildOf_testcases[] = {
68286829
{
68296830
"delete_mixed_tree_3",
68306831
NonFragmentingChildOf_delete_mixed_tree_3
6832+
},
6833+
{
6834+
"delete_mixed_tree_4",
6835+
NonFragmentingChildOf_delete_mixed_tree_4
68316836
}
68326837
};
68336838

@@ -15740,7 +15745,7 @@ static bake_test_suite suites[] = {
1574015745
"NonFragmentingChildOf",
1574115746
NULL,
1574215747
NULL,
15743-
228,
15748+
229,
1574415749
NonFragmentingChildOf_testcases
1574515750
},
1574615751
{

0 commit comments

Comments
 (0)