Fixed incorrect fps cap

This commit is contained in:
Anuken 2019-07-03 13:00:57 -04:00
parent 5799e6f567
commit 5036c57372
3 changed files with 11 additions and 30 deletions

View File

@ -60,27 +60,6 @@ public class Mindustry extends ApplicationCore{
setup();
}
@Override
public void update(){
long lastFrameTime = Time.nanos();
super.update();
int fpsCap = Core.settings.getInt("fpscap", 125);
if(fpsCap <= 120){
long target = (1000 * 1000000) / fpsCap; //target in nanos
long elapsed = Time.timeSinceNanos(lastFrameTime);
if(elapsed < target){
try{
Thread.sleep((target - elapsed) / 1000000, (int)((target - elapsed) % 1000000));
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
void drawLoading(){
Core.graphics.clear(Color.BLACK);
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());

View File

@ -172,9 +172,15 @@ public class SettingsMenuDialog extends SettingsDialog{
}
});
graphics.sliderPref("fpscap", 125, 5, 125, 5, s -> (s > 120 ? Core.bundle.get("setting.fpscap.none") : Core.bundle.format("setting.fpscap.text", s)));
graphics.sliderPref("fpscap", 125, 5, 125, 5,
s -> {
Core.app.setTargetFPS(s > 120 ? -1 : s);
return (s > 120 ? Core.bundle.get("setting.fpscap.none") : Core.bundle.format("setting.fpscap.text", s));
});
graphics.sliderPref("chatopacity", 100, 0, 100, 5, s -> s + "%");
Core.app.setTargetFPS(Core.settings.getInt("fpscap", 125) > 120 ? -1 : Core.settings.getInt("fpscap"));
if(!mobile){
graphics.checkPref("vsync", true, b -> Core.graphics.setVSync(b));
graphics.checkPref("fullscreen", false, b -> {

View File

@ -28,7 +28,6 @@ public class PowerNode extends PowerBlock{
private static int lastPlaced = -1;
protected Vector2 t1 = new Vector2();
protected Vector2 t2 = new Vector2();
protected TextureRegion laser, laserEnd;
protected float laserRange = 6;
@ -212,7 +211,7 @@ public class PowerNode extends PowerBlock{
for(int i = 0; i < entity.power.links.size; i++){
Tile link = world.tile(entity.power.links.get(i));
if(link != null){
if(link != null && (link.pos() < tile.pos() || !Core.camera.bounds(Tmp.r1).contains(tile.drawx(), tile.drawy()))){
drawLaser(tile, link);
}
}
@ -245,25 +244,22 @@ public class PowerNode extends PowerBlock{
}
protected void drawLaser(Tile tile, Tile target){
float x1 = tile.drawx(), y1 = tile.drawy(),
x2 = target.drawx(), y2 = target.drawy();
float angle1 = Angles.angle(x1, y1, x2, y2);
float angle2 = angle1 + 180f;
t1.trns(angle1, tile.block().size * tilesize / 2f - 1.5f);
t2.trns(angle2, target.block().size * tilesize / 2f - 1.5f);
x1 += t1.x;
y1 += t1.y;
x2 += t2.x;
y2 += t2.y;
x2 -= t1.x;
y2 -= t1.y;
Draw.color(Pal.powerLight, Color.WHITE, Mathf.absin(Time.time(), 8f, 0.3f) + 0.2f);
//Lines.stroke(2f);
//Lines.line(x1, y1, x2, y2);
Lines.stroke(3f);
Lines.stroke(1f);
Lines.line(x1, y1, x2, y2);
Draw.reset();