@@ -1582,6 +1582,76 @@ void NonFragmentingChildOf_depth_after_parent_remove_parent(void) {
15821582 ecs_fini (world );
15831583}
15841584
1585+ void NonFragmentingChildOf_depth_after_parent_remove_other_sibling_parent (void ) {
1586+ ecs_world_t * world = ecs_mini ();
1587+
1588+ ecs_entity_t base = ecs_new_w_id (world , EcsPrefab );
1589+ ecs_insert (world , ecs_value (EcsParent , {base }));
1590+
1591+ ecs_entity_t p = ecs_new (world );
1592+
1593+ ecs_entity_t c1 = ecs_new_w_pair (world , EcsIsA , base );
1594+ ecs_add_pair (world , c1 , EcsChildOf , p );
1595+ ecs_entities_t c1_children = ecs_get_ordered_children (world , c1 );
1596+ test_int (c1_children .count , 1 );
1597+ ecs_entity_t gc1 = c1_children .ids [0 ];
1598+
1599+ ecs_entity_t c2 = ecs_new_w_pair (world , EcsIsA , base );
1600+ ecs_add_pair (world , c2 , EcsChildOf , p );
1601+ ecs_entities_t c2_children = ecs_get_ordered_children (world , c2 );
1602+ test_int (c2_children .count , 1 );
1603+ ecs_entity_t gc2 = c2_children .ids [0 ];
1604+
1605+ test_assert (ecs_has_id (world , gc1 , ecs_value_pair (EcsParentDepth , 2 )));
1606+ test_assert (ecs_has_id (world , gc2 , ecs_value_pair (EcsParentDepth , 2 )));
1607+
1608+ ecs_remove_pair (world , c2 , EcsChildOf , EcsWildcard );
1609+
1610+ test_assert (ecs_has_id (world , gc1 , ecs_value_pair (EcsParentDepth , 2 )));
1611+ test_assert (!ecs_has_id (world , gc1 , ecs_value_pair (EcsParentDepth , 1 )));
1612+
1613+ test_assert (ecs_has_id (world , gc2 , ecs_value_pair (EcsParentDepth , 1 )));
1614+ test_assert (!ecs_has_id (world , gc2 , ecs_value_pair (EcsParentDepth , 2 )));
1615+
1616+ ecs_fini (world );
1617+ }
1618+
1619+ void NonFragmentingChildOf_depth_after_parent_set_parent_sibling_traversable_no_children (void ) {
1620+ ecs_world_t * world = ecs_mini ();
1621+
1622+ ecs_entity_t root = ecs_new (world );
1623+ ecs_entity_t p = ecs_new (world );
1624+ ecs_entity_t c1 = ecs_insert (world , ecs_value (EcsParent , {p }));
1625+ ecs_entity_t c2 = ecs_insert (world , ecs_value (EcsParent , {p }));
1626+ ecs_add_id (world , c2 , EcsOrderedChildren );
1627+ ecs_entity_t gc2 = ecs_insert (world , ecs_value (EcsParent , {c2 }));
1628+
1629+ /* Make first sibling traversable without creating ChildOf record for it. */
1630+ ecs_new_w_pair (world , EcsIsA , c1 );
1631+
1632+ ecs_entities_t children = ecs_get_ordered_children (world , p );
1633+ test_int (children .count , 2 );
1634+ test_uint (children .ids [0 ], c1 );
1635+ test_uint (children .ids [1 ], c2 );
1636+
1637+ test_assert (ecs_has_id (world , c1 , ecs_value_pair (EcsParentDepth , 1 )));
1638+ test_assert (ecs_has_id (world , c2 , ecs_value_pair (EcsParentDepth , 1 )));
1639+ test_assert (ecs_has_id (world , gc2 , ecs_value_pair (EcsParentDepth , 2 )));
1640+
1641+ ecs_set (world , p , EcsParent , {root });
1642+
1643+ test_assert (ecs_has_id (world , c1 , ecs_value_pair (EcsParentDepth , 2 )));
1644+ test_assert (!ecs_has_id (world , c1 , ecs_value_pair (EcsParentDepth , 1 )));
1645+
1646+ test_assert (ecs_has_id (world , c2 , ecs_value_pair (EcsParentDepth , 2 )));
1647+ test_assert (!ecs_has_id (world , c2 , ecs_value_pair (EcsParentDepth , 1 )));
1648+
1649+ test_assert (ecs_has_id (world , gc2 , ecs_value_pair (EcsParentDepth , 3 )));
1650+ test_assert (!ecs_has_id (world , gc2 , ecs_value_pair (EcsParentDepth , 2 )));
1651+
1652+ ecs_fini (world );
1653+ }
1654+
15851655void NonFragmentingChildOf_depth_after_parent_reparent (void ) {
15861656 ecs_world_t * world = ecs_mini ();
15871657
@@ -4361,6 +4431,55 @@ void NonFragmentingChildOf_delete_tree_6(void) {
43614431 ecs_fini (world );
43624432}
43634433
4434+ static ECS_TAG_DECLARE (Foo );
4435+ static ECS_TAG_DECLARE (Bar );
4436+
4437+ static void observer_on_remove_position_up (ecs_iter_t * it ) {
4438+ if (it -> sources [0 ] != 0 ) {
4439+ ecs_entity_t src = it -> sources [0 ];
4440+ if (ecs_is_alive (it -> world , src ) && !ecs_has (it -> world , src , Foo )) {
4441+ ecs_add (it -> world , src , Bar );
4442+ }
4443+ }
4444+ }
4445+
4446+ void NonFragmentingChildOf_delete_tree_7 (void ) {
4447+ ecs_world_t * world = ecs_mini ();
4448+
4449+ ECS_COMPONENT_DEFINE (world , Position );
4450+ ECS_TAG_DEFINE (world , Foo );
4451+ ECS_TAG_DEFINE (world , Bar );
4452+
4453+ ecs_observer (world , {
4454+ .query .terms = {{
4455+ .id = ecs_id (Position ),
4456+ .src .id = EcsUp ,
4457+ .trav = EcsChildOf
4458+ }},
4459+ .events = { EcsOnRemove },
4460+ .callback = observer_on_remove_position_up
4461+ });
4462+
4463+ ecs_entity_t G = ecs_new_w (world , Position );
4464+ ecs_entity_t Q = ecs_new_w_parent (world , G , NULL );
4465+ ecs_entity_t P = ecs_new_w_parent (world , G , NULL );
4466+
4467+ ecs_add (world , P , Position );
4468+
4469+ ecs_entity_t C1 = ecs_new (world );
4470+ ecs_add_pair (world , C1 , EcsChildOf , P );
4471+ ecs_add (world , C1 , Bar );
4472+
4473+ ecs_delete (world , G );
4474+
4475+ test_assert (!ecs_is_alive (world , G ));
4476+ test_assert (!ecs_is_alive (world , Q ));
4477+ test_assert (!ecs_is_alive (world , P ));
4478+ test_assert (!ecs_is_alive (world , C1 ));
4479+
4480+ ecs_fini (world );
4481+ }
4482+
43644483void NonFragmentingChildOf_add_parent_to_childof_child (void ) {
43654484 ecs_world_t * world = ecs_mini ();
43664485
0 commit comments