From 2558bf8258c5f9c2ad43cd1b301c12801a29bdae Mon Sep 17 00:00:00 2001 From: Gulum Date: Wed, 18 Oct 2017 21:07:58 +0200 Subject: [PATCH] test --- core/src/com/darkrp2d/DarkRP2D.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/src/com/darkrp2d/DarkRP2D.java b/core/src/com/darkrp2d/DarkRP2D.java index c531302..f6e9bc5 100755 --- a/core/src/com/darkrp2d/DarkRP2D.java +++ b/core/src/com/darkrp2d/DarkRP2D.java @@ -16,6 +16,7 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; import com.badlogic.gdx.physics.box2d.World; +import com.badlogic.gdx.utils.TimeUtils; import com.darkrp2d.entities.components.TextureComponent; import com.darkrp2d.entities.entityListeners.DisposeListener; @@ -50,21 +51,23 @@ public class DarkRP2D extends Game { camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); b2dbr = new Box2DDebugRenderer(); - //must be before input registration or no character found + //must be before input registration or no controllable Entity found engine.addEntity(com.darkrp2d.entities.Character.create(this)); //Sets inputs Gdx.input.setInputProcessor(new InputHandler(this)); } //GameLoop and debug - private double lag = 0.; + private float accumulator = 0; + private float skippedFrames = 0; private static final int UPDATES_PER_SECOND = 60; - private static final double MS_PER_UPDATE = 1e3/UPDATES_PER_SECOND; + private static final float MS_PER_UPDATE = 1f / UPDATES_PER_SECOND; + private static final int MAX_FRAMESKIP = 5; // Make 5 updates mostly without a render @Override // GameLoop public void render () { - lag += Gdx.graphics.getRawDeltaTime() * 1e3; //Seconds to milliseconds + accumulator += Gdx.graphics.getDeltaTime(); //Seconds to milliseconds //Process Input Command currentCommand = CommandStream.pollCommand(); @@ -72,10 +75,13 @@ public class DarkRP2D extends Game { currentCommand.execute(); } + skippedFrames = 0; + //Update Stuff - while(lag >= MS_PER_UPDATE) { - update(1.f/UPDATES_PER_SECOND); - lag -= MS_PER_UPDATE; + while(accumulator >= MS_PER_UPDATE && skippedFrames <= MAX_FRAMESKIP) { + accumulator -= MS_PER_UPDATE; + update(MS_PER_UPDATE); + skippedFrames++; } trueRender();