diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index baa361eaf6..e36dca5715 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -102,7 +102,7 @@ public class Logic extends Module { @Override public void update(){ - if(!doUpdate) return; + if(threads.isEnabled() && !threads.isOnThread()) return; if(!state.is(State.menu)){ diff --git a/core/src/io/anuke/mindustry/core/ThreadHandler.java b/core/src/io/anuke/mindustry/core/ThreadHandler.java index 1a7f7dec04..2c16f19007 100644 --- a/core/src/io/anuke/mindustry/core/ThreadHandler.java +++ b/core/src/io/anuke/mindustry/core/ThreadHandler.java @@ -111,6 +111,10 @@ public class ThreadHandler { return enabled; } + public boolean isOnThread(){ + return impl.isOnThread(); + } + private void runLogic(){ try { while (true) { diff --git a/core/src/io/anuke/mindustry/graphics/FloorRenderer.java b/core/src/io/anuke/mindustry/graphics/FloorRenderer.java index ee8028f284..951eba6220 100644 --- a/core/src/io/anuke/mindustry/graphics/FloorRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/FloorRenderer.java @@ -39,6 +39,9 @@ public class FloorRenderer { } public void drawFloor(){ + if(cache == null){ + return; + } OrthographicCamera camera = Core.camera; @@ -103,6 +106,10 @@ public class FloorRenderer { } public void beginDraw(){ + if(cache == null){ + return; + } + cbatch.setProjectionMatrix(Core.camera.combined); cbatch.beginDraw(); @@ -110,10 +117,18 @@ public class FloorRenderer { } public void endDraw(){ + if(cache == null){ + return; + } + cbatch.endDraw(); } public void drawLayer(CacheLayer layer){ + if(cache == null){ + return; + } + OrthographicCamera camera = Core.camera; int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1; diff --git a/server/src/io/anuke/mindustry/server/mapgen/GenProperties.java b/core/src/io/anuke/mindustry/world/mapgen/GenProperties.java similarity index 85% rename from server/src/io/anuke/mindustry/server/mapgen/GenProperties.java rename to core/src/io/anuke/mindustry/world/mapgen/GenProperties.java index b419102b2b..88a00e6709 100644 --- a/server/src/io/anuke/mindustry/server/mapgen/GenProperties.java +++ b/core/src/io/anuke/mindustry/world/mapgen/GenProperties.java @@ -1,8 +1,7 @@ -package io.anuke.mindustry.server.mapgen; +package io.anuke.mindustry.world.mapgen; public class GenProperties { public long seed; - public SpawnStyle spawns; public MapStyle maps; public OreStyle ores; public RiverType riverType; @@ -11,15 +10,6 @@ public class GenProperties { public FoliageStyle foliage; public EnvironmentStyle environment; - enum SpawnStyle{ - /**spawn in a wide arc with branching paths*/ - arc, - /**spawn in one big group*/ - grouped, - /**surround player spawn*/ - surround - } - enum MapStyle{ /**256x512*/ longY, diff --git a/core/src/io/anuke/mindustry/world/mapgen/ProcGen.java b/core/src/io/anuke/mindustry/world/mapgen/ProcGen.java new file mode 100644 index 0000000000..2c76069821 --- /dev/null +++ b/core/src/io/anuke/mindustry/world/mapgen/ProcGen.java @@ -0,0 +1,20 @@ +package io.anuke.mindustry.world.mapgen; + +import io.anuke.mindustry.io.MapTileData; +import io.anuke.ucore.noise.RidgedPerlin; +import io.anuke.ucore.noise.Simplex; + +public class ProcGen { + public RidgedPerlin rid = new RidgedPerlin(1, 1); + public Simplex sim = new Simplex(); + + public MapTileData generate(GenProperties props){ + MapTileData data = new MapTileData(300, 300); + for (int x = 0; x < data.width(); x++) { + for (int y = 0; y < data.height(); y++) { + + } + } + return null; + } +} diff --git a/server/src/io/anuke/mindustry/server/mapgen/Colorizer.java b/server/src/io/anuke/mindustry/server/mapgen/Colorizer.java deleted file mode 100644 index f0f141b481..0000000000 --- a/server/src/io/anuke/mindustry/server/mapgen/Colorizer.java +++ /dev/null @@ -1,109 +0,0 @@ -package io.anuke.mindustry.server.mapgen; - -import com.badlogic.gdx.files.FileHandle; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.Pixmap; -import com.badlogic.gdx.graphics.PixmapIO; -import com.badlogic.gdx.utils.Array; -import com.badlogic.gdx.utils.IntIntMap; -import com.badlogic.gdx.utils.IntSet; -import io.anuke.ucore.util.Mathf; - -public class Colorizer { - Color tmp = new Color(); - float[] hsv1 = new float[3]; - float[] hsv2 = new float[3]; - float target = 240f; - float shift = 12f; - float e = 0.05f; - - public void process(FileHandle in, FileHandle out){ - for(FileHandle child : in.list()){ - if(child.isDirectory()){ - process(child, out); - }else if(child.extension().equals("png")){ - PixmapIO.writePNG(out.child(child.name()), colorize(new Pixmap(child))); - } - } - } - - public Pixmap colorize(Pixmap pixmap){ - Array> colors = new Array<>(); - IntSet used = new IntSet(); - - for(int x = 0; x < pixmap.getWidth(); x ++){ - for(int y = 0; y < pixmap.getHeight(); y ++){ - tmp.set(pixmap.getPixel(x, y)); - - if(tmp.a <= 0.1f || used.contains(Color.rgba8888(tmp))) continue; - - used.add(Color.rgba8888(tmp)); - - boolean found = false; - - outer: - for(Array arr : colors){ - for(Color color : arr){ - if(isSameShade(color, tmp)){ - arr.add(tmp.cpy()); - found = true; - break outer; - } - } - } - - if(!found){ - colors.add(Array.with(tmp.cpy())); - } - } - } - - colors.forEach(a -> a.sort((c1, c2) -> Float.compare(c1.toHsv(hsv1)[2], c2.toHsv(hsv2)[2]))); - - IntIntMap map = new IntIntMap(); - - for(Array arr : colors){ - for(int i = 0; i < arr.size; i ++){ - int shift = arr.size - 1 - i; - map.put(Color.rgba8888(arr.get(i)), Color.rgba8888(shift(arr.get(i), shift))); - } - } - - Pixmap result = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), pixmap.getFormat()); - - for(int x = 0; x < pixmap.getWidth(); x ++) { - for (int y = 0; y < pixmap.getHeight(); y++) { - result.drawPixel(x, y, map.get(pixmap.getPixel(x, y), 0)); - } - } - - return result; - } - - Color shift(Color color, int amount){ - color.toHsv(hsv1); - float h = hsv1[0]; - /*if(hsv1[1] < e){ - hsv1[1] += amount * 0.1f; - h = Mathf.lerp(0f, target, amount * 0.08f); - }*/ - float s = amount * shift; - if(Math.abs(h - target) < s){ - h = target; - }else{ - if(h > target) h -= s; - if(h < target) h += s; - } - hsv1[0] = h; - tmp.fromHsv(hsv1); - tmp.a = color.a; - return tmp; - } - - boolean isSameShade(Color a, Color b){ - a.toHsv(hsv1); - b.toHsv(hsv2); - - return Mathf.near(hsv1[0], hsv2[0], e*360f) && Mathf.near(hsv1[1], hsv2[1], e); - } -} diff --git a/server/src/io/anuke/mindustry/server/mapgen/MapImage.java b/server/src/io/anuke/mindustry/server/mapgen/MapImage.java deleted file mode 100644 index 54e2987913..0000000000 --- a/server/src/io/anuke/mindustry/server/mapgen/MapImage.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.anuke.mindustry.server.mapgen; - -import com.badlogic.gdx.graphics.Pixmap; -import com.badlogic.gdx.graphics.Pixmap.Format; -import io.anuke.mindustry.world.Block; -import io.anuke.mindustry.world.ColorMapper; -import io.anuke.mindustry.world.ColorMapper.BlockPair; -import io.anuke.ucore.util.Mathf; - -public class MapImage { - public final Pixmap pixmap; - public final int width, height; - - public MapImage(Pixmap pixmap){ - this.pixmap = pixmap; - this.width = pixmap.getWidth(); - this.height = pixmap.getHeight(); - } - - public MapImage(int width, int height){ - this(new Pixmap(width, height, Format.RGBA8888)); - } - - public Block wall(int x, int y){ - BlockPair pair = ColorMapper.get(pixmap.getPixel(x, y)); - return pair.wall; - } - - public Block floor(int x, int y){ - BlockPair pair = ColorMapper.get(pixmap.getPixel(x, y)); - return pair.floor; - } - - public void set(int x, int y, Block block){ - pixmap.drawPixel(x, y, ColorMapper.getColor(block)); - } - - public Block get(int x, int y){ - BlockPair pair = ColorMapper.get(pixmap.getPixel(x, y)); - return pair.dominant(); - } - - public boolean solid(int x, int y){ - BlockPair pair = ColorMapper.get(pixmap.getPixel(x, y)); - return pair.dominant().solid; - } - - public boolean has(int x, int y){ - return Mathf.inBounds(x, y, width, height); - } - - public int pack(int x, int y){ - return x + y*width; - } -} diff --git a/server/src/io/anuke/mindustry/server/mapgen/MapPathfinder.java b/server/src/io/anuke/mindustry/server/mapgen/MapPathfinder.java deleted file mode 100644 index bc5d30db92..0000000000 --- a/server/src/io/anuke/mindustry/server/mapgen/MapPathfinder.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.anuke.mindustry.server.mapgen; - -import com.badlogic.gdx.ai.pfa.Connection; -import com.badlogic.gdx.ai.pfa.DefaultGraphPath; -import com.badlogic.gdx.ai.pfa.Heuristic; -import com.badlogic.gdx.ai.pfa.indexed.IndexedAStarPathFinder; -import com.badlogic.gdx.ai.pfa.indexed.IndexedGraph; -import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.utils.Array; -import io.anuke.mindustry.world.Block; -import io.anuke.ucore.util.Geometry; - -public class MapPathfinder { - private IndexedGraph graph = new MapGraph(); - private DefaultGraphPath path = new DefaultGraphPath<>(); - private IndexedAStarPathFinder finder = new IndexedAStarPathFinder<>(graph); - private Heuristic heuristic; - private MapImage image; - - public Array find(int startx, int starty, int endx, int endy, Evaluator eval){ - finder.searchNodePath(image.pack(startx, starty), image.pack(endx, endy), - (heuristic = (node, endNode) -> - eval.cost(image.get(node % image.width, node / image.width), - node % image.width, - node / image.width)), path); - - Array arr = new Array<>(); - - for(int i : path.nodes){ - arr.add(new GridPoint2(i % image.width, i / image.width)); - } - - return arr; - } - - private class MapGraph extends DefaultGraphPath implements IndexedGraph{ - private Array> cons = new Array<>(); - - @Override - public int getIndex(Integer node) { - return node; - } - - @Override - public int getNodeCount() { - return image.width * image.height; - } - - @Override - public Array> getConnections(Integer fromNode) { - int x = fromNode % image.width; - int y = fromNode / image.width; - cons.clear(); - for(GridPoint2 p : Geometry.d4){ - if(image.has(x + p.x, y + p.y)){ - cons.add(new MapConnection(fromNode, image.pack(x + p.x, y + p.y))); - } - } - return cons; - } - } - - private class MapConnection implements Connection{ - int from, to; - - MapConnection(int from, int to){ - this.from = from; - this.to = to; - } - - @Override - public float getCost() { - return heuristic.estimate(from, to); - } - - @Override - public Integer getFromNode() { - return from; - } - - @Override - public Integer getToNode() { - return to; - } - } - - interface Evaluator{ - int cost(Block block, int x, int y); - } -} diff --git a/server/src/io/anuke/mindustry/server/mapgen/ProcGen.java b/server/src/io/anuke/mindustry/server/mapgen/ProcGen.java deleted file mode 100644 index 160d327f19..0000000000 --- a/server/src/io/anuke/mindustry/server/mapgen/ProcGen.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.anuke.mindustry.server.mapgen; - -import io.anuke.mindustry.io.Map; -import io.anuke.ucore.noise.RidgedPerlin; -import io.anuke.ucore.noise.Simplex; - -public class ProcGen { - public RidgedPerlin rid = new RidgedPerlin(1, 1); - public Simplex sim = new Simplex(); - - public Map generate(GenProperties props){ - return null; - } -}