Timing of loop is now based on accumulated time

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 d6b17fce95
commit 5e97719ccf
  1. BIN
      bin/RabiClone.jar
  2. 11
      src/sig/RabiClone.java

Binary file not shown.

@ -84,14 +84,16 @@ public class RabiClone{
p.render(); p.render();
long lastGameTime = System.nanoTime(); long lastGameTime = System.nanoTime();
long dt = 0;
CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers(); CONTROLLERS = ControllerEnvironment.getDefaultEnvironment().getControllers();
while (true) { while (true) {
long timePassed = System.nanoTime()-lastGameTime; dt += System.nanoTime()-lastGameTime;
lastGameTime=System.nanoTime(); lastGameTime=System.nanoTime();
double updateMult = Math.min(1/120d,timePassed/1000000000d);
while (dt>=(1/244d)*1000000000) {
double updateMult = 1/244d;
handleGameControllers(); handleGameControllers();
KeyBind.poll(); KeyBind.poll();
@ -127,6 +129,11 @@ public class RabiClone{
OBJ.remove(i--); OBJ.remove(i--);
} }
} }
dt-=(1/244d)*1000000000;
}
if (dt<0) {
dt=0;
}
} }
} }

Loading…
Cancel
Save