I was looking at notch's game loop and i can't understand what is the meaning of unprocessedTime variable.
long now = System.nanoTime();
unprocessedTime += now - lastTime;
lastTime = now;
I would be really grateful if someone could explain me the difference between the two variables.Thanks
public void run() {
requestFocus();
Image image = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
setScreen(new TitleScreen(this));
long lastTime = System.nanoTime();
long unprocessedTime = 0;
[b] try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}[/b]
while (running) {
Graphics g = image.getGraphics();
long now = System.nanoTime();
unprocessedTime += now - lastTime;
lastTime = now;
int max = 10;
[b]while (unprocessedTime > 0) {
unprocessedTime -= 1000000000 / 60;
fps = unprocessedTime;
screen.update(input);
input.update();
if (max-- == 0) {
unprocessedTime = 0;
break;
}
}[/b]
screen.render(g);
g.dispose();
try {
started = true;
g = getGraphics();
g.drawImage(image, 0, 0, GAME_WIDTH * SCREEN_SCALE, GAME_HEIGHT * SCREEN_SCALE, 0, 0, GAME_WIDTH, GAME_HEIGHT, null);
g.dispose();
} catch (Throwable e) {
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}