From 56113cd1de3e98f285e1e100f082a028181622e8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 23 Nov 2017 23:05:19 -0500 Subject: [PATCH] Fixed bugs with router clogging and save loading --- core/src/io/anuke/mindustry/ai/Pathfind.java | 7 ------- core/src/io/anuke/mindustry/ui/LoadDialog.java | 8 ++++++-- .../world/blocks/types/distribution/Conveyor.java | 10 +++++----- .../world/blocks/types/distribution/Router.java | 5 ++++- .../io/anuke/mindustry/desktop/DesktopLauncher.java | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/io/anuke/mindustry/ai/Pathfind.java b/core/src/io/anuke/mindustry/ai/Pathfind.java index 646c8a7f12..c276ccdb0a 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfind.java +++ b/core/src/io/anuke/mindustry/ai/Pathfind.java @@ -92,13 +92,6 @@ public class Pathfind{ } } - //TODO make this work? - /* - PathFinderRequest request = new PathFinderRequest(); - request.startNode = World.spawnpoints.get(0); - request.endNode = World.core; - passpathfinder.search(request, 1000); */ - for(int i = 0; i < paths.size; i ++){ SmoothGraphPath path = paths.get(i); diff --git a/core/src/io/anuke/mindustry/ui/LoadDialog.java b/core/src/io/anuke/mindustry/ui/LoadDialog.java index 0dccf8e5a7..26b874ad68 100644 --- a/core/src/io/anuke/mindustry/ui/LoadDialog.java +++ b/core/src/io/anuke/mindustry/ui/LoadDialog.java @@ -76,13 +76,17 @@ public class LoadDialog extends FloatingDialog{ hide(); try{ SaveIO.loadFromSlot(slot); + GameState.set(State.playing); + Vars.ui.hideMenu(); }catch(Exception e){ e.printStackTrace(); + Vars.ui.hideMenu(); + GameState.set(State.menu); + Vars.control.reset(); Vars.ui.showError("[orange]Save file corrupted or invalid!"); return; } - Vars.ui.hideMenu(); - GameState.set(State.playing); + } }, 3f/60f); } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java index d24acf8dac..c3ccc55a11 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Conveyor.java @@ -79,14 +79,14 @@ public class Conveyor extends Block{ for(int j = 0; j < entity.convey.size; j ++){ ItemPos other = pos2.set(entity.convey.get(j)); - if(other.y > pos.y && other.y - pos.y < 0.14){ + if(other.y > pos.y && other.y - pos.y < 0.14 * Timers.delta()){ canmove = false; break; } } if(canmove){ - pos.y += speed * Timers.delta(); + pos.y += Math.max(speed * Timers.delta(), 1f/252f); //TODO fix precision issues? pos.x = MathUtils.lerp(pos.x, 0, 0.06f * Timers.delta()); }else{ pos.x = MathUtils.lerp(pos.x, pos.seed/128f/3f, 0.1f * Timers.delta()); @@ -138,7 +138,7 @@ public class Conveyor extends Block{ * Conveyor data format: * [0] item ordinal * [1] x: byte ranging from -128 to 127, scaled should be at [-1, 1], corresponds to relative X from the conveyor middle - * [2] y: byte ranging from 0 to 127, scaled should be at [0, 1], corresponds to relative Y from the conveyor start + * [2] y: byte ranging from -128 to 127, scaled should be at [0, 1], corresponds to relative Y from the conveyor start * [3] seed: -128 to 127, unscaled * Size is 4 bytes, or one int. */ @@ -178,7 +178,7 @@ public class Conveyor extends Block{ byte[] values = Bits.getBytes(value); item = items[values[0]]; x = values[1] / 127f; - y = ((int)values[2]) / 127f; + y = ((int)values[2] + 128) / 255f; seed = values[3]; return this; } @@ -191,7 +191,7 @@ public class Conveyor extends Block{ byte[] bytes = Bits.getBytes(0); bytes[0] = (byte)item.ordinal(); bytes[1] = (byte)(x*127); - bytes[2] = (byte)(y*127); + bytes[2] = (byte)(y*255-128); bytes[3] = seed; //UCore.log("Packing item: ", item, x, y, seed, "\n", Arrays.toString(bytes)); //UCore.log(Arrays.toString(Bits.getBytes(Bits.packInt(bytes)))); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Router.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Router.java index 8b8f5afe95..f667ad8efd 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/distribution/Router.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/Router.java @@ -9,6 +9,7 @@ import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Timers; +import io.anuke.ucore.util.Mathf; public class Router extends Block{ private ObjectMap lastmap = new ObjectMap<>(); @@ -34,8 +35,10 @@ public class Router extends Block{ @Override public void update(Tile tile){ if(Timers.get(tile, "dump", 2) && tile.entity.totalItems() > 0){ - if(lastmap.get(tile, (byte)-1) != tile.rotation) + if(lastmap.get(tile, (byte)-1) != tile.rotation + || Mathf.chance(0.3)){ //sometimes dump backwards at a 1/4 chance... this somehow works? tryDump(tile, tile.rotation, null); + } tile.rotation ++; tile.rotation %= 4; diff --git a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java index 9eadf7daa9..a66e2a34a1 100644 --- a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java @@ -17,7 +17,7 @@ public class DesktopLauncher { Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setTitle("Mindustry"); config.setMaximized(true); - //config.useVsync(false); + config.useVsync(false); config.setWindowedMode(800, 600); config.setWindowIcon("sprites/icon.png");