我很难理解一段控制游戏循环的代码......我无法理解这个while循环“while(unprocessedSeconds> secondsForEachTick)”的目的以及为什么FPS计数器在里面if(tickCounter % 60 ==0) 代码如下:
public void run()
{
int frames = 0;
double unprocessedSeconds = 0;
long previousTime = System.nanoTime();
double secondsForEachTick = 1/60.0;
int tickCount = 0; //RENDER COUNTER
boolean ticked = false;
while (running)
{
long currentTime = System.nanoTime();
long passedTime = currentTime - previousTime;
previousTime = currentTime;
unprocessedSeconds = unprocessedSeconds + passedTime / 1000000000.0;
int count = 0;
while(unprocessedSeconds > secondsForEachTick)
{
tick();
count++;
unprocessedSeconds -= secondsForEachTick;
ticked = true;
tickCount++;
if(tickCount % 60 == 0){
System.out.println(frames + " fps");
previousTime += 1000;
frames = 0;
}
}
System.out.println("Iterações do loop: "+count);
if(ticked)
{
render();
frames++;
ticked = false;
}
}
}