From 5036c5737299837db5833def89ef3dd76ba5987b Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 3 Jul 2019 13:00:57 -0400 Subject: [PATCH] Fixed incorrect fps cap --- core/src/io/anuke/mindustry/Mindustry.java | 21 ------------------- .../ui/dialogs/SettingsMenuDialog.java | 8 ++++++- .../world/blocks/power/PowerNode.java | 12 ++++------- 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/core/src/io/anuke/mindustry/Mindustry.java b/core/src/io/anuke/mindustry/Mindustry.java index e5de1aee0b..8b6d33603f 100644 --- a/core/src/io/anuke/mindustry/Mindustry.java +++ b/core/src/io/anuke/mindustry/Mindustry.java @@ -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()); diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java index d4d7eaf152..bc5d77c384 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -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 -> { diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index 0e7044d983..f1ec09884d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -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();