diff --git a/core/assets-raw/sprites/blocks/environment/grassedge.png b/core/assets-raw/sprites/blocks/environment/grassedge.png index 32b6f87c0f..eadc1f3b14 100644 Binary files a/core/assets-raw/sprites/blocks/environment/grassedge.png and b/core/assets-raw/sprites/blocks/environment/grassedge.png differ diff --git a/core/assets/version.properties b/core/assets/version.properties index d4b118d25d..fbb060eb9f 100644 --- a/core/assets/version.properties +++ b/core/assets/version.properties @@ -1,7 +1,7 @@ #Autogenerated file. Do not modify. -#Tue Apr 17 19:48:06 EDT 2018 +#Tue Apr 17 22:18:27 EDT 2018 version=release -androidBuildCode=947 +androidBuildCode=962 name=Mindustry code=3.5 build=custom build diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 91b4b82930..0c568586a5 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -27,6 +27,7 @@ import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.input.InputHandler; import io.anuke.mindustry.input.PlaceMode; import io.anuke.mindustry.ui.fragments.ToolFragment; +import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.BlockBar; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.*; @@ -106,6 +107,10 @@ public class Renderer extends RendererModule{ clearColor.a = 1f; background.setWrap(TextureWrap.Repeat, TextureWrap.Repeat); + + for(Block block : Block.getAllBlocks()){ + block.load(); + } } @Override @@ -141,7 +146,7 @@ public class Renderer extends RendererModule{ } if(state.is(State.menu)){ - clearScreen(); + Graphics.clear(Color.BLACK); }else{ boolean smoothcam = Settings.getBool("smoothcam"); @@ -190,8 +195,8 @@ public class Renderer extends RendererModule{ @Override public void draw(){ camera.update(); - - clearScreen(clearColor); + + Graphics.clear(clearColor); batch.setProjectionMatrix(camera.combined); diff --git a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java index 141ba61a03..c8773b430d 100644 --- a/core/src/io/anuke/mindustry/graphics/BlockRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/BlockRenderer.java @@ -1,22 +1,13 @@ package io.anuke.mindustry.graphics; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.types.StaticBlock; -import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Graphics; -import io.anuke.ucore.core.Timers; -import io.anuke.ucore.graphics.CacheBatch; import io.anuke.ucore.graphics.Draw; -import io.anuke.ucore.graphics.Lines; -import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Mathf; import java.util.Arrays; @@ -27,9 +18,8 @@ import static io.anuke.ucore.core.Core.camera; public class BlockRenderer{ private final static int chunksize = 32; private final static int initialRequests = 32*32; - - private int[][][] cache; - private CacheBatch cbatch; + + private FloorRenderer floorRenderer; private Array requests = new Array(initialRequests); private Layer lastLayer; @@ -37,6 +27,8 @@ public class BlockRenderer{ private int iterateidx = 0; public BlockRenderer(){ + floorRenderer = new FloorRenderer(); + for(int i = 0; i < requests.size; i ++){ requests.set(i, new BlockRequest()); } @@ -113,7 +105,7 @@ public class BlockRenderer{ Draw.color(); Graphics.end(); - drawCache(DrawLayer.walls, crangex, crangey); + floorRenderer.drawCache(DrawLayer.walls, crangex, crangey); Graphics.begin(); Arrays.sort(requests.items, 0, requestidx); @@ -182,6 +174,14 @@ public class BlockRenderer{ } } + public void clearTiles(){ + floorRenderer.clearTiles(); + } + + public void drawFloor(){ + floorRenderer.drawFloor(); + } + private void layerBegins(Layer layer){} private void layerEnds(Layer layer){} @@ -198,118 +198,4 @@ public class BlockRenderer{ r.layer = layer; requestidx ++; } - - public void drawFloor(){ - int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize; - - //render the entire map - if(cache == null || cache.length != chunksx || cache[0].length != chunksy){ - cache = new int[chunksx][chunksy][DrawLayer.values().length]; - - Timers.markNs(); - - for(DrawLayer layer : DrawLayer.values()){ - for(int x = 0; x < chunksx; x++){ - for(int y = 0; y < chunksy; y++){ - cacheChunk(x, y, layer); - } - } - } - - Log.info("CACHING ELAPSED: {0}", Timers.elapsedNs()); - } - - OrthographicCamera camera = Core.camera; - - if(Graphics.drawing()) Graphics.end(); - - int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1; - int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1; - - DrawLayer[] layers = DrawLayer.values(); - - for(int i = 0; i < layers.length - 1; i ++) { - drawCache(layers[i], crangex, crangey); - } - - Graphics.begin(); - - Draw.reset(); - - if(debug && debugChunks){ - Draw.color(Color.YELLOW); - Lines.stroke(1f); - for(int x = -crangex; x <= crangex; x++){ - for(int y = -crangey; y <= crangey; y++){ - int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; - int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y; - - if(!Mathf.inBounds(worldx, worldy, cache)) - continue; - Lines.rect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize); - } - } - Draw.reset(); - } - } - - void drawCache(DrawLayer layer, int crangex, int crangey){ - Gdx.gl.glEnable(GL20.GL_BLEND); - - layer.begin(cbatch); - - for(int x = -crangex; x <= crangex; x++){ - for(int y = -crangey; y <= crangey; y++){ - int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; - int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y; - - if(!Mathf.inBounds(worldx, worldy, cache)) - continue; - - cbatch.drawCache(cache[worldx][worldy][layer.ordinal()]); - } - } - - layer.end(cbatch); - } - - void cacheChunk(int cx, int cy, DrawLayer layer){ - if(cbatch == null){ - createBatch(); - } - - cbatch.begin(); - Graphics.useBatch(cbatch); - - for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){ - for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){ - Tile tile = world.tile(tilex, tiley); - if(tile == null) continue; - - if(tile.floor().drawLayer == layer && tile.block().drawLayer != DrawLayer.walls){ - tile.floor().draw(tile); - }else if(tile.floor().drawLayer.ordinal() < layer.ordinal() && tile.block().drawLayer != DrawLayer.walls){ - tile.floor().drawNonLayer(tile); - } - - if(tile.block().drawLayer == layer && layer == DrawLayer.walls){ - tile.block().draw(tile); - } - } - } - Graphics.popBatch(); - cbatch.end(); - cache[cx][cy][layer.ordinal()] = cbatch.getLastCache(); - } - - public void clearTiles(){ - cache = null; - createBatch(); - } - - private void createBatch(){ - if(cbatch != null) - cbatch.dispose(); - cbatch = new CacheBatch(world.width() * world.height() * 4); - } } diff --git a/core/src/io/anuke/mindustry/graphics/FloorRenderer.java b/core/src/io/anuke/mindustry/graphics/FloorRenderer.java new file mode 100644 index 0000000000..283950eea3 --- /dev/null +++ b/core/src/io/anuke/mindustry/graphics/FloorRenderer.java @@ -0,0 +1,144 @@ +package io.anuke.mindustry.graphics; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import io.anuke.mindustry.world.Tile; +import io.anuke.ucore.core.Core; +import io.anuke.ucore.core.Graphics; +import io.anuke.ucore.core.Timers; +import io.anuke.ucore.graphics.CacheBatch; +import io.anuke.ucore.graphics.Draw; +import io.anuke.ucore.graphics.Lines; +import io.anuke.ucore.util.Log; +import io.anuke.ucore.util.Mathf; + +import static io.anuke.mindustry.Vars.*; +import static io.anuke.ucore.core.Core.camera; + +public class FloorRenderer { + private final static int chunksize = 32; + + private int[][][] cache; + private CacheBatch cbatch; + + public FloorRenderer(){ + + } + + public void drawFloor(){ + int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize; + + //render the entire map + if(cache == null || cache.length != chunksx || cache[0].length != chunksy){ + cache = new int[chunksx][chunksy][DrawLayer.values().length]; + + Timers.markNs(); + + for(DrawLayer layer : DrawLayer.values()){ + for(int x = 0; x < chunksx; x++){ + for(int y = 0; y < chunksy; y++){ + cacheChunk(x, y, layer); + } + } + } + + Log.info("CACHING ELAPSED: {0}", Timers.elapsedNs()); + } + + OrthographicCamera camera = Core.camera; + + if(Graphics.drawing()) Graphics.end(); + + int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1; + int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1; + + DrawLayer[] layers = DrawLayer.values(); + + for(int i = 0; i < layers.length - 1; i ++) { + drawCache(layers[i], crangex, crangey); + } + + Graphics.begin(); + + Draw.reset(); + + if(debug && debugChunks){ + Draw.color(Color.YELLOW); + Lines.stroke(1f); + for(int x = -crangex; x <= crangex; x++){ + for(int y = -crangey; y <= crangey; y++){ + int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; + int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y; + + if(!Mathf.inBounds(worldx, worldy, cache)) + continue; + Lines.rect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize); + } + } + Draw.reset(); + } + } + + void drawCache(DrawLayer layer, int crangex, int crangey){ + + Gdx.gl.glEnable(GL20.GL_BLEND); + + layer.begin(cbatch); + + for(int x = -crangex; x <= crangex; x++){ + for(int y = -crangey; y <= crangey; y++){ + int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; + int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y; + + if(!Mathf.inBounds(worldx, worldy, cache)) + continue; + + cbatch.drawCache(cache[worldx][worldy][layer.ordinal()]); + } + } + + layer.end(cbatch); + } + + void cacheChunk(int cx, int cy, DrawLayer layer){ + if(cbatch == null){ + createBatch(); + } + + cbatch.begin(); + Graphics.useBatch(cbatch); + + for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){ + for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){ + Tile tile = world.tile(tilex, tiley); + if(tile == null) continue; + + if(tile.floor().drawLayer == layer && tile.block().drawLayer != DrawLayer.walls){ + tile.floor().draw(tile); + }else if(tile.floor().drawLayer.ordinal() < layer.ordinal() && tile.block().drawLayer != DrawLayer.walls){ + tile.floor().drawNonLayer(tile); + } + + if(tile.block().drawLayer == layer && layer == DrawLayer.walls){ + tile.block().draw(tile); + } + } + } + Graphics.popBatch(); + cbatch.end(); + cache[cx][cy][layer.ordinal()] = cbatch.getLastCache(); + } + + public void clearTiles(){ + cache = null; + createBatch(); + } + + private void createBatch(){ + if(cbatch != null) + cbatch.dispose(); + cbatch = new CacheBatch(world.width() * world.height() * 4); + } +} diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 078a040ddc..fcf6b2cb39 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -27,9 +27,7 @@ import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Bundles; import io.anuke.ucore.util.Mathf; -import static io.anuke.mindustry.Vars.state; -import static io.anuke.mindustry.Vars.tilesize; -import static io.anuke.mindustry.Vars.world; +import static io.anuke.mindustry.Vars.*; public class Block extends BaseBlock { private static int lastid; @@ -139,6 +137,11 @@ public class Block extends BaseBlock { setBars(); } + /**Called after texture atlas is loaded.*/ + public void load(){ + + } + public void tapped(Tile tile){} public void buildTable(Tile tile, Table table) {} public void configure(Tile tile, byte data){} diff --git a/core/src/io/anuke/mindustry/world/blocks/types/Floor.java b/core/src/io/anuke/mindustry/world/blocks/types/Floor.java index 4d0326f2dc..df6f47ae87 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/Floor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/Floor.java @@ -44,7 +44,6 @@ public class Floor extends Block{ } } - @Override public void drawNonLayer(Tile tile){ MathUtils.random.setSeed(tile.id()); @@ -63,6 +62,7 @@ public class Floor extends Block{ private void drawEdges(Tile tile, boolean sameLayer){ if(!blend) return; + for(int dx = -1; dx <= 1; dx ++){ for(int dy = -1; dy <= 1; dy ++){