I’ve been checking out your source for the 4k games, and I’m interested in this game loop technique.
long lastLoopTime = System.currentTimeMillis();
while (true)
{
int delta = (int) (System.currentTimeMillis() - lastLoopTime);
for (int i=0;i<delta/10;i++) {
logic(10);
}
logic(delta % 10);
lastLoopTime = System.currentTimeMillis();
draw((Graphics2D) strategy.getDrawGraphics());
strategy.show();
if (!isVisible()) {
System.exit(0);
}
}
Why do you call logic() inside that for-loop, and also after the for-loop. Aren’t you calling the logic() way too often, and hence slowing down the game? Isn’t it better to calculate the delta argument to pass to logic(delta) instead of calling logic() n-times? Like this:
int diff = 0;
for (int i=0;i<delta/10;i++) {
diff+=10;
}
logic((delta % 10) + diff);
??
Are there any better ways to keep the game logic at a static speed, independent from framerate? I’m not too familiar with this concept.


