@@ -6165,3 +6165,128 @@ void Toggle_toggle_0_src(void) {
61656165
61666166 ecs_fini (world );
61676167}
6168+
6169+ static
6170+ void Toggle_or_toggle_count_matches (ecs_iter_t * it ) {
6171+ int32_t * match_count = it -> ctx ;
6172+ * match_count += it -> count ;
6173+ }
6174+
6175+ static
6176+ ecs_entity_t Toggle_or_toggle_setup (
6177+ ecs_world_t * world ,
6178+ int32_t * match_count )
6179+ {
6180+ ECS_COMPONENT (world , Position );
6181+ ECS_COMPONENT (world , Velocity );
6182+ ECS_COMPONENT (world , Mass );
6183+ ECS_TAG (world , HasChangedPosition );
6184+ ECS_TAG (world , HasChangedRotation );
6185+ ECS_TAG (world , HasChangedScale );
6186+
6187+ ecs_add_id (world , HasChangedPosition , EcsCanToggle );
6188+ ecs_add_id (world , HasChangedRotation , EcsCanToggle );
6189+ ecs_add_id (world , HasChangedScale , EcsCanToggle );
6190+
6191+ ecs_system (world , {
6192+ .query .terms = {
6193+ { .id = ecs_id (Position ) },
6194+ { .id = ecs_id (Velocity ) },
6195+ { .id = ecs_id (Mass ) },
6196+ { .id = HasChangedPosition },
6197+ { .id = HasChangedRotation , .oper = EcsOr },
6198+ { .id = HasChangedScale , .oper = EcsOr }
6199+ },
6200+ .query .cache_kind = cache_kind ,
6201+ .callback = Toggle_or_toggle_count_matches ,
6202+ .ctx = match_count
6203+ });
6204+
6205+ ecs_entity_t e = ecs_entity (world , { .name = "e" });
6206+ ecs_set (world , e , Position , {10 , 20 });
6207+ ecs_set (world , e , Velocity , {1 , 2 });
6208+ ecs_set (world , e , Mass , 3 );
6209+ ecs_add (world , e , HasChangedPosition );
6210+ ecs_add (world , e , HasChangedRotation );
6211+ ecs_add (world , e , HasChangedScale );
6212+
6213+ ecs_enable_id (world , e , HasChangedPosition , false);
6214+ ecs_enable_id (world , e , HasChangedRotation , false);
6215+ ecs_enable_id (world , e , HasChangedScale , false);
6216+
6217+ return e ;
6218+ }
6219+
6220+ void Toggle_or_toggle_first_branch_matches (void ) {
6221+ ecs_world_t * world = ecs_mini ();
6222+ int32_t match_count = 0 ;
6223+ ecs_entity_t e = Toggle_or_toggle_setup (world , & match_count );
6224+
6225+ ecs_progress (world , 0 );
6226+ test_int (0 , match_count );
6227+
6228+ match_count = 0 ;
6229+ ecs_enable_id (world , e , HasChangedPosition , true);
6230+ ecs_progress (world , 0 );
6231+ test_int (1 , match_count );
6232+
6233+ ecs_fini (world );
6234+ }
6235+
6236+ void Toggle_or_toggle_second_branch_matches (void ) {
6237+ ecs_world_t * world = ecs_mini ();
6238+ int32_t match_count = 0 ;
6239+ ecs_entity_t e = Toggle_or_toggle_setup (world , & match_count );
6240+
6241+ ecs_progress (world , 0 );
6242+ test_int (0 , match_count );
6243+
6244+ match_count = 0 ;
6245+ ecs_enable_id (world , e , HasChangedRotation , true);
6246+ ecs_progress (world , 0 );
6247+ test_int (1 , match_count );
6248+
6249+ ecs_fini (world );
6250+ }
6251+
6252+ void Toggle_or_toggle_third_branch_matches (void ) {
6253+ ecs_world_t * world = ecs_mini ();
6254+ int32_t match_count = 0 ;
6255+ ecs_entity_t e = Toggle_or_toggle_setup (world , & match_count );
6256+
6257+ ecs_progress (world , 0 );
6258+ test_int (0 , match_count );
6259+
6260+ match_count = 0 ;
6261+ ecs_enable_id (world , e , HasChangedScale , true);
6262+ ecs_progress (world , 0 );
6263+ test_int (1 , match_count );
6264+
6265+ ecs_fini (world );
6266+ }
6267+
6268+ void Toggle_or_toggle_all_branches_match_once (void ) {
6269+ ecs_world_t * world = ecs_mini ();
6270+ int32_t match_count = 0 ;
6271+ ecs_entity_t e = Toggle_or_toggle_setup (world , & match_count );
6272+
6273+ ecs_enable_id (world , e , HasChangedPosition , true);
6274+ ecs_enable_id (world , e , HasChangedRotation , true);
6275+ ecs_enable_id (world , e , HasChangedScale , true);
6276+
6277+ ecs_progress (world , 0 );
6278+ test_int (1 , match_count );
6279+
6280+ ecs_fini (world );
6281+ }
6282+
6283+ void Toggle_or_toggle_no_branches_match (void ) {
6284+ ecs_world_t * world = ecs_mini ();
6285+ int32_t match_count = 0 ;
6286+ Toggle_or_toggle_setup (world , & match_count );
6287+
6288+ ecs_progress (world , 0 );
6289+ test_int (0 , match_count );
6290+
6291+ ecs_fini (world );
6292+ }
0 commit comments