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.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();
|
||||
|
||||
Reference in New Issue
Block a user