Consider this Game Loop:
double nextTime = (double)System.nanoTime() / 1000000000.0;
while(runFlag)
{
double currTime = (double)System.nanoTime() / 1000000000.0;
if(currTime >= nextTime)
{
nextTime += delta;
update();
draw();
}
else
{
int sleepTime = (int)(1000.0 * (nextTime - currTime));
if(sleepTime > 0)
{
try
{
Thread.sleep(sleepTime);
}
catch(InterruptedException e)
{
}
How should I calculate an appropriate value of delta (the time that has to pass before the next update and render). I have seen it been calculated different ways but I am still not sure how or what exactly is really going on. This is a fixed time step loop, so for instance if i wanted to calculate delta for a constant fps of 30 of 60, what would I have to set it as and why? I am unable to grasp some of the explanations I have come across on the Internet. Thanks.