@@ -5903,3 +5903,157 @@ void NonFragmentingChildOf_instantiate_parent_w_has_in_hook(void) {
59035903
59045904 ecs_fini (world );
59055905}
5906+
5907+ void NonFragmentingChildOf_add_prefab_tag_after_hierarchy_creation (void ) {
5908+ ecs_world_t * world = ecs_mini ();
5909+
5910+ ecs_entity_t mom = ecs_new (world );
5911+ ecs_entity_t daughter = ecs_new (world );
5912+ ecs_entity_t granddaughter = ecs_new (world );
5913+
5914+ ecs_add_id (world , mom , EcsOrderedChildren );
5915+ ecs_add_id (world , daughter , EcsOrderedChildren );
5916+
5917+ ecs_set (world , daughter , EcsParent , {mom });
5918+ ecs_set (world , granddaughter , EcsParent , {daughter });
5919+
5920+ ecs_add_id (world , mom , EcsPrefab );
5921+
5922+ ecs_entity_t a = ecs_new (world );
5923+ ecs_add_pair (world , a , EcsIsA , mom );
5924+
5925+ {
5926+ ecs_entities_t children = ecs_get_ordered_children (world , a );
5927+ test_int (children .count , 1 );
5928+ ecs_entity_t a_child = children .ids [0 ];
5929+ test_assert (ecs_has_pair (world , a_child , EcsIsA , daughter ));
5930+ test_int (ecs_get_target (world , a_child , EcsParentDepth , 0 ), 1 );
5931+
5932+ ecs_entities_t gchildren = ecs_get_ordered_children (world , a_child );
5933+ test_int (gchildren .count , 1 );
5934+ ecs_entity_t a_gchild = gchildren .ids [0 ];
5935+ test_assert (ecs_has_pair (world , a_gchild , EcsIsA , granddaughter ));
5936+ test_int (ecs_get_target (world , a_gchild , EcsParentDepth , 0 ), 2 );
5937+ }
5938+
5939+ ecs_fini (world );
5940+ }
5941+
5942+ void NonFragmentingChildOf_defer_add_prefab_tag_after_hierarchy_creation (void ) {
5943+ ecs_world_t * world = ecs_mini ();
5944+
5945+ ecs_entity_t mom = ecs_new (world );
5946+ ecs_entity_t daughter = ecs_new (world );
5947+ ecs_entity_t granddaughter = ecs_new (world );
5948+
5949+ ecs_add_id (world , mom , EcsOrderedChildren );
5950+ ecs_add_id (world , daughter , EcsOrderedChildren );
5951+
5952+ ecs_set (world , daughter , EcsParent , {mom });
5953+ ecs_set (world , granddaughter , EcsParent , {daughter });
5954+
5955+ ecs_add_id (world , mom , EcsPrefab );
5956+
5957+ ecs_defer_begin (world );
5958+ ecs_entity_t a = ecs_new (world );
5959+ ecs_add_pair (world , a , EcsIsA , mom );
5960+ ecs_defer_end (world );
5961+
5962+ {
5963+ ecs_entities_t children = ecs_get_ordered_children (world , a );
5964+ test_int (children .count , 1 );
5965+ ecs_entity_t a_child = children .ids [0 ];
5966+ test_assert (ecs_has_pair (world , a_child , EcsIsA , daughter ));
5967+ test_int (ecs_get_target (world , a_child , EcsParentDepth , 0 ), 1 );
5968+
5969+ ecs_entities_t gchildren = ecs_get_ordered_children (world , a_child );
5970+ test_int (gchildren .count , 1 );
5971+ ecs_entity_t a_gchild = gchildren .ids [0 ];
5972+ test_assert (ecs_has_pair (world , a_gchild , EcsIsA , granddaughter ));
5973+ test_int (ecs_get_target (world , a_gchild , EcsParentDepth , 0 ), 2 );
5974+ }
5975+
5976+ ecs_fini (world );
5977+ }
5978+
5979+ void NonFragmentingChildOf_add_prefab_tag_after_hierarchy_creation_2 (void ) {
5980+ ecs_world_t * world = ecs_mini ();
5981+
5982+ ECS_TAG (world , Foo );
5983+ ECS_TAG (world , Bar );
5984+
5985+ ecs_entity_t mom = ecs_new (world );
5986+ ecs_entity_t daughter = ecs_new_w (world , Foo );
5987+ ecs_entity_t granddaughter = ecs_new_w (world , Bar );
5988+
5989+ ecs_add_id (world , mom , EcsOrderedChildren );
5990+ ecs_add_id (world , daughter , EcsOrderedChildren );
5991+
5992+ ecs_set (world , daughter , EcsParent , {mom });
5993+ ecs_set (world , granddaughter , EcsParent , {daughter });
5994+
5995+ ecs_add_id (world , mom , EcsPrefab );
5996+
5997+ ecs_entity_t a = ecs_new (world );
5998+ ecs_add_pair (world , a , EcsIsA , mom );
5999+
6000+ {
6001+ ecs_entities_t children = ecs_get_ordered_children (world , a );
6002+ test_int (children .count , 1 );
6003+ ecs_entity_t a_child = children .ids [0 ];
6004+ test_assert (ecs_has_pair (world , a_child , EcsIsA , daughter ));
6005+ test_assert (ecs_has (world , a_child , Foo ));
6006+ test_int (ecs_get_target (world , a_child , EcsParentDepth , 0 ), 1 );
6007+
6008+ ecs_entities_t gchildren = ecs_get_ordered_children (world , a_child );
6009+ test_int (gchildren .count , 1 );
6010+ ecs_entity_t a_gchild = gchildren .ids [0 ];
6011+ test_assert (ecs_has_pair (world , a_gchild , EcsIsA , granddaughter ));
6012+ test_assert (ecs_has (world , a_gchild , Bar ));
6013+ test_int (ecs_get_target (world , a_gchild , EcsParentDepth , 0 ), 2 );
6014+ }
6015+
6016+ ecs_fini (world );
6017+ }
6018+
6019+ void NonFragmentingChildOf_defer_add_prefab_tag_after_hierarchy_creation_2 (void ) {
6020+ ecs_world_t * world = ecs_mini ();
6021+
6022+ ECS_TAG (world , Foo );
6023+ ECS_TAG (world , Bar );
6024+
6025+ ecs_entity_t mom = ecs_new (world );
6026+ ecs_entity_t daughter = ecs_new_w (world , Foo );
6027+ ecs_entity_t granddaughter = ecs_new_w (world , Bar );
6028+
6029+ ecs_add_id (world , mom , EcsOrderedChildren );
6030+ ecs_add_id (world , daughter , EcsOrderedChildren );
6031+
6032+ ecs_set (world , daughter , EcsParent , {mom });
6033+ ecs_set (world , granddaughter , EcsParent , {daughter });
6034+
6035+ ecs_add_id (world , mom , EcsPrefab );
6036+
6037+ ecs_defer_begin (world );
6038+ ecs_entity_t a = ecs_new (world );
6039+ ecs_add_pair (world , a , EcsIsA , mom );
6040+ ecs_defer_end (world );
6041+
6042+ {
6043+ ecs_entities_t children = ecs_get_ordered_children (world , a );
6044+ test_int (children .count , 1 );
6045+ ecs_entity_t a_child = children .ids [0 ];
6046+ test_assert (ecs_has_pair (world , a_child , EcsIsA , daughter ));
6047+ test_assert (ecs_has (world , a_child , Foo ));
6048+ test_int (ecs_get_target (world , a_child , EcsParentDepth , 0 ), 1 );
6049+
6050+ ecs_entities_t gchildren = ecs_get_ordered_children (world , a_child );
6051+ test_int (gchildren .count , 1 );
6052+ ecs_entity_t a_gchild = gchildren .ids [0 ];
6053+ test_assert (ecs_has_pair (world , a_gchild , EcsIsA , granddaughter ));
6054+ test_assert (ecs_has (world , a_gchild , Bar ));
6055+ test_int (ecs_get_target (world , a_gchild , EcsParentDepth , 0 ), 2 );
6056+ }
6057+
6058+ ecs_fini (world );
6059+ }
0 commit comments