@@ -1806,6 +1806,91 @@ static void Run_w_query_next(ecs_iter_t *it) {
18061806 run_invoked ++ ;
18071807}
18081808
1809+ static
1810+ uint64_t SystemMisc_group_by_rel (
1811+ ecs_world_t * world ,
1812+ ecs_table_t * table ,
1813+ ecs_id_t id ,
1814+ void * ctx )
1815+ {
1816+ (void )ctx ;
1817+
1818+ ecs_id_t match ;
1819+ if (ecs_search (world , table , ecs_pair (id , EcsWildcard ), & match ) != -1 ) {
1820+ return ECS_PAIR_SECOND (match );
1821+ }
1822+
1823+ return 0 ;
1824+ }
1825+
1826+ static
1827+ uint64_t system_misc_expected_group ;
1828+
1829+ static
1830+ void SystemMisc_grouped_dummy (ecs_iter_t * it ) {
1831+ test_uint (ecs_iter_get_group (it ), system_misc_expected_group );
1832+ probe_iter (it );
1833+ }
1834+
1835+ static
1836+ void SystemMisc_reset_probe (Probe * ctx ) {
1837+ ecs_os_zeromem (ctx );
1838+ }
1839+
1840+ void SystemMisc_set_group (void ) {
1841+ ecs_world_t * world = ecs_init ();
1842+
1843+ ecs_entity_t Rel = ecs_entity (world , {0 });
1844+ ecs_entity_t TgtA = ecs_entity (world , {0 });
1845+ ecs_entity_t TgtB = ecs_entity (world , {0 });
1846+ ecs_entity_t TgtC = ecs_entity (world , {0 });
1847+ ECS_TAG (world , Tag );
1848+
1849+ ecs_entity_t e1 = ecs_new_w_pair (world , Rel , TgtA );
1850+ ecs_entity_t e2 = ecs_new_w_pair (world , Rel , TgtB );
1851+ ecs_new_w_pair (world , Rel , TgtC );
1852+ ecs_entity_t e4 = ecs_new_w_pair (world , Rel , TgtA );
1853+ ecs_entity_t e5 = ecs_new_w_pair (world , Rel , TgtB );
1854+ ecs_entity_t e6 = ecs_new_w_pair (world , Rel , TgtC );
1855+
1856+ ecs_add (world , e4 , Tag );
1857+ ecs_add (world , e5 , Tag );
1858+ ecs_add (world , e6 , Tag );
1859+
1860+ Probe ctx = {0 };
1861+ ecs_set_ctx (world , & ctx , NULL );
1862+
1863+ ecs_entity_t system = ecs_system_init (world , & (ecs_system_desc_t ){
1864+ .query .terms = {{ .id = ecs_pair (Rel , EcsWildcard ) }},
1865+ .query .group_by = Rel ,
1866+ .query .group_by_callback = SystemMisc_group_by_rel ,
1867+ .callback = SystemMisc_grouped_dummy
1868+ });
1869+ test_assert (system != 0 );
1870+
1871+ system_misc_expected_group = TgtB ;
1872+ ecs_system_set_group (world , system , TgtB );
1873+ ecs_run (world , system , 0 , NULL );
1874+
1875+ test_int (ctx .invoked , 2 );
1876+ test_int (ctx .count , 2 );
1877+ probe_has_entity (& ctx , e2 );
1878+ probe_has_entity (& ctx , e5 );
1879+
1880+ SystemMisc_reset_probe (& ctx );
1881+
1882+ system_misc_expected_group = TgtA ;
1883+ ecs_system_set_group (world , system , TgtA );
1884+ ecs_run (world , system , 0 , NULL );
1885+
1886+ test_int (ctx .invoked , 2 );
1887+ test_int (ctx .count , 2 );
1888+ probe_has_entity (& ctx , e1 );
1889+ probe_has_entity (& ctx , e4 );
1890+
1891+ ecs_fini (world );
1892+ }
1893+
18091894void SystemMisc_run_w_query_next (void ) {
18101895 ecs_world_t * world = ecs_init ();
18111896
0 commit comments