From 31f9bb513b6f3ee5779c39503a28cf9f3e1e022d Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 9 Jun 2022 16:33:45 -0500 Subject: [PATCH] Game update system now respects frame update time Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- src/sig/RabiClone.java | 14 +++++++++----- src/sig/objects/Player.java | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sig/RabiClone.java b/src/sig/RabiClone.java index 2936810..83fe252 100644 --- a/src/sig/RabiClone.java +++ b/src/sig/RabiClone.java @@ -92,8 +92,8 @@ public class RabiClone{ lastGameTime=System.nanoTime(); - while (dt>=(1/244d)*1000000000) { - double updateMult = 1/244d; + while (dt>=(1/244d)*1000000000l) { + final double updateMult = 1/244d; handleGameControllers(); KeyBind.poll(); @@ -129,10 +129,14 @@ public class RabiClone{ OBJ.remove(i--); } } - dt-=(1/244d)*1000000000; + dt-=(1/244d)*1000000000l; } - if (dt<0) { - dt=0; + if (dt<(1/244d)*1000000000l) { + lastReportedTime=System.currentTimeMillis(); + } else + if (System.currentTimeMillis()-lastReportedTime>5000) { + System.out.println("WARNING! Game is lagging behind! Frames Behind: "+(dt/((1/244d)*1000000000l))); + lastReportedTime=System.currentTimeMillis(); } } } diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index d8125c8..d44c1ea 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -395,6 +395,7 @@ public class Player extends AnimatedObject{ groundCollision=true; collisionOccured=true; state = State.IDLE; + break; } } if (!collisionOccured) {