22
33import com .github .elebras1 .flecs .*;
44import com .github .elebras1 .flecs .examples .components .Minister ;
5+ import com .github .elebras1 .flecs .examples .components .MinisterView ;
56import com .github .elebras1 .flecs .util .FlecsConstants ;
67
78import java .util .Random ;
@@ -18,22 +19,18 @@ public static void main(String[] args) {
1819 world .obtainEntity (world .entity ("Min_" + i )).set (new Minister ("M-" + i , "default.png" , rnd .nextFloat () * 50 , 2020 , 0 ));
1920 }
2021
21- world .system ("LoyaltySystem" )
22- .with (Minister .class )
23- .kind (FlecsConstants .EcsOnUpdate )
24- .multiThreaded (true )
25- .iter (it -> {
26- int count = it .count ();
27- for (int i = 0 ; i < count ; i ++) {
28- float loyalty = it .fieldFloat (Minister .class , 0 , "loyalty" , i );
29-
30- float newLoyalty = Math .min (loyalty + 10.0f , 100.0f );
31- String newImg = newLoyalty > 50 ? "happy.png" : "angry.png" ;
32-
33- it .setFieldFloat (Minister .class , 0 , "loyalty" , i , newLoyalty );
34- it .setFieldString (Minister .class , 0 , "imageFileName" , i , newImg );
35- }
36- });
22+ world .system ("LoyaltySystem" ).with (Minister .class ).kind (FlecsConstants .EcsOnUpdate ).multiThreaded (true ).iter (it -> {
23+ Field <Minister > ministerField = it .field (Minister .class , 0 );
24+ for (int i = 0 ; i < it .count (); i ++) {
25+ MinisterView ministerView = ministerField .getMutView (i );
26+
27+ float newLoyalty = Math .min (ministerView .loyalty () + 10.0f , 100.0f );
28+ String newImg = newLoyalty > 50 ? "happy.png" : "angry.png" ;
29+
30+ ministerView .loyalty (newLoyalty );
31+ ministerView .imageFileName (newImg );
32+ }
33+ });
3734
3835 for (int f = 0 ; f < 5 ; f ++) {
3936 world .progress (0.016f );
0 commit comments