public static void main(String[] args) {
long newTime, delta, timeSince1Second, startTime, oldTime;
long ticks = 0;
double frameCap = 1000/60;
double time_passed = 0;
startTime = System.currentTimeMillis();
oldTime = System.currentTimeMillis();
while(true)
{
newTime = System.currentTimeMillis();
delta = newTime - oldTime;
timeSince1Second = newTime - startTime;
currentTime = newTime;
//update game based on dynamic time step here (if needed)
//update loop (fixed time step)
while(time_passed >= frameCap)
{
//update game logic (fixed time step update)
time_passed = time_passed - frameCap; //resetting time_passed essentially to 0
ticks++;
}
time_passed = time_passed + (double) delta; //time passed since start of loop
//render here
//frame rate counter
if((timeSince1Second/1000) >= 1)
{
System.out.println(ticks+" frames per second");
startTime = System.currentTimeMillis();
ticks = 0;
}
}
} //end main function
This code has been written in java. I'd like to know if i'm missing anything here, because in the fixed time step update loop, if i display for example a window, and move the window around, the framerate will sometimes change until i stop moving the window around, which is kind of confusing to me. Is that normal? Or perhaps I might be missing something Guidance will be appreciated