test
This commit is contained in:
@@ -16,6 +16,7 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.math.Matrix4;
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
|
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
|
||||||
import com.badlogic.gdx.physics.box2d.World;
|
import com.badlogic.gdx.physics.box2d.World;
|
||||||
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
|
|
||||||
import com.darkrp2d.entities.components.TextureComponent;
|
import com.darkrp2d.entities.components.TextureComponent;
|
||||||
import com.darkrp2d.entities.entityListeners.DisposeListener;
|
import com.darkrp2d.entities.entityListeners.DisposeListener;
|
||||||
@@ -50,21 +51,23 @@ public class DarkRP2D extends Game {
|
|||||||
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
b2dbr = new Box2DDebugRenderer();
|
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));
|
engine.addEntity(com.darkrp2d.entities.Character.create(this));
|
||||||
//Sets inputs
|
//Sets inputs
|
||||||
Gdx.input.setInputProcessor(new InputHandler(this));
|
Gdx.input.setInputProcessor(new InputHandler(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
//GameLoop and debug
|
//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 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
|
@Override
|
||||||
// GameLoop
|
// GameLoop
|
||||||
public void render () {
|
public void render () {
|
||||||
lag += Gdx.graphics.getRawDeltaTime() * 1e3; //Seconds to milliseconds
|
accumulator += Gdx.graphics.getDeltaTime(); //Seconds to milliseconds
|
||||||
|
|
||||||
//Process Input
|
//Process Input
|
||||||
Command currentCommand = CommandStream.pollCommand();
|
Command currentCommand = CommandStream.pollCommand();
|
||||||
@@ -72,10 +75,13 @@ public class DarkRP2D extends Game {
|
|||||||
currentCommand.execute();
|
currentCommand.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skippedFrames = 0;
|
||||||
|
|
||||||
//Update Stuff
|
//Update Stuff
|
||||||
while(lag >= MS_PER_UPDATE) {
|
while(accumulator >= MS_PER_UPDATE && skippedFrames <= MAX_FRAMESKIP) {
|
||||||
update(1.f/UPDATES_PER_SECOND);
|
accumulator -= MS_PER_UPDATE;
|
||||||
lag -= MS_PER_UPDATE;
|
update(MS_PER_UPDATE);
|
||||||
|
skippedFrames++;
|
||||||
}
|
}
|
||||||
|
|
||||||
trueRender();
|
trueRender();
|
||||||
|
|||||||
Reference in New Issue
Block a user