@@ -6165,3 +6165,119 @@ void Toggle_toggle_0_src(void) {
61656165
61666166 ecs_fini (world );
61676167}
6168+
6169+ static
6170+ int32_t toggle_or_match_count (
6171+ ecs_world_t * world ,
6172+ ecs_query_t * q )
6173+ {
6174+ int32_t count = 0 ;
6175+ ecs_iter_t it = ecs_query_iter (world , q );
6176+ while (ecs_query_next (& it )) {
6177+ count += it .count ;
6178+ }
6179+ return count ;
6180+ }
6181+
6182+ void Toggle_or_chain_3_toggleable_tags (void ) {
6183+ ecs_world_t * world = ecs_mini ();
6184+
6185+ ECS_TAG (world , TagA );
6186+ ECS_TAG (world , TagB );
6187+ ECS_TAG (world , TagC );
6188+
6189+ ecs_add_id (world , TagA , EcsCanToggle );
6190+ ecs_add_id (world , TagB , EcsCanToggle );
6191+ ecs_add_id (world , TagC , EcsCanToggle );
6192+
6193+ ecs_entity_t e = ecs_new_w_id (world , TagA );
6194+ ecs_add (world , e , TagB );
6195+ ecs_add (world , e , TagC );
6196+
6197+ ecs_enable_id (world , e , TagA , false);
6198+ ecs_enable_id (world , e , TagB , false);
6199+ ecs_enable_id (world , e , TagC , false);
6200+
6201+ ecs_query_t * q = ecs_query (world , {
6202+ .terms = {
6203+ { .id = TagA , .oper = EcsOr },
6204+ { .id = TagB , .oper = EcsOr },
6205+ { .id = TagC }
6206+ },
6207+ .cache_kind = cache_kind
6208+ });
6209+ test_assert (q != NULL );
6210+
6211+ test_int (toggle_or_match_count (world , q ), 0 );
6212+
6213+ ecs_enable_id (world , e , TagA , true);
6214+ test_int (toggle_or_match_count (world , q ), 1 );
6215+
6216+ ecs_enable_id (world , e , TagA , false);
6217+ ecs_enable_id (world , e , TagB , true);
6218+ test_int (toggle_or_match_count (world , q ), 1 );
6219+
6220+ ecs_enable_id (world , e , TagB , false);
6221+ ecs_enable_id (world , e , TagC , true);
6222+ test_int (toggle_or_match_count (world , q ), 1 );
6223+
6224+ ecs_enable_id (world , e , TagA , true);
6225+ ecs_enable_id (world , e , TagB , true);
6226+ test_int (toggle_or_match_count (world , q ), 1 );
6227+
6228+ ecs_query_fini (q );
6229+
6230+ ecs_fini (world );
6231+ }
6232+
6233+ void Toggle_or_chain_3_toggleable_components (void ) {
6234+ ecs_world_t * world = ecs_mini ();
6235+
6236+ ECS_COMPONENT (world , Position );
6237+ ECS_COMPONENT (world , Velocity );
6238+ ECS_COMPONENT (world , Mass );
6239+
6240+ ecs_add_id (world , ecs_id (Position ), EcsCanToggle );
6241+ ecs_add_id (world , ecs_id (Velocity ), EcsCanToggle );
6242+ ecs_add_id (world , ecs_id (Mass ), EcsCanToggle );
6243+
6244+ ecs_entity_t e = ecs_new_w (world , Position );
6245+ ecs_set (world , e , Position , {10 , 20 });
6246+ ecs_set (world , e , Velocity , {1 , 2 });
6247+ ecs_set (world , e , Mass , {100 });
6248+
6249+ ecs_enable_component (world , e , Position , false);
6250+ ecs_enable_component (world , e , Velocity , false);
6251+ ecs_enable_component (world , e , Mass , false);
6252+
6253+ ecs_query_t * q = ecs_query (world , {
6254+ .terms = {
6255+ { .id = ecs_id (Position ), .oper = EcsOr },
6256+ { .id = ecs_id (Velocity ), .oper = EcsOr },
6257+ { .id = ecs_id (Mass ) }
6258+ },
6259+ .cache_kind = cache_kind
6260+ });
6261+ test_assert (q != NULL );
6262+
6263+ test_int (toggle_or_match_count (world , q ), 0 );
6264+
6265+ ecs_enable_component (world , e , Position , true);
6266+ test_int (toggle_or_match_count (world , q ), 1 );
6267+
6268+ ecs_enable_component (world , e , Position , false);
6269+ ecs_enable_component (world , e , Velocity , true);
6270+ test_int (toggle_or_match_count (world , q ), 1 );
6271+
6272+ ecs_enable_component (world , e , Velocity , false);
6273+ ecs_enable_component (world , e , Mass , true);
6274+ test_int (toggle_or_match_count (world , q ), 1 );
6275+
6276+ ecs_enable_component (world , e , Position , true);
6277+ ecs_enable_component (world , e , Velocity , true);
6278+ test_int (toggle_or_match_count (world , q ), 1 );
6279+
6280+ ecs_query_fini (q );
6281+
6282+ ecs_fini (world );
6283+ }
0 commit comments