Been trying my hand lately in programming in Perl. Doing some database things with it. It’s quite an interesting language. I’m rather enjoying it, if I’m being honest. Coming from a Java background, I find it exciting to learn new things and take them as they come to me. It’s fun for sure!
Found this gameloop somewhere, probably on the internet of course. Maybe YouTube? I can't remember. Putting it here so I can use it later:
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int updates = 0;
int frames = 0;
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1){
tick();
updates++;
delta--;
}
render();
frames++;
if(System.currentTimeMillis() - timer > 1000){
timer += 1000;
System.out.println("FPS: " + frames + " TICKS: " + updates);
frames = 0;
updates = 0;
}
}
Comments
Post a Comment