From 7b8de91b8c5786ee36680da924a4aa814acec09f Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 20 Dec 2017 22:06:36 -0500 Subject: [PATCH] Add vSync, fix multiple bugs --- core/src/io/anuke/mindustry/Vars.java | 2 +- core/src/io/anuke/mindustry/core/UI.java | 11 ++--- .../mindustry/entities/enemies/Enemy.java | 44 ++++--------------- core/src/io/anuke/mindustry/world/Block.java | 2 + .../blocks/types/distribution/Junction.java | 3 -- 5 files changed, 15 insertions(+), 47 deletions(-) diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index ab3e403cdd..8cb39dbe34 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -40,7 +40,7 @@ public class Vars{ //how much the zoom changes every zoom button press public static final int zoomScale = Math.round(Unit.dp.scl(1)); //if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available - public static boolean debug = false; + public static boolean debug = true; //whether the player can clip through walls public static boolean noclip = false; //whether to draw chunk borders diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index a6b4abe249..e33403e723 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -163,13 +163,7 @@ public class UI extends SceneModule{ configtable = new Table(); scene.add(configtable); - try { - editorDialog = new MapEditorDialog(editor); - }catch (Exception e){ - Timers.run(1f, () -> { - showErrorClose("[orange]Error occurred loading editor![]Are you running from a zip file?\n"); - }); - } + editorDialog = new MapEditorDialog(editor); settingserror = new Dialog("Warning", "dialog"); settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved."); @@ -210,6 +204,7 @@ public class UI extends SceneModule{ prefs.volumePrefs(); prefs.checkPref("fps", "Show FPS", false); + prefs.checkPref("vsync", "VSync", true, b -> Gdx.graphics.setVSync(b)); prefs.checkPref("noshadows", "Disable shadows", false); prefs.checkPref("smoothcam", "Smooth Camera", true); prefs.checkPref("indicators", "Enemy Indicators", true); @@ -226,6 +221,8 @@ public class UI extends SceneModule{ } renderer.setPixelate(b); }); + + Gdx.graphics.setVSync(Settings.getBool("vsync")); prefs.hidden(()->{ if(!GameState.is(State.menu)){ diff --git a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java index 6b7fbfbfc6..fc8a6e5f7f 100644 --- a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java +++ b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java @@ -9,6 +9,7 @@ import io.anuke.mindustry.entities.*; import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.world.Tile; +import io.anuke.ucore.UCore; import io.anuke.ucore.core.*; import io.anuke.ucore.entities.*; import io.anuke.ucore.util.*; @@ -152,41 +153,6 @@ public class Enemy extends DestructibleEntity{ Bullet out = new Bullet(bullet, this, x + Angles.x(), y + Angles.y(), this.angle + rotation).add(); out.damage = (int) (damage * Vars.multiplier); } - - /* - public void findClosestNode(){ - int index = 0; - int cindex = -1; - float dst = Float.MAX_VALUE; - UCore.log("Finding closest."); - - Tile[] clone = path.clone(); - UCore.log(clone.length); - - //find closest node index - for(Tile tile : path){ - if(Vector2.dst(tile.worldx(), tile.worldy(), x, y) < dst){ - dst = Vector2.dst(tile.worldx(), tile.worldy(), x, y); - cindex = index; - } - - index++; - } - - cindex = Math.max(cindex, 1); - - //set node to that index - node = cindex; - - int x2 = path[node].x, y2 = path[node].y; - - //if the enemy can't move to that node right now, set its position to it - if(Vars.world.raycast(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize), x2, y2) != null){ - Timers.run(Mathf.random(15f), () -> { - set(x2 * Vars.tilesize, y2 * Vars.tilesize); - }); - } - }*/ @Override public void added(){ @@ -240,7 +206,7 @@ public class Enemy extends DestructibleEntity{ float minv = 0.07f; - if(xvelocity < minv && yvelocity < minv && node > 0 && target == null){ + if(Math.abs(xvelocity) < minv && Math.abs(yvelocity) < minv && node > 0 && target == null){ idletime += Timers.delta(); }else{ idletime = 0; @@ -271,8 +237,14 @@ public class Enemy extends DestructibleEntity{ if(Vars.showPaths){ Draw.color(Color.PURPLE); Draw.line(x, y, x + xvelocity*10f, y + yvelocity*10f); + + Draw.color(Color.BLACK, Color.WHITE, idletime / maxIdleLife); + Draw.square(x, y, 7f); + Draw.color(); } + + Draw.color(); Graphics.flush(); } diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index b31605ef2f..3c522e063c 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -155,6 +155,7 @@ public class Block{ tile.setDump((byte)((i+1)%4)); return; } + tiles = tile.getNearby(); i++; i %= 4; } @@ -191,6 +192,7 @@ public class Block{ } } } + tiles = tile.getNearby(); i++; i %= 4; } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Junction.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Junction.java index e1983c338a..8bbfb3bf6b 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Junction.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Junction.java @@ -23,8 +23,6 @@ public class Junction extends Block{ public void handleItem(Item item, Tile tile, Tile source){ int dir = source.relativeTo(tile.x, tile.y); Tile to = tile.getNearby()[dir]; - - UCore.log("handling to " + to + " from " + source + ", tile = " + tile); Timers.run(15, ()->{ if(to == null || to.entity == null) return; @@ -38,7 +36,6 @@ public class Junction extends Block{ int dir = source.relativeTo(dest.x, dest.y); if(dir == -1) return false; Tile to = dest.getNearby()[dir]; - UCore.log("outputting to " + to + " " + to.block().acceptItem(item, to, dest) + " from " + source); return to != null && to.block().acceptItem(item, to, dest); }