I have a while loop with a switch statement:
while(true) {
switch(state) {
case LOADING :
//THIS IS THE IMPORTANT PART
//view loading screen (already set by default)
contentPane.repaint();
if(tick == 400000) {
//state = GameState.MENU;
System.out.println("Reached " + gameTick);
}
break;
case MENU :
//view menu
break;
//some other cases without content, left them out here
}
tick++;
if(tick < 400000) {
System.out.println(tick);
}
if(tick == Long.MAX_VALUE) {
tick = 0;
}
}
Now this code executes just fine, it shows the loading screen (which has moving dots on it for as long as it's repaint is repeatedly called, so I know exactly when it stops), and the output counts from 1 to 400000 and on that number prints
399998
399999
Reached 400000
(last 3 lines of output)
The application goes fullscreen, and when I alt+tab out, the counter is usually somewhere around 130K, and I watch it move to 400K.
However, if I remove the if statement that prints this number:
if(tick < 400000) {
System.out.println(tick);
}
The loading screen never moves, and when I alt + tab out, the 400K is already reached.
Also curious is that the loading screen has three 'appearance changes', one at 100 calls of it's paintComponent method, one at 200 calls and one at 300 calls, which resets the counter to 0. So basically, every 100 ticks it's supposed to have an appearance change. In the first case, with the if-statement, which has longer execution time, I see the changes but by far not as frequently as I'd expect. In the second case, I don't see them at all (I can imagine they'd happen too fast).
So my question is, what creates this quite big difference in execution time, and what causes the difference in the amount of times the paintComponent method seems to be called, and the 400.000 times the loop iterates?
All ideas appreceated.