Game should be running with highest potential game loop setting

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent b5e5e1c611
commit d6b17fce95
  1. BIN
      bin/RabiClone.jar
  2. 20
      src/sig/RabiClone.java

Binary file not shown.

@ -89,7 +89,7 @@ public class RabiClone{
while (true) {
long timePassed = System.nanoTime()-lastGameTime;
lastGameTime=System.nanoTime();
double updateMult = 1/120d;
double updateMult = Math.min(1/120d,timePassed/1000000000d);
handleGameControllers();
@ -127,8 +127,6 @@ public class RabiClone{
OBJ.remove(i--);
}
}
waitForNextFrame();
}
}
@ -169,20 +167,4 @@ public class RabiClone{
}
f.setSize(f.getWidth()*SIZE_MULTIPLIER,(int)((f.getWidth()*SIZE_MULTIPLIER)/1.77777777778d));
}
private static void waitForNextFrame() {
long newTime = System.nanoTime();
if (newTime-lastUpdate<TARGET_FRAMETIME) {
long timeRemaining=TARGET_FRAMETIME-(newTime-lastUpdate);
long millis = timeRemaining/1000000l;
int nanos = (int)(timeRemaining-millis*1000000l);
//System.out.println(timeRemaining+"/"+millis+" Nanos:"+nanos);
try {
Thread.sleep(millis,nanos);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
lastUpdate=newTime;
}
}

Loading…
Cancel
Save