Here is my gameloop (taken from http://www.koonsolo.com/news/dewitters-gameloop/) which is supposed to limit the game (logic) updates to 60 per seconds and render as fast as the device allows:
long nextGameTick = System.currentTimeMillis();
int loops;
final int maxFrameskip =5;
final int ticksPerSecond = 60;
final int skipTicks = 1000 / ticksPerSecond;
float dt = 1f/ticksPerSecond;
int ticks;
long secondCount;
onDrawFrame{
//This loop will limit the logic update to defined value and render flat out
loops = 0;
while( System.currentTimeMillis() > nextGameTick && loops < maxFrameskip){
updateLogic();
//Update nextGameTic by adding skipTicks value to it, ready for next comparison
nextGameTick += skipTicks;
//Update loops value ready for next comparison in while loop
loops++;
ticks++;
}
//Once thses conditions are no longer true, exit while loop and render
render();
if (System.currentTimeMillis()>secondCount+1000){
Log.v("Blocks","Ticks this second:"+ticks);
secondCount = 0;
ticks=0;
}
}
However, when I run this, I'm getting anywhere between 62 and 65 as you can see from my logcat output:
So, the loop doesn't do what it's supposed to.